Merge branch '3.4' into 4.1

* 3.4:
  [Serializer] fixed DateTimeNormalizer to maintain microseconds when a different timezone required
  [Routing] fix taking verb into account when redirecting
  [WebProfilerBundle] Split form field heading
This commit is contained in:
Nicolas Grekas 2018-12-02 14:22:14 +01:00
commit 22795af29e
11 changed files with 148 additions and 31 deletions

View File

@ -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;
}
</style>
{% endblock %}
@ -455,9 +461,10 @@
{% macro form_tree_details(name, data, forms_by_hash, show) %}
{% import _self as tree %}
<div class="tree-details{% if not show|default(false) %} hidden{% endif %}" {% if data.id is defined %}id="{{ data.id }}-details"{% endif %}>
<h2 class="dump-inline">
{{ name|default('(no name)') }} {% if data.type_class is defined %}({{ profiler_dump(data.type_class) }}){% endif %}
</h2>
<h2>{{ name|default('(no name)') }}</h2>
{% if data.type_class is defined %}
<h3 class="dump-inline form-data-type">{{ profiler_dump(data.type_class) }}</h3>
{% endif %}
{% if data.errors is defined and data.errors|length > 0 %}
<div class="errors">

View File

@ -161,10 +161,10 @@ EOF;
throw new ResourceNotFoundException();
}
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): array
EOF
.$code."\n return null;\n }";
.$code."\n return array();\n }";
}
return " public function match(\$rawPathinfo)\n".$code."\n throw \$allow ? new MethodNotAllowedException(array_keys(\$allow)) : new ResourceNotFoundException();\n }";
@ -565,7 +565,7 @@ EOF;
}\n" : '',
$this->supportsRedirections ? "
if (!\$requiredMethods || isset(\$requiredMethods['GET'])) {
return null;
return \$allow = \$allowSchemes = array();
}" : ''
);
@ -638,7 +638,7 @@ EOF;
%s;
}\n\n",
$hasTrailingSlash ? '!==' : '===',
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? 'return null' : 'break'
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? 'return $allow = $allowSchemes = array()' : 'break'
);
} elseif ($hasTrailingSlash) {
$code .= sprintf("
@ -648,14 +648,14 @@ EOF;
if ('/' !== \$pathinfo && preg_match(\$regex, substr(\$pathinfo, 0, -1), \$n) && \$m === (int) \$n['MARK']) {
\$matches = \$n;
}\n\n",
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? 'return null' : 'break'
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? 'return $allow = $allowSchemes = array()' : 'break'
);
} else {
$code .= sprintf("
if ('/' !== \$pathinfo && '/' === \$pathinfo[-1] && preg_match(\$regex, substr(\$pathinfo, 0, -1), \$n) && \$m === (int) \$n['MARK']) {
%s;
}\n\n",
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? 'return null' : 'break'
$this->supportsRedirections && (!$methods || isset($methods['GET'])) ? 'return $allow = $allowSchemes = array()' : 'break'
);
}

View File

@ -143,9 +143,9 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
} elseif (!$supportsTrailingSlash || ($requiredMethods && !\in_array('GET', $requiredMethods))) {
continue;
} elseif ('/' === $staticPrefix[-1] && substr($staticPrefix, 0, -1) === $pathinfo) {
return;
return $this->allow = $this->allowSchemes = array();
} elseif ('/' === $pathinfo[-1] && substr($pathinfo, 0, -1) === $staticPrefix) {
return;
return $this->allow = $this->allowSchemes = array();
} else {
continue;
}
@ -171,7 +171,7 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
}
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if (!$requiredMethods || \in_array('GET', $requiredMethods)) {
return;
return $this->allow = $this->allowSchemes = array();
}
continue;
}
@ -212,6 +212,8 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
return $this->getAttributes($route, $name, array_replace($matches, $hostMatches, isset($status[1]) ? $status[1] : array()));
}
return array();
}
/**

View File

@ -50,7 +50,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
throw new ResourceNotFoundException();
}
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): array
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
@ -129,7 +129,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if (!$requiredMethods || isset($requiredMethods['GET'])) {
return null;
return $allow = $allowSchemes = array();
}
break;
}
@ -167,6 +167,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
return null;
return array();
}
}

View File

@ -50,7 +50,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
throw new ResourceNotFoundException();
}
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): array
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
@ -94,7 +94,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
if ('/' !== $pathinfo) {
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if (!$requiredMethods || isset($requiredMethods['GET'])) {
return null;
return $allow = $allowSchemes = array();
}
break;
}
@ -183,7 +183,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
// baz4
if ('/' !== $pathinfo[-1]) {
return null;
return $allow = $allowSchemes = array();
}
if ('/' !== $pathinfo && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
$matches = $n;
@ -249,7 +249,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
// foo2
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
return null;
return $allow = $allowSchemes = array();
}
return $this->mergeDefaults(array('_route' => 'foo2') + $matches, array());
@ -260,7 +260,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
// foo3
if ('/' !== $pathinfo && '/' === $pathinfo[-1] && preg_match($regex, substr($pathinfo, 0, -1), $n) && $m === (int) $n['MARK']) {
return null;
return $allow = $allowSchemes = array();
}
return $this->mergeDefaults(array('_route' => 'foo3') + $matches, array());
@ -300,7 +300,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if (!$requiredMethods || isset($requiredMethods['GET'])) {
return null;
return $allow = $allowSchemes = array();
}
break;
}
@ -338,6 +338,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
return null;
return array();
}
}

View File

@ -50,7 +50,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
throw new ResourceNotFoundException();
}
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): array
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
@ -86,7 +86,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
if ('/' !== $pathinfo) {
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if (!$requiredMethods || isset($requiredMethods['GET'])) {
return null;
return $allow = $allowSchemes = array();
}
break;
}
@ -137,7 +137,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if (!$requiredMethods || isset($requiredMethods['GET'])) {
return null;
return $allow = $allowSchemes = array();
}
break;
}
@ -175,6 +175,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
return null;
return array();
}
}

View File

@ -50,7 +50,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
throw new ResourceNotFoundException();
}
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): ?array
private function doMatch(string $rawPathinfo, array &$allow = array(), array &$allowSchemes = array()): array
{
$allow = $allowSchemes = array();
$pathinfo = rawurldecode($rawPathinfo) ?: '/';
@ -82,7 +82,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
if ('/' !== $pathinfo) {
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if (!$requiredMethods || isset($requiredMethods['GET'])) {
return null;
return $allow = $allowSchemes = array();
}
break;
}
@ -149,7 +149,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
if ($hasTrailingSlash !== ('/' === $pathinfo[-1])) {
if (!$requiredMethods || isset($requiredMethods['GET'])) {
return null;
return $allow = $allowSchemes = array();
}
break;
}
@ -187,6 +187,6 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
return null;
return array();
}
}

View File

@ -170,6 +170,23 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
$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()));

View File

@ -708,6 +708,20 @@ class UrlMatcherTest extends TestCase
$this->assertSame(array('_route' => 'b'), $matcher->match('/bar/'));
}
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());

View File

@ -55,7 +55,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);

View File

@ -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".