[ 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; 13 14 use Symfony\Component\Config\Resource\ResourceInterface; 15 use Symfony\Component\Filesystem\Exception\IOException; 16 use Symfony\Component\Filesystem\Filesystem; 17 18 /** 19 * ConfigCache manages PHP cache files. 20 * 21 * When debug is enabled, it knows when to flush the cache 22 * thanks to an array of ResourceInterface instances. 23 * 24 * @author Fabien Potencier <fabien@symfony.com> 25 */ 26 class ConfigCache 27 { 28 private $debug; 29 private $file; 30 31 /** 32 * Constructor. 33 * 34 * @param string $file The absolute cache path 35 * @param bool $debug Whether debugging is enabled or not 36 */ 37 public function __construct($file, $debug) 38 { 39 $this->file = $file; 40 $this->debug = (bool) $debug; 41 } 42 43 /** 44 * Gets the cache file path. 45 * 46 * @return string The cache file path 47 */ 48 public function __toString() 49 { 50 return $this->file; 51 } 52 53 /** 54 * Checks if the cache is still fresh. 55 * 56 * This method always returns true when debug is off and the 57 * cache file exists. 58 * 59 * @return bool true if the cache is fresh, false otherwise 60 */ 61 public function isFresh() 62 { 63 if (!is_file($this->file)) { 64 return false; 65 } 66 67 if (!$this->debug) { 68 return true; 69 } 70 71 $metadata = $this->getMetaFile(); 72 if (!is_file($metadata)) { 73 return false; 74 } 75 76 $time = filemtime($this->file); 77 $meta = unserialize(file_get_contents($metadata)); 78 foreach ($meta as $resource) { 79 if (!$resource->isFresh($time)) { 80 return false; 81 } 82 } 83 84 return true; 85 } 86 87 /** 88 * Writes cache. 89 * 90 * @param string $content The content to write in the cache 91 * @param ResourceInterface[] $metadata An array of ResourceInterface instances 92 * 93 * @throws \RuntimeException When cache file can't be written 94 */ 95 public function write($content, array $metadata = null) 96 { 97 $mode = 0666; 98 $umask = umask(); 99 $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 }
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 |