[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\Config\Resource; 13 14 /** 15 * DirectoryResource represents a resources stored in a subdirectory tree. 16 * 17 * @author Fabien Potencier <fabien@symfony.com> 18 */ 19 class DirectoryResource implements ResourceInterface, \Serializable 20 { 21 private $resource; 22 private $pattern; 23 24 /** 25 * Constructor. 26 * 27 * @param string $resource The file path to the resource 28 * @param string|null $pattern A pattern to restrict monitored files 29 */ 30 public function __construct($resource, $pattern = null) 31 { 32 $this->resource = $resource; 33 $this->pattern = $pattern; 34 } 35 36 /** 37 * {@inheritdoc} 38 */ 39 public function __toString() 40 { 41 return md5(serialize(array($this->resource, $this->pattern))); 42 } 43 44 /** 45 * {@inheritdoc} 46 */ 47 public function getResource() 48 { 49 return $this->resource; 50 } 51 52 /** 53 * Returns the pattern to restrict monitored files. 54 * 55 * @return string|null 56 */ 57 public function getPattern() 58 { 59 return $this->pattern; 60 } 61 62 /** 63 * {@inheritdoc} 64 */ 65 public function isFresh($timestamp) 66 { 67 if (!is_dir($this->resource)) { 68 return false; 69 } 70 71 $newestMTime = filemtime($this->resource); 72 foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->resource), \RecursiveIteratorIterator::SELF_FIRST) as $file) { 73 // if regex filtering is enabled only check matching files 74 if ($this->pattern && $file->isFile() && !preg_match($this->pattern, $file->getBasename())) { 75 continue; 76 } 77 78 // always monitor directories for changes, except the .. entries 79 // (otherwise deleted files wouldn't get detected) 80 if ($file->isDir() && '/..' === substr($file, -3)) { 81 continue; 82 } 83 84 $newestMTime = max($file->getMTime(), $newestMTime); 85 } 86 87 return $newestMTime < $timestamp; 88 } 89 90 public function serialize() 91 { 92 return serialize(array($this->resource, $this->pattern)); 93 } 94 95 public function unserialize($serialized) 96 { 97 list($this->resource, $this->pattern) = unserialize($serialized); 98 } 99 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |