phorge/src/infrastructure/celerity/resources/CelerityResourcesOnDisk.php2c35532256eamaster
phorge/src/infrastructure/celerity/resources/CelerityResourcesOnDisk.php
2c35532256eamaster
CelerityResourcesOnDisk.php
CelerityResourcesOnDisk.php
906ac21e543d | <?php | ||
---|---|---|---|
/** | |||
* Defines the location of static resources on disk. | |||
*/ | |||
abstract class CelerityResourcesOnDisk extends CelerityResources { | |||
abstract public function getPathToResources(); | |||
2c35532256ea | private function getPathToResource($name) { | ||
return $this->getPathToResources().DIRECTORY_SEPARATOR.$name; | |||
} | |||
543f6355572a | public function getResourceData($name) { | ||
2c35532256ea | return Filesystem::readFile($this->getPathToResource($name)); | ||
543f6355572a | } | ||
906ac21e543d | public function findBinaryResources() { | ||
return $this->findResourcesWithSuffixes($this->getBinaryFileSuffixes()); | |||
} | |||
public function findTextResources() { | |||
return $this->findResourcesWithSuffixes($this->getTextFileSuffixes()); | |||
} | |||
2c35532256ea | public function getResourceModifiedTime($name) { | ||
return (int)filemtime($this->getPathToResource($name)); | |||
} | |||
906ac21e543d | protected function getBinaryFileSuffixes() { | ||
return array( | |||
'png', | |||
'jpg', | |||
'gif', | |||
'swf', | |||
); | |||
} | |||
protected function getTextFileSuffixes() { | |||
return array( | |||
'js', | |||
'css', | |||
); | |||
} | |||
private function findResourcesWithSuffixes(array $suffixes) { | |||
$root = $this->getPathToResources(); | |||
$finder = id(new FileFinder($root)) | |||
->withType('f') | |||
->withFollowSymlinks(true) | |||
->setGenerateChecksums(true); | |||
foreach ($suffixes as $suffix) { | |||
$finder->withSuffix($suffix); | |||
} | |||
$raw_files = $finder->find(); | |||
$results = array(); | |||
foreach ($raw_files as $path => $hash) { | |||
543f6355572a | $readable = Filesystem::readablePath($path, $root); | ||
906ac21e543d | $results[$readable] = $hash; | ||
} | |||
return $results; | |||
} | |||
} |
Owner Packages
Owner Packages
- No Owners