8000 Merge branch '5.1' into 5.2 · symfony/symfony@a5ef152 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a5ef152

Browse files
Merge branch '5.1' into 5.2
* 5.1: Changed private static array-properties to const
2 parents c11a6da + 6f73287 commit a5ef152

File tree

58 files changed

+279
-283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
< F438 span class="prc-TooltipV2-Tooltip-cYMVY" data-direction="se" aria-hidden="true" id=":R12plab:">Collapse file tree

58 files changed

+279
-283
lines changed

src/Symfony/Bridge/Monolog/Command/ServerLogCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
class ServerLogCommand extends Command
3030
{
31-
private static $bgColor = ['black', 'blue', 'cyan', 'green', 'magenta', 'red', 'white', 'yellow'];
31+
private const BG_COLOR = ['black', 'blue', 'cyan', 'green', 'magenta', 'red', 'white', 'yellow'];
3232

3333
private $el;
3434
private $handler;
@@ -151,7 +151,7 @@ private function displayLog(OutputInterface $output, int $clientId, array $recor
151151
if (isset($record['log_id'])) {
152152
$clientId = unpack('H*', $record['log_id'])[1];
153153
}
154-
$logBlock = sprintf('<bg=%s> </>', self::$bgColor[$clientId % 8]);
154+
$logBlock = sprintf('<bg=%s> </>', self::BG_COLOR[$clientId % 8]);
155155
$output->write($logBlock);
156156

157157
$this->handler->handle($record);

src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ConsoleFormatter implements FormatterInterface
3030
public const SIMPLE_FORMAT = "%datetime% %start_tag%%level_name%%end_tag% <comment>[%channel%]</> %message%%context%%extra%\n";
3131
public const SIMPLE_DATE = 'H:i:s';
3232

33-
private static $levelColorMap = [
33+
private const LEVEL_COLOR_MAP = [
3434
Logger::DEBUG => 'fg=white',
3535
Logger::INFO => 'fg=green',
3636
Logger::NOTICE => 'fg=blue',
@@ -104,8 +104,6 @@ public function format(array $record)
104104
{
105105
$record = $this->replacePlaceHolder($record);
106106

107-
$levelColor = self::$levelColorMap[$record['level']];
108-
109107
if (!$this->options['ignore_empty_context_and_extra'] || !empty($record['context'])) {
110108
$context = ($this->options['multiline'] ? "\n" : ' ').$this->dumpData($record['context']);
111109
} else {
@@ -122,7 +120,7 @@ public function format(array $record)
122120
'%datetime%' => $record['datetime'] instanceof \DateTimeInterface
123121
? $record['datetime']->format($this->options['date_format'])
124122
: $record['datetime'],
125-
'%start_tag%' => sprintf('<%s>', $levelColor),
123+
'%start_tag%' => sprintf('<%s>', self::LEVEL_COLOR_MAP[$record['level']]),
126124
'%level_name%' => sprintf($this->options['level_name_format'], $record['level_name']),
127125
'%end_tag%' => '</>',
128126
'%channel%' => $record['channel'],

src/Symfony/Bridge/Twig/UndefinedCallableHandler.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
*/
2020
class UndefinedCallableHandler
2121
{
22-
private static $filterComponents = [
22+
private const FILTER_COMPONENTS = [
2323
'humanize' => 'form',
2424
'trans' => 'translation',
2525
'yaml_encode' => 'yaml',
2626
'yaml_dump' => 'yaml',
2727
];
2828

29-
private static $functionComponents = [
29+
private const FUNCTION_COMPONENTS = [
3030
'asset' => 'asset',
3131
'asset_version' => 'asset',
3232
'dump' => 'debug-bundle',
@@ -56,7 +56,7 @@ class UndefinedCallableHandler
5656
'workflow_marked_places' => 'workflow',
5757
];
5858

59-
private static $fullStackEnable = [
59+
private const FULL_STACK_ENABLE = [
6060
'form' => 'enable "framework.form"',
6161
'security-core' => 'add the "SecurityBundle"',
6262
'security-http' => 'add the "SecurityBundle"',
@@ -66,30 +66,30 @@ class UndefinedCallableHandler
6666

6767
public static function onUndefinedFilter(string $name): bool
6868
{
69-
if (!isset(self::$filterComponents[$name])) {
69+
if (!isset(self::FILTER_COMPONENTS[$name])) {
7070
return false;
7171
}
7272

73-
self::onUndefined($name, 'filter', self::$filterComponents[$name]);
73+
self::onUndefined($name, 'filter', self::FILTER_COMPONENTS[$name]);
7474

7575
return true;
7676
}
7777

7878
public static function onUndefinedFunction(string $name): bool
7979
{
80-
if (!isset(self::$functionComponents[$name])) {
80+
if (!isset(self::FUNCTION_COMPONENTS[$name])) {
8181
return false;
8282
}
8383

84-
self::onUndefined($name, 'function', self::$functionComponents[$name]);
84+
self::onUndefined($name, 'function', self::FUNCTION_COMPONENTS[$name]);
8585

8686
return true;
8787
}
8888

8989
private static function onUndefined(string $name, string $type, string $component)
9090
{
91-
if (class_exists(FullStack::class) && isset(self::$fullStackEnable[$component])) {
92-
throw new SyntaxError(sprintf('Did you forget to %s? Unknown %s "%s".', self::$fullStackEnable[$component], $type, $name));
91+
if (class_exists(FullStack::class) && isset(self::FULL_STACK_ENABLE[$component])) {
92+
throw new SyntaxError(sprintf('Did you forget to %s? Unknown %s "%s".', self::FULL_STACK_ENABLE[$component], $type, $name));
9393
}
9494

9595
throw new SyntaxError(sprintf('Did you forget to run "composer require symfony/%s"? Unknown %s "%s".', $component, $type, $name));

src/Symfony/Component/BrowserKit/Cookie.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Cookie
2222
* Handles dates as defined by RFC 2616 section 3.3.1, and also some other
2323
* non-standard, but common formats.
2424
*/
25-
private static $dateFormats = [
25+
private const DATE_FORMATS = [
2626
'D, d M Y H:i:s T',
2727
'D, d-M-y H:i:s T',
2828
'D, d-M-Y H:i:s T',
@@ -92,7 +92,7 @@ public function __toString()
9292

9393
if (null !== $this->expires) {
9494
$dateTime = \DateTime::createFromFormat('U', $this->expires, new \DateTimeZone('GMT'));
95-
$cookie .= '; expires='.str_replace('+0000', '', $dateTime->format(self::$dateFormats[0]));
95+
$cookie .= '; expires='.str_replace('+0000', '', $dateTime->format(self::DATE_FORMATS[0]));
9696
}
9797

9898
if ('' !== $this->domain) {
@@ -205,7 +205,7 @@ private static function parseDate(string $dateValue): ?string
205205
$dateValue = substr($dateValue, 1, -1);
206206
}
207207

208-
foreach (self::$dateFormats as $dateFormat) {
208+
foreach (self::DATE_FORMATS as $dateFormat) {
209209
if (false !== $date = \DateTime::createFromFormat($dateFormat, $dateValue, new \DateTimeZone('GMT'))) {
210210
return $date->format('U');
211211
}

src/Symfony/Component/DependencyInjection/Compiler/RegisterEnvVarProcessorsPass.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
class RegisterEnvVarProcessorsPass implements CompilerPassInterface
2727
{
28-
private static $allowedTypes = ['array', 'bool', 'float', 'int', 'string'];
28+
private const ALLOWED_TYPES = ['array', 'bool', 'float', 'int', 'string'];
2929

3030
public function process(ContainerBuilder $container)
3131
{
@@ -65,8 +65,8 @@ private static function validateProvidedTypes(string $types, string $class): arr
6565
$types = explode('|', $types);
6666

6767
foreach ($types as $type) {
68-
if (!\in_array($type, self::$allowedTypes)) {
69-
throw new InvalidArgumentException(sprintf('Invalid type "%s" returned by "%s::getProvidedTypes()", expected one of "%s".', $type, $class, implode('", "', self::$allowedTypes)));
68+
if (!\in_array($type, self::ALLOWED_TYPES)) {
69+
throw new InvalidArgumentException(sprintf('Invalid type "%s" returned by "%s::getProvidedTypes()", expected one of "%s".', $type, $class, implode('", "', self::ALLOWED_TYPES)));
7070
}
7171
}
7272

src/Symfony/Component/DependencyInjection/Compiler/ValidateEnvPlaceholdersPass.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
class ValidateEnvPlaceholdersPass implements CompilerPassInterface
2828
{
29-
private static $typeFixtures = ['array' => [], 'bool' => false, 'float' => 0.0, 'int' => 0, 'string' => ''];
29+
private const TYPE_FIXTURES = ['array' => [], 'bool' => false, 'float' => 0.0, 'int' => 0, 'string' => ''];
3030

3131
private $extensionConfig = [];
3232

@@ -52,13 +52,13 @@ public function process(ContainerBuilder $container)
5252
foreach ($resolvingBag->getEnvPlaceholders() + $resolvingBag->getUnusedEnvPlaceholders() as $env => $placeholders) {
5353
$values = [];
5454
if (false === $i = strpos($env, ':')) {
55-
$default = $defaultBag->has("env($env)") ? $defaultBag->get("env($env)") : self::$typeFixtures['string'];
55+
$default = $defaultBag->has("env($env)") ? $defaultBag->get("env($env)") : self::TYPE_FIXTURES['string'];
5656
$defaultType = null !== $default ? get_debug_type($default) : 'string';
5757
$values[$defaultType] = $default;
5858
} else {
5959
$prefix = substr($env, 0, $i);
6060
foreach ($envTypes[$prefix] ?? ['string'] as $type) {
61-
$values[$type] = self::$typeFixtures[$type] ?? null;
61+
$values[$type] = self::TYPE_FIXTURES[$type] ?? null;
6262
}
6363
}
6464
foreach ($placeholders as $placeholder) {

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
127127

128128
private $removedBindingIds = [];
129129

130-
private static $internalTypes = [
130+
private const INTERNAL_TYPES = [
131131
'int' => true,
132132
'float' => true,
133133
'string' => true,
@@ -334,7 +334,7 @@ public function getReflectionClass(?string $class, bool $throw = true): ?\Reflec
334334
return null;
335335
}
336336

337-
if (isset(self::$internalTypes[$class])) {
337+
if (isset(self::INTERNAL_TYPES[$class])) {
338338
return null;
339339
}
340340

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
*/
4040
class YamlFileLoader extends FileLoader
4141
{
42-
private static $serviceKeywords = [
42+
private const SERVICE_KEYWORDS = [
4343
'alias' => 'alias',
4444
'parent' => 'parent',
4545
'class' => 'class',
@@ -65,7 +65,7 @@ class YamlFileLoader extends FileLoader
6565
'bind' => 'bind',
6666
];
6767

68-
private static $prototypeKeywords = [
68+
private const PROTOTYPE_KEYWORDS = [
6969
'resource' => 'resource',
7070
'namespace' => 'namespace',
7171
'exclude' => 'exclude',
@@ -86,7 +86,7 @@ class YamlFileLoader extends FileLoader
8686
'bind' => 'bind',
8787
];
8888

89-
private static $instanceofKeywords = [
89+
private const INSTANCEOF_KEYWORDS = [
9090
'shared' => 'shared',
9191
'lazy' => 'lazy',
9292
'public' => 'public',
@@ -98,7 +98,7 @@ class YamlFileLoader extends FileLoader
9898
'bind' => 'bind',
9999
];
100100

101-
private static $defaultsKeywords = [
101+
private const DEFAULTS_KEYWORDS = [
102102
'public' => 'public',
103103
'tags' => 'tags',
104104
'autowire' => 'autowire',
@@ -251,8 +251,8 @@ private function parseDefaults(array &$content, string $file): array
251251
}
252252

253253
foreach ($defaults as $key => $default) {
254-
if (!isset(self::$defaultsKeywords[$key])) {
255-
throw new InvalidArgumentException(sprintf('The configuration key "%s" cannot be used to define a default value in "%s". Allowed keys are "%s".', $key, $file, implode('", "', self::$defaultsKeywords)));
254+
if (!isset(self::DEFAULTS_KEYWORDS[$key])) {
255+
throw new InvalidArgumentException(sprintf('The configuration key "%s" cannot be used to define a default value in "%s". Allowed keys are "%s".', $key, $file, implode('", "', self::DEFAULTS_KEYWORDS)));
256256
}
257257
}
258258

@@ -919,11 +919,11 @@ private function loadFromExtensions(array $content)
919919
private function checkDefinition(string $id, array $definition, string $file)
920920
{
921921
if ($this->isLoadingInstanceof) {
922-
$keywords = self::$instanceofKeywords;
922+
$keywords = self::INSTANCEOF_KEYWORDS;
923923
} elseif (isset($definition['resource']) || isset($definition['namespace'])) {
924-
$keywords = self::$prototypeKeywords;
924+
$keywords = self::PROTOTYPE_KEYWORDS;
925925
} else {
926-
$keywords = self::$serviceKeywords;
926+
$keywords = self::SERVICE_KEYWORDS;
927927
}
928928

929929
foreach ($definition as $key => $value) {

src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
*/
2121
class BinaryNode extends Node
2222
{
23-
private static $operators = [
23+
private const OPERATORS = [
2424
'~' => '.',
2525
'and' => '&&',
2626
'or' => '||',
2727
];
2828

29-
private static $functions = [
29+
private const FUNCTIONS = [
3030
'**' => 'pow',
3131
'..' => 'range',
3232
'in' => 'in_array',
@@ -57,9 +57,9 @@ public function compile(Compiler $compiler)
5757
return;
5858
}
5959

60-
if (isset(self::$functions[$operator])) {
60+
if (isset(self::FUNCTIONS[$operator])) {
6161
$compiler
62-
->raw(sprintf('%s(', self::$functions[$operator]))
62+
->raw(sprintf('%s(', self::FUNCTIONS[$operator]))
6363
->compile($this->nodes['left'])
6464
->raw(', ')
6565
->compile($this->nodes['right'])
@@ -69,8 +69,8 @@ public function compile(Compiler $compiler)
6969
return;
7070
}
7171

72-
if (isset(self::$operators[$operator])) {
73-
$operator = self::$operators[$operator];
72+
if (isset(self::OPERATORS[$operator])) {
73+
$operator = self::OPERATORS[$operator];
7474
}
7575

7676
$compiler
@@ -89,13 +89,13 @@ public function evaluate(array $functions, array $values)
8989
$operator = $this->attributes['operator'];
9090
$left = $this->nodes['left']->evaluate($functions, $values);
9191

92-
if (isset(self::$functions[$operator])) {
92+
if (isset(self::FUNCTIONS[$operator])) {
9393
$right = $this->nodes['right']->evaluate($functions, $values);
9494

9595
if ('not in' === $operator) {
9696
return !\in_array($left, $right);
9797
}
98-
$f = self::$functions[$operator];
98+
$f = self::FUNCTIONS[$operator];
9999

100100
return $f($left, $right);
101101
}

src/Symfony/Component/ExpressionLanguage/Node/UnaryNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class UnaryNode extends Node
2222
{
23-
private static $operators = [
23+
private const OPERATORS = [
2424
'!' => '!',
2525
'not' => '!',
2626
'+' => '+',
@@ -39,7 +39,7 @@ public function compile(Compiler $compiler)
3939
{
4040
$compiler
4141
->raw('(')
42-
->raw(self::$operators[$this->attributes['operator']])
42+
->raw(self::OPERATORS[$this->attributes['operator']])
4343
->compile($this->nodes['node'])
4444
->raw(')')
4545
;

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateIntervalToArrayTransformer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DateIntervalToArrayTransformer implements DataTransformerInterface
3030
public const SECONDS = 'seconds';
3131
public const INVERT = 'invert';
3232

33-
private static $availableFields = [
33+
private const AVAILABLE_FIELDS = [
3434
self::YEARS => 'y',
3535
self::MONTHS => 'm',
3636
self::DAYS => 'd',
@@ -85,7 +85,7 @@ public function transform($dateInterval)
8585
throw new UnexpectedTypeException($dateInterval, \DateInterval::class);
8686
}
8787
$result = [];
88-
foreach (self::$availableFields as $field => $char) {
88+
foreach (self::AVAILABLE_FIELDS as $field => $char) {
8989
$result[$field] = $dateInterval->format('%'.($this->pad ? strtoupper($char) : $char));
9090
}
9191
if (\in_array('weeks', $this->fields, true)) {
@@ -134,7 +134,7 @@ public function reverseTransform($value)
134134
if (isset($value['invert']) && !\is_bool($value['invert'])) {
135135
throw new TransformationFailedException('The value of "invert" must be boolean.');
136136
}
137-
foreach (self::$availableFields as $field => $char) {
137+
foreach (self::AVAILABLE_FIELDS as $field => $char) {
138138
if ('invert' !== $field && isset($value[$field]) && !ctype_digit((string) $value[$field])) {
139139
throw new TransformationFailedException(sprintf('This amount of "%s" is invalid.', $field));
140140
}

src/Symfony/Component/Form/Extension/Core/Type/DateIntervalType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DateIntervalType extends AbstractType
3737
'minutes',
3838
'seconds',
3939
];
40-
private static $widgets = [
40+
private const WIDGETS = [
4141
'text' => TextType::class,
4242
'integer' => IntegerType::class,
4343
'choice' => ChoiceType::class,
@@ -112,7 +112,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
112112
$childOptions['choices'] = $options[$part];
113113
$childOptions['placeholder'] = $options['placeholder'][$part];
114114
}
115-
$childForm = $builder->create($part, self::$widgets[$options['widget']], $childOptions);
115+
$childForm = $builder->create($part, self::WIDGETS[$options['widget']], $childOptions);
116116
if ('integer' === $options['widget']) {
117117
$childForm->addModelTransformer(
118118
new ReversedTransformer(

src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class DateTimeType extends AbstractType
4040
*/
4141
public const HTML5_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";
4242

43-
private static $acceptedFormats = [
43+
private const ACCEPTED_FORMATS = [
4444
\IntlDateFormatter::FULL,
4545
\IntlDateFormatter::LONG,
4646
\IntlDateFormatter::MEDIUM,
@@ -71,7 +71,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
7171
$calendar = \IntlDateFormatter::GREGORIAN;
7272
$pattern = \is_string($options['format']) ? $options['format'] : null;
7373

74-
if (!\in_array($dateFormat, self::$acceptedFormats, true)) {
74+
if (!\in_array($dateFormat, self::ACCEPTED_FORMATS, true)) {
7575
throw new InvalidOptionsException('The "d 42F8 ate_format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom format.');
7676
}
7777

0 commit comments

Comments
 (0)
0