64288ea1db2d62c27ff28e14e7a9ae8047fd093e
[yaffs-website] / vendor / symfony / config / Resource / ComposerResource.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  * ComposerResource tracks the PHP version and Composer dependencies.
16  *
17  * @author Nicolas Grekas <p@tchwork.com>
18  */
19 class ComposerResource implements SelfCheckingResourceInterface, \Serializable
20 {
21     private $vendors;
22
23     private static $runtimeVendors;
24
25     public function __construct()
26     {
27         self::refresh();
28         $this->vendors = self::$runtimeVendors;
29     }
30
31     public function getVendors()
32     {
33         return array_keys($this->vendors);
34     }
35
36     /**
37      * {@inheritdoc}
38      */
39     public function __toString()
40     {
41         return __CLASS__;
42     }
43
44     /**
45      * {@inheritdoc}
46      */
47     public function isFresh($timestamp)
48     {
49         self::refresh();
50
51         return self::$runtimeVendors === $this->vendors;
52     }
53
54     public function serialize()
55     {
56         return serialize($this->vendors);
57     }
58
59     public function unserialize($serialized)
60     {
61         $this->vendors = unserialize($serialized);
62     }
63
64     private static function refresh()
65     {
66         self::$runtimeVendors = array();
67
68         foreach (get_declared_classes() as $class) {
69             if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
70                 $r = new \ReflectionClass($class);
71                 $v = dirname(dirname($r->getFileName()));
72                 if (file_exists($v.'/composer/installed.json')) {
73                     self::$runtimeVendors[$v] = @filemtime($v.'/composer/installed.json');
74                 }
75             }
76         }
77     }
78 }