8a9df906a643d8fca931a3ae2feabdf16f66b6a9
[yaffs-website] / vendor / symfony / config / Resource / ClassExistenceResource.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  * ClassExistenceResource represents a class existence.
16  * Freshness is only evaluated against resource existence.
17  *
18  * The resource must be a fully-qualified class name.
19  *
20  * @author Fabien Potencier <fabien@symfony.com>
21  */
22 class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializable
23 {
24     private $resource;
25     private $exists;
26
27     /**
28      * @param string $resource The fully-qualified class name
29      */
30     public function __construct($resource)
31     {
32         $this->resource = $resource;
33         $this->exists = class_exists($resource);
34     }
35
36     /**
37      * {@inheritdoc}
38      */
39     public function __toString()
40     {
41         return $this->resource;
42     }
43
44     /**
45      * @return string The file path to the resource
46      */
47     public function getResource()
48     {
49         return $this->resource;
50     }
51
52     /**
53      * {@inheritdoc}
54      */
55     public function isFresh($timestamp)
56     {
57         return class_exists($this->resource) === $this->exists;
58     }
59
60     /**
61      * {@inheritdoc}
62      */
63     public function serialize()
64     {
65         return serialize(array($this->resource, $this->exists));
66     }
67
68     /**
69      * {@inheritdoc}
70      */
71     public function unserialize($serialized)
72     {
73         list($this->resource, $this->exists) = unserialize($serialized);
74     }
75 }