Skip to content

[Dotenv][Yaml] Remove PHP 8.0 polyfill #42296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Symfony/Component/Dotenv/Dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function populate(array $values, bool $overrideExistingVars = false): voi
$loadedVars = array_flip(explode(',', $_SERVER['SYMFONY_DOTENV_VARS'] ?? $_ENV['SYMFONY_DOTENV_VARS'] ?? ''));

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

private function resolveCommands(string $value, array $loadedVars): string
{
if (!str_contains($value, '$')) {
if (false === strpos($value, '$')) {
return $value;
}

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

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

private function resolveVariables(string $value, array $loadedVars): string
{
if (!str_contains($value, '$')) {
if (false === strpos($value, '$')) {
return $value;
}

Expand Down Expand Up @@ -461,7 +461,7 @@ private function resolveVariables(string $value, array $loadedVars): string
$value = $this->values[$name];
} elseif (isset($_ENV[$name])) {
$value = $_ENV[$name];
} elseif (isset($_SERVER[$name]) && !str_starts_with($name, 'HTTP_')) {
} elseif (isset($_SERVER[$name]) && 0 !== strpos($name, 'HTTP_')) {
$value = $_SERVER[$name];
} elseif (isset($this->values[$name])) {
$value = $this->values[$name];
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Dotenv/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
}
],
"require": {
"php": ">=7.1.3",
"symfony/polyfill-php80": "^1.16"
"php": ">=7.1.3"
},
"require-dev": {
"symfony/process": "^3.4.2|^4.0|^5.0"
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Yaml/Command/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private function displayTxt(SymfonyStyle $io, array $filesInfo): int
$io->text('<error> ERROR </error>'.($info['file'] ? sprintf(' in %s', $info['file']) : ''));
$io->text(sprintf('<error> >> %s</error>', $info['message']));

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

if (isset($v['message']) && str_contains($v['message'], 'PARSE_CUSTOM_TAGS')) {
if (isset($v['message']) && false !== strpos($v['message'], 'PARSE_CUSTOM_TAGS')) {
$v['message'] .= ' Use the --parse-tags option if you want parse custom tags.';
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Yaml/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function dump($input, int $inline = 0, int $indent = 0, int $flags = 0):
$output .= "\n";
}

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

if (Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value->getValue()) && str_contains($value->getValue(), "\n") && !str_contains($value->getValue(), "\r\n")) {
if (Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value->getValue()) && false !== strpos($value->getValue(), "\n") && false === strpos($value->getValue(), "\r\n")) {
// If the first line starts with a space character, the spec requires a blockIndicationIndicator
// http://www.yaml.org/spec/1.2/spec.html#id2793979
$blockIndentationIndicator = (' ' === substr($value->getValue(), 0, 1)) ? (string) $this->indentation : '';
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Exception/ParseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private function updateRepr()
$this->message = $this->rawMessage;

$dot = false;
if (str_ends_with($this->message, '.')) {
if ('.' === substr($this->message, -1)) {
$this->message = substr($this->message, 0, -1);
$dot = true;
}
Expand Down
16 changes: 8 additions & 8 deletions src/Symfony/Component/Yaml/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ private static function parseSequence(string $sequence, int $flags, int &$i = 0,
$value = self::parseScalar($sequence, $flags, [',', ']'], $i, null === $tag, $references);

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

if (str_starts_with($scalar, '*')) {
if (0 === strpos($scalar, '*')) {
if (false !== $pos = strpos($scalar, '#')) {
$value = substr($scalar, 1, $pos - 2);
} else {
Expand Down Expand Up @@ -595,11 +595,11 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
return false;
case '!' === $scalar[0]:
switch (true) {
case str_starts_with($scalar, '!!str '):
case 0 === strpos($scalar, '!!str '):
return (string) substr($scalar, 6);
case str_starts_with($scalar, '! '):
case 0 === strpos($scalar, '! '):
return substr($scalar, 2);
case str_starts_with($scalar, '!php/object'):
case 0 === strpos($scalar, '!php/object'):
if (self::$objectSupport) {
if (!isset($scalar[12])) {
return false;
Expand All @@ -613,7 +613,7 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
}

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

return null;
case str_starts_with($scalar, '!!float '):
case 0 === strpos($scalar, '!!float '):
return (float) substr($scalar, 8);
case str_starts_with($scalar, '!!binary '):
case 0 === strpos($scalar, '!!binary '):
return self::evaluateBinaryScalar(substr($scalar, 9));
default:
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);
Expand Down
20 changes: 10 additions & 10 deletions src/Symfony/Component/Yaml/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private function doParse(string $value, int $flags)
}

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

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

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

if (str_contains($line, ': ')) {
if (false !== strpos($line, ': ')) {
@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);
}

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

if ('' !== trim($line) && str_ends_with($line, '\\')) {
if ('' !== trim($line) && '\\' === substr($line, -1)) {
$value .= ltrim(substr($line, 0, -1));
} elseif ('' !== trim($line)) {
$value .= trim($line);
Expand All @@ -472,7 +472,7 @@ private function doParse(string $value, int $flags)
if ('' === trim($line)) {
$previousLineWasNewline = true;
$previousLineWasTerminatedWithBackslash = false;
} elseif (str_ends_with($line, '\\')) {
} elseif ('\\' === substr($line, -1)) {
$previousLineWasNewline = false;
$previousLineWasTerminatedWithBackslash = true;
} else {
Expand Down Expand Up @@ -716,7 +716,7 @@ private function moveToPreviousLine(): bool
*/
private function parseValue(string $value, int $flags, string $context)
{
if (str_starts_with($value, '*')) {
if (0 === strpos($value, '*')) {
if (false !== $pos = strpos($value, '#')) {
$value = substr($value, 1, $pos - 2);
} else {
Expand Down Expand Up @@ -803,7 +803,7 @@ private function parseValue(string $value, int $flags, string $context)

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

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

Expand Down Expand Up @@ -1073,7 +1073,7 @@ private function isNextLineUnIndentedCollection(): bool
*/
private function isStringUnIndentedCollectionItem(): bool
{
return '-' === rtrim($this->currentLine) || str_starts_with($this->currentLine, '- ');
return '-' === rtrim($this->currentLine) || 0 === strpos($this->currentLine, '- ');
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Yaml/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
],
"require": {
"php": ">=7.1.3",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-php80": "^1.16"
"symfony/polyfill-ctype": "~1.8"
},
"require-dev": {
"symfony/console": "^3.4|^4.0|^5.0"
Expand Down