comparison vendor/symfony/dependency-injection/Loader/IniFileLoader.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
30 30
31 $this->container->fileExists($path); 31 $this->container->fileExists($path);
32 32
33 // first pass to catch parsing errors 33 // first pass to catch parsing errors
34 $result = parse_ini_file($path, true); 34 $result = parse_ini_file($path, true);
35 if (false === $result || array() === $result) { 35 if (false === $result || [] === $result) {
36 throw new InvalidArgumentException(sprintf('The "%s" file is not valid.', $resource)); 36 throw new InvalidArgumentException(sprintf('The "%s" file is not valid.', $resource));
37 } 37 }
38 38
39 // real raw parsing 39 // real raw parsing
40 $result = parse_ini_file($path, true, INI_SCANNER_RAW); 40 $result = parse_ini_file($path, true, INI_SCANNER_RAW);
41 41
42 if (isset($result['parameters']) && is_array($result['parameters'])) { 42 if (isset($result['parameters']) && \is_array($result['parameters'])) {
43 foreach ($result['parameters'] as $key => $value) { 43 foreach ($result['parameters'] as $key => $value) {
44 $this->container->setParameter($key, $this->phpize($value)); 44 $this->container->setParameter($key, $this->phpize($value));
45 } 45 }
46 } 46 }
47 } 47 }
49 /** 49 /**
50 * {@inheritdoc} 50 * {@inheritdoc}
51 */ 51 */
52 public function supports($resource, $type = null) 52 public function supports($resource, $type = null)
53 { 53 {
54 if (!is_string($resource)) { 54 if (!\is_string($resource)) {
55 return false; 55 return false;
56 } 56 }
57 57
58 if (null === $type && 'ini' === pathinfo($resource, PATHINFO_EXTENSION)) { 58 if (null === $type && 'ini' === pathinfo($resource, PATHINFO_EXTENSION)) {
59 return true; 59 return true;
68 * * string concatenation ("foo" "bar"). 68 * * string concatenation ("foo" "bar").
69 */ 69 */
70 private function phpize($value) 70 private function phpize($value)
71 { 71 {
72 // trim on the right as comments removal keep whitespaces 72 // trim on the right as comments removal keep whitespaces
73 $value = rtrim($value); 73 if ($value !== $v = rtrim($value)) {
74 $value = '""' === substr_replace($v, '', 1, -1) ? substr($v, 1, -1) : $v;
75 }
74 $lowercaseValue = strtolower($value); 76 $lowercaseValue = strtolower($value);
75 77
76 switch (true) { 78 switch (true) {
77 case defined($value): 79 case \defined($value):
78 return constant($value); 80 return \constant($value);
79 case 'yes' === $lowercaseValue || 'on' === $lowercaseValue: 81 case 'yes' === $lowercaseValue || 'on' === $lowercaseValue:
80 return true; 82 return true;
81 case 'no' === $lowercaseValue || 'off' === $lowercaseValue || 'none' === $lowercaseValue: 83 case 'no' === $lowercaseValue || 'off' === $lowercaseValue || 'none' === $lowercaseValue:
82 return false; 84 return false;
83 case isset($value[1]) && ( 85 case isset($value[1]) && (
84 ("'" === $value[0] && "'" === $value[strlen($value) - 1]) || 86 ("'" === $value[0] && "'" === $value[\strlen($value) - 1]) ||
85 ('"' === $value[0] && '"' === $value[strlen($value) - 1]) 87 ('"' === $value[0] && '"' === $value[\strlen($value) - 1])
86 ): 88 ):
87 // quoted string 89 // quoted string
88 return substr($value, 1, -1); 90 return substr($value, 1, -1);
89 default: 91 default:
90 return XmlUtils::phpize($value); 92 return XmlUtils::phpize($value);