From 50fdcd6c4f40fb9a97515b34d1b1e60096a6422f Mon Sep 17 00:00:00 2001 From: Brandon Kelly Date: Sun, 21 May 2017 07:18:42 -0700 Subject: [PATCH 1/8] Fixed filename in help text for update-data.php --- src/Symfony/Component/Intl/Resources/bin/update-data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Intl/Resources/bin/update-data.php b/src/Symfony/Component/Intl/Resources/bin/update-data.php index fe527efecc..0914d26ec6 100644 --- a/src/Symfony/Component/Intl/Resources/bin/update-data.php +++ b/src/Symfony/Component/Intl/Resources/bin/update-data.php @@ -36,7 +36,7 @@ $argv = $_SERVER['argv']; if ($argc > 3 || 2 === $argc && '-h' === $argv[1]) { bailout(<<<'MESSAGE' -Usage: php update-icu-component.php +Usage: php update-data.php Updates the ICU data for Symfony to the latest version of ICU. From 49d6604ee4bd89a5d63b370151536722cf70392c Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 22 May 2017 13:36:46 +0200 Subject: [PATCH 2/8] Fix file perms --- src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php | 0 src/Symfony/Component/Finder/Tests/GlobTest.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php mode change 100755 => 100644 src/Symfony/Component/Finder/Tests/GlobTest.php diff --git a/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php b/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php old mode 100755 new mode 100644 diff --git a/src/Symfony/Component/Finder/Tests/GlobTest.php b/src/Symfony/Component/Finder/Tests/GlobTest.php old mode 100755 new mode 100644 From 6350dab5bf7a05e72d6ae531c9e89f876de32f7e Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 23 May 2017 13:49:26 +0200 Subject: [PATCH 3/8] don't call getTrustedHeaderName() if possible --- .../HttpKernel/Fragment/InlineFragmentRenderer.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php b/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php index 09ce50df4d..437b40bf95 100644 --- a/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php +++ b/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php @@ -119,7 +119,11 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer // Sub-request object will point to localhost as client ip and real client ip // will be included into trusted header for client ip try { - if ($trustedHeaderName = Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP, false)) { + if (Request::HEADER_X_FORWARDED_FOR & Request::getTrustedHeaderSet()) { + $currentXForwardedFor = $request->headers->get('X_FORWARDED_FOR', ''); + + $server['HTTP_X_FORWARDED_FOR'] = ($currentXForwardedFor ? $currentXForwardedFor.', ' : '').$request->getClientIp(); + } elseif (method_exists(Request::class, 'getTrustedHeaderName') && $trustedHeaderName = Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP, false)) { $currentXForwardedFor = $request->headers->get($trustedHeaderName, ''); $server['HTTP_'.$trustedHeaderName] = ($currentXForwardedFor ? $currentXForwardedFor.', ' : '').$request->getClientIp(); From ae52fe6dabf45767f54ce0a71abd9fcb92963dad Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 23 May 2017 11:43:45 +0200 Subject: [PATCH 4/8] [Yaml] parse PHP constants in mapping keys --- src/Symfony/Component/Yaml/Parser.php | 11 +++- .../Component/Yaml/Tests/ParserTest.php | 50 +++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 52cd1867ef..42f61af9de 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -208,7 +208,7 @@ class Parser $this->refs[$isRef] = end($data); } } elseif ( - self::preg_match('#^(?P'.Inline::REGEX_QUOTED_STRING.'|(?:![^\s]++\s++)?[^ \'"\[\{!].*?) *\:(\s++(?P.+))?$#u', rtrim($this->currentLine), $values) + self::preg_match('#^(?P'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?(?:![^\s]++\s++)?[^ \'"\[\{!].*?) *\:(\s++(?P.+))?$#u', rtrim($this->currentLine), $values) && (false === strpos($values['key'], ' #') || in_array($values['key'][0], array('"', "'"))) ) { if ($context && 'sequence' == $context) { @@ -221,7 +221,14 @@ class Parser try { Inline::$parsedLineNumber = $this->getRealCurrentLineNb(); $i = 0; - $key = Inline::parseScalar($values['key'], 0, null, $i, !(Yaml::PARSE_KEYS_AS_STRINGS & $flags)); + $evaluateKey = !(Yaml::PARSE_KEYS_AS_STRINGS & $flags); + + // constants in key will be evaluated anyway + if (isset($values['key'][0]) && '!' === $values['key'][0] && Yaml::PARSE_CONSTANT & $flags) { + $evaluateKey = true; + } + + $key = Inline::parseScalar($values['key'], 0, null, $i, $evaluateKey); } catch (ParseException $e) { $e->setParsedLine($this->getRealCurrentLineNb() + 1); $e->setSnippet($this->currentLine); diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index c8f4a7d40e..a0bef9d528 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -1819,9 +1819,59 @@ bar: YAML; $this->parser->parse($yaml); } + + public function testPhpConstantTagMappingKey() + { + $yaml = << array( + 'foo' => array( + 'from' => array( + 'bar', + ), + 'to' => 'baz', + ), + ), + ); + + $this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT)); + } + + public function testPhpConstantTagMappingKeyWithKeysCastToStrings() + { + $yaml = << array( + 'foo' => array( + 'from' => array( + 'bar', + ), + 'to' => 'baz', + ), + ), + ); + + $this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT | Yaml::PARSE_KEYS_AS_STRINGS)); + } } class B { public $b = 'foo'; + + const FOO = 'foo'; + const BAR = 'bar'; + const BAZ = 'baz'; } From a8414962389538142e65f0cb682772b102576208 Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Thu, 25 May 2017 11:59:16 +0200 Subject: [PATCH 5/8] [Form] Remove DateTimeToStringTransformer $parseUsingPipe option --- .../DateTimeToStringTransformer.php | 80 +------------------ .../DateTimeToStringTransformerTest.php | 16 +--- 2 files changed, 4 insertions(+), 92 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php index 56dee35027..daeee5cce7 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php @@ -40,15 +40,6 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer */ private $parseFormat; - /** - * Whether to parse by appending a pipe "|" to the parse format. - * - * This only works as of PHP 5.3.7. - * - * @var bool - */ - private $parseUsingPipe; - /** * Transforms a \DateTime instance to a string. * @@ -57,18 +48,15 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer * @param string $inputTimezone The name of the input timezone * @param string $outputTimezone The name of the output timezone * @param string $format The date format - * @param bool $parseUsingPipe Whether to parse by appending a pipe "|" to the parse format * * @throws UnexpectedTypeException if a timezone is not a string */ - public function __construct($inputTimezone = null, $outputTimezone = null, $format = 'Y-m-d H:i:s', $parseUsingPipe = true) + public function __construct($inputTimezone = null, $outputTimezone = null, $format = 'Y-m-d H:i:s') { parent::__construct($inputTimezone, $outputTimezone); $this->generateFormat = $this->parseFormat = $format; - $this->parseUsingPipe = $parseUsingPipe || null === $parseUsingPipe; - // See http://php.net/manual/en/datetime.createfromformat.php // The character "|" in the format makes sure that the parts of a date // that are *not* specified in the format are reset to the corresponding @@ -77,7 +65,7 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer // where the time corresponds to the current server time. // With "|" and "Y-m-d", "2010-02-03" becomes "2010-02-03 00:00:00", // which is at least deterministic and thus used here. - if ($this->parseUsingPipe && false === strpos($this->parseFormat, '|')) { + if (false === strpos($this->parseFormat, '|')) { $this->parseFormat .= '|'; } } @@ -147,70 +135,6 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer } try { - // On PHP versions < 5.3.7 we need to emulate the pipe operator - // and reset parts not given in the format to their equivalent - // of the UNIX base timestamp. - if (!$this->parseUsingPipe) { - list($year, $month, $day, $hour, $minute, $second) = explode('-', $dateTime->format('Y-m-d-H-i-s')); - - // Check which of the date parts are present in the pattern - preg_match( - '/('. - '(?P[djDl])|'. - '(?P[FMmn])|'. - '(?P[Yy])|'. - '(?P[ghGH])|'. - '(?Pi)|'. - '(?Ps)|'. - '(?Pz)|'. - '(?PU)|'. - '[^djDlFMmnYyghGHiszU]'. - ')*/', - $this->parseFormat, - $matches - ); - - // preg_match() does not guarantee to set all indices, so - // set them unless given - $matches = array_merge(array( - 'day' => false, - 'month' => false, - 'year' => false, - 'hour' => false, - 'minute' => false, - 'second' => false, - 'dayofyear' => false, - 'timestamp' => false, - ), $matches); - - // Reset all parts that don't exist in the format to the - // corresponding part of the UNIX base timestamp - if (!$matches['timestamp']) { - if (!$matches['dayofyear']) { - if (!$matches['day']) { - $day = 1; - } - if (!$matches['month']) { - $month = 1; - } - } - if (!$matches['year']) { - $year = 1970; - } - if (!$matches['hour']) { - $hour = 0; - } - if (!$matches['minute']) { - $minute = 0; - } - if (!$matches['second']) { - $second = 0; - } - $dateTime->setDate($year, $month, $day); - $dateTime->setTime($hour, $minute, $second); - } - } - if ($this->inputTimezone !== $this->outputTimezone) { $dateTime->setTimezone(new \DateTimeZone($this->inputTimezone)); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php index 883634985a..e2389ebf00 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php @@ -120,21 +120,9 @@ class DateTimeToStringTransformerTest extends DateTimeTestCase /** * @dataProvider dataProvider */ - public function testReverseTransformUsingPipe($format, $input, $output) + public function testReverseTransform($format, $input, $output) { - $reverseTransformer = new DateTimeToStringTransformer('UTC', 'UTC', $format, true); - - $output = new \DateTime($output); - - $this->assertDateTimeEquals($output, $reverseTransformer->reverseTransform($input)); - } - - /** - * @dataProvider dataProvider - */ - public function testReverseTransformWithoutUsingPipe($format, $input, $output) - { - $reverseTransformer = new DateTimeToStringTransformer('UTC', 'UTC', $format, false); + $reverseTransformer = new DateTimeToStringTransformer('UTC', 'UTC', $format); $output = new \DateTime($output); From 40f60ec60daa54fc83f4210f4715a9ccafad0a96 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Wed, 24 May 2017 21:00:11 -0400 Subject: [PATCH 6/8] Fixing missing abstract attribute in XmlDumper Caused mis-reporting of abstract key (always no) in debug:container --- .../DependencyInjection/Dumper/XmlDumper.php | 4 ++++ .../Tests/Dumper/XmlDumperTest.php | 8 ++++++++ .../Tests/Fixtures/containers/container_abstract.php | 12 ++++++++++++ .../Tests/Fixtures/xml/services_abstract.xml | 6 ++++++ 4 files changed, 30 insertions(+) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_abstract.php create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_abstract.xml diff --git a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php index 3306c4b1a6..c793e9aed0 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php @@ -191,6 +191,10 @@ class XmlDumper extends Dumper $service->appendChild($factory); } + if ($definition->isAbstract()) { + $service->setAttribute('abstract', 'true'); + } + if ($callable = $definition->getConfigurator()) { $configurator = $this->document->createElement('configurator'); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php index 72ae589720..687ba1efcb 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php @@ -184,4 +184,12 @@ class XmlDumperTest extends TestCase $this->assertEquals(file_get_contents(self::$fixturesPath.'/xml/services21.xml'), $dumper->dump()); } + + public function testDumpAbstractServices() + { + $container = include self::$fixturesPath.'/containers/container_abstract.php'; + $dumper = new XmlDumper($container); + + $this->assertEquals(file_get_contents(self::$fixturesPath.'/xml/services_abstract.xml'), $dumper->dump()); + } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_abstract.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_abstract.php new file mode 100644 index 0000000000..9622a273d3 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_abstract.php @@ -0,0 +1,12 @@ +register('foo', 'Foo') + ->setAbstract(true) +; + +return $container; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_abstract.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_abstract.xml new file mode 100644 index 0000000000..97e5ce419b --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_abstract.xml @@ -0,0 +1,6 @@ + + + + + + From 56892819e35ab2417ac989f55fc6faf93c61996e Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Thu, 25 May 2017 12:05:01 +0200 Subject: [PATCH 7/8] [DI] Avoid private call to Container::has() --- .../DependencyInjection/Dumper/PhpDumper.php | 8 ++++++++ .../Tests/Dumper/PhpDumperTest.php | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 28cad05b59..4431418d85 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -1191,9 +1191,17 @@ EOF; $conditions = array(); foreach ($services as $service) { + if ($this->container->hasDefinition($service) && !$this->container->getDefinition($service)->isPublic()) { + continue; + } + $conditions[] = sprintf("\$this->has('%s')", $service); } + if (!$conditions) { + return $code; + } + // re-indent the wrapped code $code = implode("\n", array_map(function ($line) { return $line ? ' '.$line : $line; }, explode("\n", $code))); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index c63d5ec183..2ad701aa6d 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -15,6 +15,7 @@ use DummyProxyDumper; use PHPUnit\Framework\TestCase; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\DependencyInjection\Reference; @@ -406,4 +407,21 @@ class PhpDumperTest extends TestCase $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_private_frozen.php', $dumper->dump()); } + + public function testPrivateWithIgnoreOnInvalidReference() + { + require_once self::$fixturesPath.'/includes/classes.php'; + + $container = new ContainerBuilder(); + $container->register('not_invalid', 'BazClass') + ->setPublic(false); + $container->register('bar', 'BarClass') + ->addMethodCall('setBaz', array(new Reference('not_invalid', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))); + + $dumper = new PhpDumper($container); + eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Private_With_Ignore_On_Invalid_Reference'))); + + $container = new \Symfony_DI_PhpDumper_Test_Private_With_Ignore_On_Invalid_Reference(); + $this->assertInstanceOf('BazClass', $container->get('bar')->getBaz()); + } } From 9ba12b0d2a79e89f9bc0b9836a35ce2165aca810 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 25 May 2017 09:51:51 +0200 Subject: [PATCH 8/8] [HttpFoundation] Add Request::HEADER_X_FORWARDED_AWS_ELB const --- src/Symfony/Component/HttpFoundation/Request.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 4962256376..cf812a960f 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -30,12 +30,13 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface; */ class Request { - const HEADER_FORWARDED = 0b00001; - const HEADER_X_FORWARDED_ALL = 0b11110; - const HEADER_X_FORWARDED_FOR = 2; - const HEADER_X_FORWARDED_HOST = 4; - const HEADER_X_FORWARDED_PROTO = 8; - const HEADER_X_FORWARDED_PORT = 16; + const HEADER_FORWARDED = 0b00001; // When using RFC 7239 + const HEADER_X_FORWARDED_FOR = 0b00010; + const HEADER_X_FORWARDED_HOST = 0b00100; + const HEADER_X_FORWARDED_PROTO = 0b01000; + const HEADER_X_FORWARDED_PORT = 0b10000; + const HEADER_X_FORWARDED_ALL = 0b11110; // All "X-Forwarded-*" headers + const HEADER_X_FORWARDED_AWS_ELB = 0b11010; // AWS ELB doesn't send X-Forwarded-Host /** @deprecated since version 3.3, to be removed in 4.0 */ const HEADER_CLIENT_IP = self::HEADER_X_FORWARDED_FOR;