Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
ConfigCache.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\Config;
013
014 use Symfony\Component\Config\Resource\ResourceInterface;
015 use Symfony\Component\Filesystem\Exception\IOException;
016 use Symfony\Component\Filesystem\Filesystem;
017
018 /**
019 * ConfigCache manages PHP cache files.
020 *
021 * When debug is enabled, it knows when to flush the cache
022 * thanks to an array of ResourceInterface instances.
023 *
024 * @author Fabien Potencier <fabien@symfony.com>
025 */
026 class ConfigCache
027 {
028 private $debug;
029 private $file;
030
031 /**
032 * Constructor.
033 *
034 * @param string $file The absolute cache path
035 * @param bool $debug Whether debugging is enabled or not
036 */
037 public function __construct($file, $debug)
038 {
039 $this->file = $file;
040 $this->debug = (bool) $debug;
041 }
042
043 /**
044 * Gets the cache file path.
045 *
046 * @return string The cache file path
047 */
048 public function __toString()
049 {
050 return $this->file;
051 }
052
053 /**
054 * Checks if the cache is still fresh.
055 *
056 * This method always returns true when debug is off and the
057 * cache file exists.
058 *
059 * @return bool true if the cache is fresh, false otherwise
060 */
061 public function isFresh()
062 {
063 if (!is_file($this->file)) {
064 return false;
065 }
066
067 if (!$this->debug) {
068 return true;
069 }
070
071 $metadata = $this->getMetaFile();
072 if (!is_file($metadata)) {
073 return false;
074 }
075
076 $time = filemtime($this->file);
077 $meta = unserialize(file_get_contents($metadata));
078 foreach ($meta as $resource) {
079 if (!$resource->isFresh($time)) {
080 return false;
081 }
082 }
083
084 return true;
085 }
086
087 /**
088 * Writes cache.
089 *
090 * @param string $content The content to write in the cache
091 * @param ResourceInterface[] $metadata An array of ResourceInterface instances
092 *
093 * @throws \RuntimeException When cache file can't be wrote
094 */
095 public function write($content, array $metadata = null)
096 {
097 $mode = 0666;
098 $umask = umask();
099 $filesystem = new Filesystem();
100 $filesystem->dumpFile($this->file, $content, null);
101 try {
102 $filesystem->chmod($this->file, $mode, $umask);
103 } catch (IOException $e) {
104 // discard chmod failure (some filesystem may not support it)
105 }
106
107 if (null !== $metadata && true === $this->debug) {
108 $filesystem->dumpFile($this->getMetaFile(), serialize($metadata), null);
109 try {
110 $filesystem->chmod($this->getMetaFile(), $mode, $umask);
111 } catch (IOException $e) {
112 // discard chmod failure (some filesystem may not support it)
113 }
114 }
115 }
116
117 /**
118 * Gets the meta file path.
119 *
120 * @return string The meta file path
121 */
122 private function getMetaFile()
123 {
124 return $this->file.'.meta';
125 }
126 }
127