From 3855d5af0139c6069016cc21526e54414779b1a8 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Sat, 1 Dec 2018 20:35:42 +0100 Subject: [PATCH 1/3] [WebProfilerBundle] Split form field heading --- .../Resources/views/Collector/form.html.twig | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig index 02b77319ac..720da85750 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig @@ -177,6 +177,12 @@ color: inherit; text-decoration: inherit; } + h2 + h3.form-data-type { + margin-top: 0; + } + h3.form-data-type + h3 { + margin-top: 1em; + } {% endblock %} @@ -455,9 +461,10 @@ {% macro form_tree_details(name, data, forms_by_hash, show) %} {% import _self as tree %}
-

- {{ name|default('(no name)') }} {% if data.type_class is defined %}({{ profiler_dump(data.type_class) }}){% endif %} -

+

{{ name|default('(no name)') }}

+ {% if data.type_class is defined %} +

{{ profiler_dump(data.type_class) }}

+ {% endif %} {% if data.errors is defined and data.errors|length > 0 %}
From 6b65fac2cfaaeb980fb83feb8aed92eb39fa2ee6 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 2 Dec 2018 12:14:59 +0100 Subject: [PATCH 2/3] [Routing] fix taking verb into account when redirecting --- .../Component/Routing/Matcher/UrlMatcher.php | 14 ++++++++++---- .../Matcher/RedirectableUrlMatcherTest.php | 17 +++++++++++++++++ .../Routing/Tests/Matcher/UrlMatcherTest.php | 14 ++++++++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php index 69d73906fe..fc4554fff5 100644 --- a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php +++ b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php @@ -123,14 +123,15 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface foreach ($routes as $name => $route) { $compiledRoute = $route->compile(); $staticPrefix = $compiledRoute->getStaticPrefix(); + $requiredMethods = $route->getMethods(); // check the static prefix of the URL first. Only use the more expensive preg_match when it matches if ('' === $staticPrefix || 0 === strpos($pathinfo, $staticPrefix)) { // no-op - } elseif (!$supportsTrailingSlash) { + } elseif (!$supportsTrailingSlash || ($requiredMethods && !\in_array('GET', $requiredMethods))) { continue; } elseif ('/' === substr($staticPrefix, -1) && substr($staticPrefix, 0, -1) === $pathinfo) { - return; + return $this->allow = array(); } else { continue; } @@ -148,7 +149,10 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface } if ($hasTrailingSlash && '/' !== substr($pathinfo, -1)) { - return; + if (!$requiredMethods || \in_array('GET', $requiredMethods)) { + return $this->allow = array(); + } + continue; } $hostMatches = array(); @@ -163,7 +167,7 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface } // check HTTP method requirement - if ($requiredMethods = $route->getMethods()) { + if ($requiredMethods) { // HEAD and GET are equivalent as per RFC if ('HEAD' === $method = $this->context->getMethod()) { $method = 'GET'; @@ -180,6 +184,8 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface return $this->getAttributes($route, $name, array_replace($matches, $hostMatches, isset($status[1]) ? $status[1] : array())); } + + return array(); } /** diff --git a/src/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php b/src/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php index a7aea0ec07..9857f05024 100644 --- a/src/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php +++ b/src/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php @@ -128,6 +128,23 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest $this->assertSame(array('_route' => 'foo'), $matcher->match('/foo')); } + public function testSlashAndVerbPrecedenceWithRedirection() + { + $coll = new RouteCollection(); + $coll->add('a', new Route('/api/customers/{customerId}/contactpersons', array(), array(), array(), '', array(), array('post'))); + $coll->add('b', new Route('/api/customers/{customerId}/contactpersons/', array(), array(), array(), '', array(), array('get'))); + + $matcher = $this->getUrlMatcher($coll); + $expected = array( + '_route' => 'b', + 'customerId' => '123', + ); + $this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons/')); + + $matcher->expects($this->once())->method('redirect')->with('/api/customers/123/contactpersons/')->willReturn(array()); + $this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons')); + } + protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null) { return $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($routes, $context ?: new RequestContext())); diff --git a/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php b/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php index 0d4b44b090..ab682732ca 100644 --- a/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php +++ b/src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php @@ -502,6 +502,20 @@ class UrlMatcherTest extends TestCase $matcher->match('/'); } + public function testSlashAndVerbPrecedence() + { + $coll = new RouteCollection(); + $coll->add('a', new Route('/api/customers/{customerId}/contactpersons/', array(), array(), array(), '', array(), array('post'))); + $coll->add('b', new Route('/api/customers/{customerId}/contactpersons', array(), array(), array(), '', array(), array('get'))); + + $matcher = $this->getUrlMatcher($coll); + $expected = array( + '_route' => 'b', + 'customerId' => '123', + ); + $this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons')); + } + protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null) { return new UrlMatcher($routes, $context ?: new RequestContext()); From 2bf8a1cae6d425b6a854a909ab186c0943d85ad9 Mon Sep 17 00:00:00 2001 From: Vitaliy Ryaboy Date: Sat, 1 Dec 2018 19:23:29 +0100 Subject: [PATCH 3/3] [Serializer] fixed DateTimeNormalizer to maintain microseconds when a different timezone required --- .../Normalizer/DateTimeNormalizer.php | 3 +- .../Normalizer/DateTimeNormalizerTest.php | 76 +++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php index be469a4d53..aaa4e8b940 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php @@ -59,7 +59,8 @@ class DateTimeNormalizer implements NormalizerInterface, DenormalizerInterface $timezone = $this->getTimezone($context); if (null !== $timezone) { - $object = (new \DateTimeImmutable('@'.$object->getTimestamp()))->setTimezone($timezone); + $object = clone $object; + $object = $object->setTimezone($timezone); } return $object->format($format); diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/DateTimeNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/DateTimeNormalizerTest.php index 178519b30e..99b224996c 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/DateTimeNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/DateTimeNormalizerTest.php @@ -78,6 +78,82 @@ class DateTimeNormalizerTest extends TestCase yield array('2016-12-01T09:00:00+09:00', new \DateTimeImmutable('2016/12/01', new \DateTimeZone('UTC')), new \DateTimeZone('Japan')); } + /** + * @dataProvider normalizeUsingTimeZonePassedInContextAndExpectedFormatWithMicrosecondsProvider + */ + public function testNormalizeUsingTimeZonePassedInContextAndFormattedWithMicroseconds($expected, $expectedFormat, $input, $timezone) + { + $this->assertSame( + $expected, + $this->normalizer->normalize( + $input, + null, + array( + DateTimeNormalizer::TIMEZONE_KEY => $timezone, + DateTimeNormalizer::FORMAT_KEY => $expectedFormat, + ) + ) + ); + } + + public function normalizeUsingTimeZonePassedInContextAndExpectedFormatWithMicrosecondsProvider() + { + yield array( + '2018-12-01T18:03:06.067634', + 'Y-m-d\TH:i:s.u', + \DateTime::createFromFormat( + 'Y-m-d\TH:i:s.u', + '2018-12-01T18:03:06.067634', + new \DateTimeZone('UTC') + ), + null, + ); + + yield array( + '2018-12-01T18:03:06.067634', + 'Y-m-d\TH:i:s.u', + \DateTime::createFromFormat( + 'Y-m-d\TH:i:s.u', + '2018-12-01T18:03:06.067634', + new \DateTimeZone('UTC') + ), + new \DateTimeZone('UTC'), + ); + + yield array( + '2018-12-01T19:03:06.067634+01:00', + 'Y-m-d\TH:i:s.uP', + \DateTimeImmutable::createFromFormat( + 'Y-m-d\TH:i:s.u', + '2018-12-01T18:03:06.067634', + new \DateTimeZone('UTC') + ), + new \DateTimeZone('Europe/Rome'), + ); + + yield array( + '2018-12-01T20:03:06.067634+02:00', + 'Y-m-d\TH:i:s.uP', + \DateTime::createFromFormat( + 'Y-m-d\TH:i:s.u', + '2018-12-01T18:03:06.067634', + new \DateTimeZone('UTC') + ), + new \DateTimeZone('Europe/Kiev'), + ); + + yield array( + '2018-12-01T21:03:06.067634', + 'Y-m-d\TH:i:s.u', + \DateTime::createFromFormat( + 'Y-m-d\TH:i:s.u', + '2018-12-01T18:03:06.067634', + new \DateTimeZone('UTC') + ), + new \DateTimeZone('Europe/Moscow'), + ); + } + /** * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException * @expectedExceptionMessage The object must implement the "\DateTimeInterface".