vendor/symfony/config/Resource/FileExistenceResource.php line 22

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Config\Resource;
  11. /**
  12.  * FileExistenceResource represents a resource stored on the filesystem.
  13.  * Freshness is only evaluated against resource creation or deletion.
  14.  *
  15.  * The resource can be a file or a directory.
  16.  *
  17.  * @author Charles-Henri Bruyand <charleshenri.bruyand@gmail.com>
  18.  */
  19. class FileExistenceResource implements SelfCheckingResourceInterface\Serializable
  20. {
  21.     private $resource;
  22.     private $exists;
  23.     /**
  24.      * @param string $resource The file path to the resource
  25.      */
  26.     public function __construct($resource)
  27.     {
  28.         $this->resource = (string) $resource;
  29.         $this->exists file_exists($resource);
  30.     }
  31.     /**
  32.      * {@inheritdoc}
  33.      */
  34.     public function __toString()
  35.     {
  36.         return $this->resource;
  37.     }
  38.     /**
  39.      * @return string The file path to the resource
  40.      */
  41.     public function getResource()
  42.     {
  43.         return $this->resource;
  44.     }
  45.     /**
  46.      * {@inheritdoc}
  47.      */
  48.     public function isFresh($timestamp)
  49.     {
  50.         return file_exists($this->resource) === $this->exists;
  51.     }
  52.     /**
  53.      * @internal
  54.      */
  55.     public function serialize()
  56.     {
  57.         return serialize([$this->resource$this->exists]);
  58.     }
  59.     /**
  60.      * @internal
  61.      */
  62.     public function unserialize($serialized)
  63.     {
  64.         list($this->resource$this->exists) = unserialize($serialized);
  65.     }
  66. }