349402edf0494279984349295073e7285e8076b7
[yaffs-website] / vendor / symfony / config / Resource / FileExistenceResource.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  * FileExistenceResource represents a resource stored on the filesystem.
16  * Freshness is only evaluated against resource creation or deletion.
17  *
18  * The resource can be a file or a directory.
19  *
20  * @author Charles-Henri Bruyand <charleshenri.bruyand@gmail.com>
21  */
22 class FileExistenceResource implements SelfCheckingResourceInterface, \Serializable
23 {
24     private $resource;
25
26     private $exists;
27
28     /**
29      * Constructor.
30      *
31      * @param string $resource The file path to the resource
32      */
33     public function __construct($resource)
34     {
35         $this->resource = (string) $resource;
36         $this->exists = file_exists($resource);
37     }
38
39     /**
40      * {@inheritdoc}
41      */
42     public function __toString()
43     {
44         return $this->resource;
45     }
46
47     /**
48      * @return string The file path to the resource
49      */
50     public function getResource()
51     {
52         return $this->resource;
53     }
54
55     /**
56      * {@inheritdoc}
57      */
58     public function isFresh($timestamp)
59     {
60         return file_exists($this->resource) === $this->exists;
61     }
62
63     /**
64      * {@inheritdoc}
65      */
66     public function serialize()
67     {
68         return serialize(array($this->resource, $this->exists));
69     }
70
71     /**
72      * {@inheritdoc}
73      */
74     public function unserialize($serialized)
75     {
76         list($this->resource, $this->exists) = unserialize($serialized);
77     }
78 }