[ Index ] |
PHP Cross Reference of phpBB-3.2.11-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 SelfCheckingResourceInterface, \Serializable 20 { 21 private $resource; 22 private $pattern; 23 24 /** 25 * @param string $resource The file path to the resource 26 * @param string|null $pattern A pattern to restrict monitored files 27 */ 28 public function __construct($resource, $pattern = null) 29 { 30 $this->resource = $resource; 31 $this->pattern = $pattern; 32 } 33 34 /** 35 * {@inheritdoc} 36 */ 37 public function __toString() 38 { 39 return md5(serialize(array($this->resource, $this->pattern))); 40 } 41 42 /** 43 * {@inheritdoc} 44 */ 45 public function getResource() 46 { 47 return $this->resource; 48 } 49 50 /** 51 * Returns the pattern to restrict monitored files. 52 * 53 * @return string|null 54 */ 55 public function getPattern() 56 { 57 return $this->pattern; 58 } 59 60 /** 61 * {@inheritdoc} 62 */ 63 public function isFresh($timestamp) 64 { 65 if (!is_dir($this->resource)) { 66 return false; 67 } 68 69 if ($timestamp < filemtime($this->resource)) { 70 return false; 71 } 72 73 foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->resource), \RecursiveIteratorIterator::SELF_FIRST) as $file) { 74 // if regex filtering is enabled only check matching files 75 if ($this->pattern && $file->isFile() && !preg_match($this->pattern, $file->getBasename())) { 76 continue; 77 } 78 79 // always monitor directories for changes, except the .. entries 80 // (otherwise deleted files wouldn't get detected) 81 if ($file->isDir() && '/..' === substr($file, -3)) { 82 continue; 83 } 84 85 // for broken links 86 try { 87 $fileMTime = $file->getMTime(); 88 } catch (\RuntimeException $e) { 89 continue; 90 } 91 92 // early return if a file's mtime exceeds the passed timestamp 93 if ($timestamp < $fileMTime) { 94 return false; 95 } 96 } 97 98 return true; 99 } 100 101 public function serialize() 102 { 103 return serialize(array($this->resource, $this->pattern)); 104 } 105 106 public function unserialize($serialized) 107 { 108 list($this->resource, $this->pattern) = unserialize($serialized); 109 } 110 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |