Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / config / Resource / FileResource.php
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\Resource;
13
14 /**
15  * FileResource represents a resource stored on the filesystem.
16  *
17  * The resource can be a file or a directory.
18  *
19  * @author Fabien Potencier <fabien@symfony.com>
20  */
21 class FileResource implements SelfCheckingResourceInterface, \Serializable
22 {
23     /**
24      * @var string|false
25      */
26     private $resource;
27
28     /**
29      * Constructor.
30      *
31      * @param string $resource The file path to the resource
32      *
33      * @throws \InvalidArgumentException
34      */
35     public function __construct($resource)
36     {
37         $this->resource = realpath($resource) ?: (file_exists($resource) ? $resource : false);
38
39         if (false === $this->resource) {
40             throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $resource));
41         }
42     }
43
44     /**
45      * {@inheritdoc}
46      */
47     public function __toString()
48     {
49         return $this->resource;
50     }
51
52     /**
53      * @return string The canonicalized, absolute path to the resource
54      */
55     public function getResource()
56     {
57         return $this->resource;
58     }
59
60     /**
61      * {@inheritdoc}
62      */
63     public function isFresh($timestamp)
64     {
65         return file_exists($this->resource) && @filemtime($this->resource) <= $timestamp;
66     }
67
68     public function serialize()
69     {
70         return serialize($this->resource);
71     }
72
73     public function unserialize($serialized)
74     {
75         $this->resource = unserialize($serialized);
76     }
77 }