Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / vendor / symfony / http-kernel / Config / EnvParametersResource.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\HttpKernel\Config;
13
14 use Symfony\Component\Config\Resource\SelfCheckingResourceInterface;
15
16 /**
17  * EnvParametersResource represents resources stored in prefixed environment variables.
18  *
19  * @author Chris Wilkinson <chriswilkinson84@gmail.com>
20  *
21  * @deprecated since version 3.4, to be removed in 4.0
22  */
23 class EnvParametersResource implements SelfCheckingResourceInterface, \Serializable
24 {
25     /**
26      * @var string
27      */
28     private $prefix;
29
30     /**
31      * @var string
32      */
33     private $variables;
34
35     /**
36      * @param string $prefix
37      */
38     public function __construct($prefix)
39     {
40         $this->prefix = $prefix;
41         $this->variables = $this->findVariables();
42     }
43
44     /**
45      * {@inheritdoc}
46      */
47     public function __toString()
48     {
49         return serialize($this->getResource());
50     }
51
52     /**
53      * @return array An array with two keys: 'prefix' for the prefix used and 'variables' containing all the variables watched by this resource
54      */
55     public function getResource()
56     {
57         return array('prefix' => $this->prefix, 'variables' => $this->variables);
58     }
59
60     /**
61      * {@inheritdoc}
62      */
63     public function isFresh($timestamp)
64     {
65         return $this->findVariables() === $this->variables;
66     }
67
68     public function serialize()
69     {
70         return serialize(array('prefix' => $this->prefix, 'variables' => $this->variables));
71     }
72
73     public function unserialize($serialized)
74     {
75         if (\PHP_VERSION_ID >= 70000) {
76             $unserialized = unserialize($serialized, array('allowed_classes' => false));
77         } else {
78             $unserialized = unserialize($serialized);
79         }
80
81         $this->prefix = $unserialized['prefix'];
82         $this->variables = $unserialized['variables'];
83     }
84
85     private function findVariables()
86     {
87         $variables = array();
88
89         foreach ($_SERVER as $key => $value) {
90             if (0 === strpos($key, $this->prefix)) {
91                 $variables[$key] = $value;
92             }
93         }
94
95         ksort($variables);
96
97         return $variables;
98     }
99 }