vendor/symfony/config/Resource/FileResource.php line 59

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.  * FileResource represents a resource stored on the filesystem.
  13.  *
  14.  * The resource can be a file or a directory.
  15.  *
  16.  * @author Fabien Potencier <fabien@symfony.com>
  17.  *
  18.  * @final
  19.  */
  20. class FileResource implements SelfCheckingResourceInterface
  21. {
  22.     private string $resource;
  23.     /**
  24.      * @param string $resource The file path to the resource
  25.      *
  26.      * @throws \InvalidArgumentException
  27.      */
  28.     public function __construct(string $resource)
  29.     {
  30.         $resolvedResource realpath($resource) ?: (file_exists($resource) ? $resource false);
  31.         if (false === $resolvedResource) {
  32.             throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.'$resource));
  33.         }
  34.         $this->resource $resolvedResource;
  35.     }
  36.     public function __toString(): string
  37.     {
  38.         return $this->resource;
  39.     }
  40.     /**
  41.      * Returns the canonicalized, absolute path to the resource.
  42.      */
  43.     public function getResource(): string
  44.     {
  45.         return $this->resource;
  46.     }
  47.     /**
  48.      * {@inheritdoc}
  49.      */
  50.     public function isFresh(int $timestamp): bool
  51.     {
  52.         return false !== ($filemtime = @filemtime($this->resource)) && $filemtime <= $timestamp;
  53.     }
  54. }