Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ResourceCheckerConfigCache.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 3.95 KiB


 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   * ResourceCheckerConfigCache uses instances of ResourceCheckerInterface
 020   * to check whether cached data is still fresh.
 021   *
 022   * @author Matthias Pigulla <mp@webfactory.de>
 023   */
 024  class ResourceCheckerConfigCache implements ConfigCacheInterface
 025  {
 026      /**
 027       * @var string
 028       */
 029      private $file;
 030   
 031      /**
 032       * @var ResourceCheckerInterface[]
 033       */
 034      private $resourceCheckers;
 035   
 036      /**
 037       * @param string                     $file             The absolute cache path
 038       * @param ResourceCheckerInterface[] $resourceCheckers The ResourceCheckers to use for the freshness check
 039       */
 040      public function __construct($file, array $resourceCheckers = array())
 041      {
 042          $this->file = $file;
 043          $this->resourceCheckers = $resourceCheckers;
 044      }
 045   
 046      /**
 047       * {@inheritdoc}
 048       */
 049      public function getPath()
 050      {
 051          return $this->file;
 052      }
 053   
 054      /**
 055       * Checks if the cache is still fresh.
 056       *
 057       * This implementation will make a decision solely based on the ResourceCheckers
 058       * passed in the constructor.
 059       *
 060       * The first ResourceChecker that supports a given resource is considered authoritative.
 061       * Resources with no matching ResourceChecker will silently be ignored and considered fresh.
 062       *
 063       * @return bool true if the cache is fresh, false otherwise
 064       */
 065      public function isFresh()
 066      {
 067          if (!is_file($this->file)) {
 068              return false;
 069          }
 070   
 071          if (!$this->resourceCheckers) {
 072              return true; // shortcut - if we don't have any checkers we don't need to bother with the meta file at all
 073          }
 074   
 075          $metadata = $this->getMetaFile();
 076          if (!is_file($metadata)) {
 077              return true;
 078          }
 079   
 080          $time = filemtime($this->file);
 081          $meta = unserialize(file_get_contents($metadata));
 082   
 083          foreach ($meta as $resource) {
 084              /* @var ResourceInterface $resource */
 085              foreach ($this->resourceCheckers as $checker) {
 086                  if (!$checker->supports($resource)) {
 087                      continue; // next checker
 088                  }
 089                  if ($checker->isFresh($resource, $time)) {
 090                      break; // no need to further check this resource
 091                  }
 092   
 093                  return false; // cache is stale
 094              }
 095              // no suitable checker found, ignore this resource
 096          }
 097   
 098          return true;
 099      }
 100   
 101      /**
 102       * Writes cache.
 103       *
 104       * @param string              $content  The content to write in the cache
 105       * @param ResourceInterface[] $metadata An array of metadata
 106       *
 107       * @throws \RuntimeException When cache file can't be written
 108       */
 109      public function write($content, array $metadata = null)
 110      {
 111          $mode = 0666;
 112          $umask = umask();
 113          $filesystem = new Filesystem();
 114          $filesystem->dumpFile($this->file, $content, null);
 115          try {
 116              $filesystem->chmod($this->file, $mode, $umask);
 117          } catch (IOException $e) {
 118              // discard chmod failure (some filesystem may not support it)
 119          }
 120   
 121          if (null !== $metadata) {
 122              $filesystem->dumpFile($this->getMetaFile(), serialize($metadata), null);
 123              try {
 124                  $filesystem->chmod($this->getMetaFile(), $mode, $umask);
 125              } catch (IOException $e) {
 126                  // discard chmod failure (some filesystem may not support it)
 127              }
 128          }
 129      }
 130   
 131      /**
 132       * Gets the meta file path.
 133       *
 134       * @return string The meta file path
 135       */
 136      private function getMetaFile()
 137      {
 138          return $this->file.'.meta';
 139      }
 140  }
 141