123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace Symfony\Component\Config\Resource;
- class DirectoryResource implements SelfCheckingResourceInterface, \Serializable
- {
- private $resource;
- private $pattern;
-
- public function __construct($resource, $pattern = null)
- {
- $this->resource = $resource;
- $this->pattern = $pattern;
- }
-
- public function __toString()
- {
- return md5(serialize(array($this->resource, $this->pattern)));
- }
-
- public function getResource()
- {
- return $this->resource;
- }
-
- public function getPattern()
- {
- return $this->pattern;
- }
-
- public function isFresh($timestamp)
- {
- if (!is_dir($this->resource)) {
- return false;
- }
- if ($timestamp < filemtime($this->resource)) {
- return false;
- }
- foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->resource), \RecursiveIteratorIterator::SELF_FIRST) as $file) {
-
- if ($this->pattern && $file->isFile() && !preg_match($this->pattern, $file->getBasename())) {
- continue;
- }
-
-
- if ($file->isDir() && '/..' === substr($file, -3)) {
- continue;
- }
-
- try {
- $fileMTime = $file->getMTime();
- } catch (\RuntimeException $e) {
- continue;
- }
-
- if ($timestamp < $fileMTime) {
- return false;
- }
- }
- return true;
- }
- public function serialize()
- {
- return serialize(array($this->resource, $this->pattern));
- }
- public function unserialize($serialized)
- {
- list($this->resource, $this->pattern) = unserialize($serialized);
- }
- }
|