8000 bug #42296 [Dotenv][Yaml] Remove PHP 8.0 polyfill (derrabus) · symfony/symfony@192e360 · GitHub
[go: up one dir, main page]

Skip to content

Commit 192e360

Browse files
committed
bug #42296 [Dotenv][Yaml] Remove PHP 8.0 polyfill (derrabus)
This PR was merged into the 4.4 branch. Discussion ---------- [Dotenv][Yaml] Remove PHP 8.0 polyfill | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #42280 | License | MIT | Doc PR | N/A This is a partial revert of #41576 and #41973. Commits ------- 08ecbf5 Remove polyfills from Yaml and Dotenv
2 parents 7f0641f + 08ecbf5 commit 192e360

File tree

8 files changed

+30
-32
lines changed

8 files changed

+30
-32
lines changed

src/Symfony/Component/Dotenv/Dotenv.php

Expand all lines: src/Symfony/Component/Dotenv/Dotenv.php
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function populate(array $values, bool $overrideExistingVars = false): voi
135135
$loadedVars = array_flip(explode(',', $_SERVER['SYMFONY_DOTENV_VARS'] ?? $_ENV['SYMFONY_DOTENV_VARS'] ?? ''));
136136

137137
foreach ($values as $name => $value) {
138-
$notHttpName = !str_starts_with($name, 'HTTP_');
138+
$notHttpName = 0 !== strpos($name, 'HTTP_');
139139
// don't check existence with getenv() because of thread safety issues
140140
if (!isset($loadedVars[$name]) && (!$overrideExistingVars && (isset($_ENV[$name]) || (isset($_SERVER[$name]) && $notHttpName)))) {
141141
continue;
@@ -372,7 +372,7 @@ private function skipEmptyLines()
372372

373373
private function resolveCommands(string $value, array $loadedVars): string
374374
{
375-
if (!str_contains($value, '$')) {
375+
if (false === strpos($value, '$')) {
376376
return $value;
377377
}
378378

@@ -408,7 +408,7 @@ private function resolveCommands(string $value, array $loadedVars): string
408408

409409
$env = [];
410410
foreach ($this->values as $name => $value) {
411-
if (isset($loadedVars[$name]) || (!isset($_ENV[$name]) && !(isset($_SERVER[$name]) && !str_starts_with($name, 'HTTP_')))) {
411+
if (isset($loadedVars[$name]) || (!isset($_ENV[$name]) && !(isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')))) {
412412
$env[$name] = $value;
413413
}
414414
}
@@ -426,7 +426,7 @@ private function resolveCommands(string $value, array $loadedVars): string
426426

427427
private function resolveVariables(string $value, array $loadedVars): string
428428
{
429-
if (!str_contains($value, '$')) {
429+
if (false === strpos($value, '$')) {
430430
return $value;
431431
}
432432

@@ -461,7 +461,7 @@ private function resolveVariables(string $value, array $loadedVars): string
461461
$value = $this->values[$name];
462462
} elseif (isset($_ENV[$name])) {
463463
$value = $_ENV[$name];
464-
} elseif (isset($_SERVER[$name]) && !str_starts_with($name, 'HTTP_')) {
464+
} elseif (isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')) {
465465
$value = $_SERVER[$name];
466466
} elseif (isset($this->values[$name])) {
467467
$value = $this->values[$name];

src/Symfony/Component/Dotenv/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
}
1717
],
1818
"require": {
19-
"php": ">=7.1.3",
20-
"symfony/polyfill-php80": "^1.16"
19+
"php": ">=7.1.3"
2120
},
2221
"require-dev": {
2322
"symfony/process": "^3.4.2|^4.0|^5.0"

src/Symfony/Component/Yaml/Command/LintCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private function displayTxt(SymfonyStyle $io, array $filesInfo): int
163163
$io->text('<error> ERROR </error>'.($info['file'] ? sprintf(' in %s', $info['file']) : ''));
164164
$io->text(sprintf('<error> >> %s</error>', $info['message']));
165165

166-
if (str_contains($info['message'], 'PARSE_CUSTOM_TAGS')) {
166+
if (false !== strpos($info['message'], 'PARSE_CUSTOM_TAGS')) {
167167
$suggestTagOption = true;
168168
}
169169
}
@@ -188,7 +188,7 @@ private function displayJson(SymfonyStyle $io, array $filesInfo): int
188188
++$errors;
189189
}
190190

191-
if (isset($v['message']) && str_contains($v['message'], 'PARSE_CUSTOM_TAGS')) {
191+
if (isset($v['message']) && false !== strpos($v['message'], 'PARSE_CUSTOM_TAGS')) {
192192
$v['message'] .= ' Use the --parse-tags option if you want parse custom tags.';
193193
}
194194
});

src/Symfony/Component/Yaml/Dumper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function dump($input, int $inline = 0, int $indent = 0, int $flags = 0):
6868
$output .= "\n";
6969
}
7070

71-
if (Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value) && str_contains($value, "\n") && !str_contains($value, "\r")) {
71+
if (Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value) && false !== strpos($value, "\n") && false === strpos($value, "\r")) {
7272
// If the first line starts with a space character, the spec requires a blockIndicationIndicator
7373
// http://www.yaml.org/spec/1.2/spec.html#id2793979
7474
$blockIndentationIndicator = (' ' === substr($value, 0, 1)) ? (string) $this->indentation : '';
@@ -97,7 +97,7 @@ public function dump($input, int $inline = 0, int $indent = 0, int $flags = 0):
9797
if ($value instanceof TaggedValue) {
9898
$output .= sprintf('%s%s !%s', $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', $value->getTag());
9999

100-
if (Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value->getValue()) && str_contains($value->getValue(), "\n") && !str_contains($value->getValue(), "\r\n")) {
100+
if (Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value->getValue()) && false !== strpos($value->getValue(), "\n") && false === strpos($value->getValue(), "\r\n")) {
101101
// If the first line starts with a space character, the spec requires a blockIndicationIndicator
102102
// http://www.yaml.org/spec/1.2/spec.html#id2793979
103103
$blockIndentationIndicator = (' ' === substr($value->getValue(), 0, 1)) ? (string) $this->indentation : '';

src/Symfony/Component/Yaml/Exception/ParseException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private function updateRepr()
114114
$this->message = $this->rawMessage;
115115

116116
$dot = false;
117-
if (str_ends_with($this->message, '.')) {
117+
if ('.' === substr($this->message, -1)) {
118118
$this->message = substr($this->message, 0, -1);
119119
$dot = true;
120120
}

src/Symfony/Component/Yaml/Inline.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ private static function parseSequence(string $sequence, int $flags, int &$i = 0,
377377
$value = self::parseScalar($sequence, $flags, [',', ']'], $i, null === $tag, $references);
378378

379379
// the value can be an array if a reference has been resolved to an array var
380-
if (\is_string($value) && !$isQuoted && str_contains($value, ': ')) {
380+
if (\is_string($value) && !$isQuoted && false !== strpos($value, ': ')) {
381381
// embedded mapping?
382382
try {
383383
$pos = 0;
@@ -565,7 +565,7 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
565565
$scalar = trim($scalar);
566566
$scalarLower = strtolower($scalar);
567567

568-
if (str_starts_with($scalar, '*')) {
568+
if (0 === strpos($scalar, '*')) {
569569
if (false !== $pos = strpos($scalar, '#')) {
570570
$value = substr($scalar, 1, $pos - 2);
571571
} else {
@@ -595,11 +595,11 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
595595
return false;
596596
case '!' === $scalar[0]:
597597
switch (true) {
598-
case str_starts_with($scalar, '!!str '):
598+
case 0 === strpos($scalar, '!!str '):
599599
return (string) substr($scalar, 6);
600-
case str_starts_with($scalar, '! '):
600+
case 0 === strpos($scalar, '! '):
601601
return substr($scalar, 2);
602-
case str_starts_with($scalar, '!php/object'):
602+
case 0 === strpos($scalar, '!php/object'):
603603
if (self::$objectSupport) {
604604
if (!isset($scalar[12])) {
605605
return false;
@@ -613,7 +613,7 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
613613
}
614614

615615
return null;
616-
case str_starts_with($scalar, '!php/const'):
616+
case 0 === strpos($scalar, '!php/const'):
617617
if (self::$constantSupport) {
618618
if (!isset($scalar[11])) {
619619
return '';
@@ -631,9 +631,9 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
631631
}
632632

633633
return null;
634-
case str_starts_with($scalar, '!!float '):
634+
case 0 === strpos($scalar, '!!float '):
635635
return (float) substr($scalar, 8);
636-
case str_starts_with($scalar, '!!binary '):
636+
case 0 === strpos($scalar, '!!binary '):
637637
return self::evaluateBinaryScalar(substr($scalar, 9));
638638
default:
639639
throw new ParseException(sprintf('The string "%s" could not be parsed as it uses an unsupported built-in tag.', $scalar), self::$parsedLineNumber, $scalar, self::$parsedFilename);

src/Symfony/Component/Yaml/Parser.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private function doParse(string $value, int $flags)
170170
}
171171

172172
// array
173-
if (isset($values['value']) && str_starts_with(ltrim($values['value'], ' '), '-')) {
173+
if (isset($values['value']) && 0 === strpos(ltrim($values['value'], ' '), '-')) {
174174
// Inline first child
175175
$currentLineNumber = $this->getRealCurrentLineNb();
176176

@@ -179,7 +179,7 @@ private function doParse(string $value, int $flags)
179179
$sequenceYaml .= "\n".$this->getNextEmbedBlock($sequenceIndentation, true);
180180

181181
$data[] = $this->parseBlock($currentLineNumber, rtrim($sequenceYaml), $flags);
182-
} elseif (!isset($values['value']) || '' == trim($values['value'], ' ') || str_starts_with(ltrim($values['value'], ' '), '#')) {
182+
} elseif (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) {
183183
$data[] = $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true) ?? '', $flags);
184184
} elseif (null !== $subTag = $this->getLineTag(ltrim($values['value'], ' '), $flags)) {
185185
$data[] = new TaggedValue(
@@ -211,7 +211,7 @@ private function doParse(string $value, int $flags)
211211
}
212212
} elseif (
213213
self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:(( |\t)++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
214-
&& (!str_contains($values['key'], ' #') || \in_array($values['key'][0], ['"', "'"]))
214+
&& (false === strpos($values['key'], ' #') || \in_array($values['key'][0], ['"', "'"]))
215215
) {
216216
if ($context && 'sequence' == $context) {
217217
throw new ParseException('You cannot define a mapping item when in a sequence.', $this->currentLineNb + 1, $this->currentLine, $this->filename);
@@ -306,7 +306,7 @@ private function doParse(string $value, int $flags)
306306
$subTag = null;
307307
if ($mergeNode) {
308308
// Merge keys
309-
} elseif (!isset($values['value']) || '' === $values['value'] || str_starts_with($values['value'], '#') || (null !== $subTag = $this->getLineTag($values['value'], $flags)) || '<<' === $key) {
309+
} elseif (!isset($values['value']) || '' === $values['value'] || 0 === strpos($values['value'], '#') || (null !== $subTag = $this->getLineTag($values['value'], $flags)) || '<<' === $key) {
310310
// hash
311311
// if next line is less indented or equal, then it means that the current value is null
312312
if (!$this->isNextLineIndented() && !$this->isNextLineUnIndentedCollection()) {
@@ -453,7 +453,7 @@ private function doParse(string $value, int $flags)
453453
throw new ParseException('Unable to parse.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
454454
}
455455

456-
if (str_contains($line, ': ')) {
456+
if (false !== strpos($line, ': ')) {
457457
@trigger_error('Support for mapping keys in multi-line blocks is deprecated since Symfony 4.3 and will throw a ParseException in 5.0.', \E_USER_DEPRECATED);
458458
}
459459

@@ -463,7 +463,7 @@ private function doParse(string $value, int $flags)
463463
$value .= ' ';
464464
}
465465

466-
if ('' !== trim($line) && str_ends_with($line, '\\')) {
466+
if ('' !== trim($line) && '\\' === substr($line, -1)) {
467467
$value .= ltrim(substr($line, 0, -1));
468468
} elseif ('' !== trim($line)) {
469469
$value .= trim($line);
@@ -472,7 +472,7 @@ private function doParse(string $value, int $flags)
472472
if ('' === trim($line)) {
473473
$previousLineWasNewline = true;
474474
$previousLineWasTerminatedWithBackslash = false;
475-
} elseif (str_ends_with($line, '\\')) {
475+
} elseif ('\\' === substr($line, -1)) {
476476
$previousLineWasNewline = false;
477477
$previousLineWasTerminatedWithBackslash = true;
478478
} else {
@@ -716,7 +716,7 @@ private function moveToPreviousLine(): bool
716716
*/
717717
private function parseValue(string $value, int $flags, string $context)
718718
{
719-
if (str_starts_with($value, '*')) {
719+
if (0 === strpos($value, '*')) {
720720
if (false !== $pos = strpos($value, '#')) {
721721
$value = substr($value, 1, $pos - 2);
722722
} else {
@@ -803,7 +803,7 @@ private function parseValue(string $value, int $flags, string $context)
803803

804804
$parsedValue = Inline::parse($value, $flags, $this->refs);
805805

806-
if ('mapping' === $context && \is_string($parsedValue) && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && str_contains($parsedValue, ': ')) {
806+
if ('mapping' === $context && \is_string($parsedValue) && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($parsedValue, ': ')) {
807807
throw new ParseException('A colon cannot be used in an unquoted mapping value.', $this->getRealCurrentLineNb() + 1, $value, $this->filename);
808808
}
809809

@@ -1073,7 +1073,7 @@ private function isNextLineUnIndentedCollection(): bool
10731073
*/
10741074
private function isStringUnIndentedCollectionItem(): bool
10751075
{
1076-
return '-' === rtrim($this->currentLine) || str_starts_with($this->currentLine, '- ');
1076+
return '-' === rtrim($this->currentLine) || 0 === strpos($this->currentLine, '- ');
10771077
}
10781078

10791079
/**

src/Symfony/Component/Yaml/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=7.1.3",
20-
"symfony/polyfill-ctype": "~1.8",
21-
"symfony/polyfill-php80": "^1.16"
20+
"symfony/polyfill-ctype": "~1.8"
2221
},
2322
"require-dev": {
2423
"symfony/console": "^3.4|^4.0|^5.0"

0 commit comments

Comments
 (0)
0