Merge branch '2.3'
* 2.3: Fix: duplicate usage of Symfony\Component\HttpFoundation\Response [Form] add support for Length and Range constraint in order to replace MaxLength, MinLength, Max and Min constraints in next release (2.3) Revert "merged branch Tobion/flattenexception (PR #9111)" [Form] check the required output timezone against the actual timezone of the input datetime object, rather than the expected timezone supplied Conflicts: src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php
This commit is contained in:
commit
f8f8816e4b
@ -12,7 +12,7 @@
|
|||||||
namespace Symfony\Bundle\TwigBundle\Controller;
|
namespace Symfony\Bundle\TwigBundle\Controller;
|
||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
|
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
|
||||||
use Symfony\Component\Debug\Exception\FlattenException;
|
use Symfony\Component\HttpKernel\Exception\FlattenException;
|
||||||
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
@ -19,7 +19,7 @@ class ExceptionControllerTest extends TestCase
|
|||||||
{
|
{
|
||||||
public function testOnlyClearOwnOutputBuffers()
|
public function testOnlyClearOwnOutputBuffers()
|
||||||
{
|
{
|
||||||
$flatten = $this->getMock('Symfony\Component\Debug\Exception\FlattenException');
|
$flatten = $this->getMock('Symfony\Component\HttpKernel\Exception\FlattenException');
|
||||||
$flatten
|
$flatten
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getStatusCode')
|
->method('getStatusCode')
|
||||||
|
@ -58,7 +58,7 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
|
|||||||
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
|
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->outputTimezone !== $this->inputTimezone) {
|
if ($this->outputTimezone !== $dateTime->getTimezone()->getName()) {
|
||||||
try {
|
try {
|
||||||
$dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
|
$dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -147,11 +147,13 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
|
|||||||
|
|
||||||
case 'Symfony\Component\Validator\Constraints\MaxLength':
|
case 'Symfony\Component\Validator\Constraints\MaxLength':
|
||||||
case 'Symfony\Component\Validator\Constraints\MinLength':
|
case 'Symfony\Component\Validator\Constraints\MinLength':
|
||||||
|
case 'Symfony\Component\Validator\Constraints\Length':
|
||||||
case 'Symfony\Component\Validator\Constraints\Regex':
|
case 'Symfony\Component\Validator\Constraints\Regex':
|
||||||
return new TypeGuess('text', array(), Guess::LOW_CONFIDENCE);
|
return new TypeGuess('text', array(), Guess::LOW_CONFIDENCE);
|
||||||
|
|
||||||
case 'Symfony\Component\Validator\Constraints\Min':
|
case 'Symfony\Component\Validator\Constraints\Min':
|
||||||
case 'Symfony\Component\Validator\Constraints\Max':
|
case 'Symfony\Component\Validator\Constraints\Max':
|
||||||
|
case 'Symfony\Component\Validator\Constraints\Range':
|
||||||
return new TypeGuess('number', array(), Guess::LOW_CONFIDENCE);
|
return new TypeGuess('number', array(), Guess::LOW_CONFIDENCE);
|
||||||
|
|
||||||
case 'Symfony\Component\Validator\Constraints\MinCount':
|
case 'Symfony\Component\Validator\Constraints\MinCount':
|
||||||
@ -198,6 +200,12 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
|
|||||||
case 'Symfony\Component\Validator\Constraints\MaxLength':
|
case 'Symfony\Component\Validator\Constraints\MaxLength':
|
||||||
return new ValueGuess($constraint->limit, Guess::HIGH_CONFIDENCE);
|
return new ValueGuess($constraint->limit, Guess::HIGH_CONFIDENCE);
|
||||||
|
|
||||||
|
case 'Symfony\Component\Validator\Constraints\Length':
|
||||||
|
if (is_numeric($constraint->max)) {
|
||||||
|
return new ValueGuess($constraint->max, Guess::HIGH_CONFIDENCE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'Symfony\Component\Validator\Constraints\Type':
|
case 'Symfony\Component\Validator\Constraints\Type':
|
||||||
if (in_array($constraint->type, array('double', 'float', 'numeric', 'real'))) {
|
if (in_array($constraint->type, array('double', 'float', 'numeric', 'real'))) {
|
||||||
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
|
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
|
||||||
@ -206,6 +214,12 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
|
|||||||
|
|
||||||
case 'Symfony\Component\Validator\Constraints\Max':
|
case 'Symfony\Component\Validator\Constraints\Max':
|
||||||
return new ValueGuess(strlen((string) $constraint->limit), Guess::LOW_CONFIDENCE);
|
return new ValueGuess(strlen((string) $constraint->limit), Guess::LOW_CONFIDENCE);
|
||||||
|
|
||||||
|
case 'Symfony\Component\Validator\Constraints\Range':
|
||||||
|
if (is_numeric($constraint->max)) {
|
||||||
|
return new ValueGuess(strlen((string) $constraint->max), Guess::LOW_CONFIDENCE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -224,6 +238,12 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
|
|||||||
case 'Symfony\Component\Validator\Constraints\MinLength':
|
case 'Symfony\Component\Validator\Constraints\MinLength':
|
||||||
return new ValueGuess(sprintf('.{%s,}', (string) $constraint->limit), Guess::LOW_CONFIDENCE);
|
return new ValueGuess(sprintf('.{%s,}', (string) $constraint->limit), Guess::LOW_CONFIDENCE);
|
||||||
|
|
||||||
|
case 'Symfony\Component\Validator\Constraints\Length':
|
||||||
|
if (is_numeric($constraint->min)) {
|
||||||
|
return new ValueGuess(sprintf('.{%s,}', (string) $constraint->min), Guess::LOW_CONFIDENCE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'Symfony\Component\Validator\Constraints\Regex':
|
case 'Symfony\Component\Validator\Constraints\Regex':
|
||||||
$htmlPattern = $constraint->getHtmlPattern();
|
$htmlPattern = $constraint->getHtmlPattern();
|
||||||
|
|
||||||
@ -235,6 +255,12 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
|
|||||||
case 'Symfony\Component\Validator\Constraints\Min':
|
case 'Symfony\Component\Validator\Constraints\Min':
|
||||||
return new ValueGuess(sprintf('.{%s,}', strlen((string) $constraint->limit)), Guess::LOW_CONFIDENCE);
|
return new ValueGuess(sprintf('.{%s,}', strlen((string) $constraint->limit)), Guess::LOW_CONFIDENCE);
|
||||||
|
|
||||||
|
case 'Symfony\Component\Validator\Constraints\Range':
|
||||||
|
if (is_numeric($constraint->min)) {
|
||||||
|
return new ValueGuess(sprintf('.{%s,}', strlen((string) $constraint->min)), Guess::LOW_CONFIDENCE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'Symfony\Component\Validator\Constraints\Type':
|
case 'Symfony\Component\Validator\Constraints\Type':
|
||||||
if (in_array($constraint->type, array('double', 'float', 'numeric', 'real'))) {
|
if (in_array($constraint->type, array('double', 'float', 'numeric', 'real'))) {
|
||||||
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
|
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
|
||||||
|
@ -65,6 +65,7 @@ class DateTimeToRfc3339TransformerTest extends DateTimeTestCase
|
|||||||
// format without seconds, as appears in some browsers
|
// format without seconds, as appears in some browsers
|
||||||
array('UTC', 'UTC', '2010-02-03 04:05:00 UTC', '2010-02-03T04:05Z'),
|
array('UTC', 'UTC', '2010-02-03 04:05:00 UTC', '2010-02-03T04:05Z'),
|
||||||
array('America/New_York', 'Asia/Hong_Kong', '2010-02-03 04:05:00 America/New_York', '2010-02-03T17:05+08:00'),
|
array('America/New_York', 'Asia/Hong_Kong', '2010-02-03 04:05:00 America/New_York', '2010-02-03T17:05+08:00'),
|
||||||
|
array('Europe/Amsterdam', 'Europe/Amsterdam', '2013-08-21 10:30:00 Europe/Amsterdam', '2013-08-21T08:30:00Z')
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Form\Tests\Extension\Validator;
|
||||||
|
|
||||||
|
use Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser;
|
||||||
|
use Symfony\Component\Form\Guess\Guess;
|
||||||
|
use Symfony\Component\Validator\Constraints\Length;
|
||||||
|
use Symfony\Component\Validator\Constraints\Type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author franek <franek@chicour.net>
|
||||||
|
*/
|
||||||
|
class ValidatorTypeGuesserTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
private $typeGuesser;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
if (!class_exists('Symfony\Component\Validator\Constraint')) {
|
||||||
|
$this->markTestSkipped('The "Validator" component is not available');
|
||||||
|
}
|
||||||
|
|
||||||
|
$metadataFactory = $this->getMock('Symfony\Component\Validator\MetadataFactoryInterface');
|
||||||
|
|
||||||
|
$this->typeGuesser = new ValidatorTypeGuesser($metadataFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGuessMaxLengthForConstraintWithMaxValue()
|
||||||
|
{
|
||||||
|
$constraint = new Length(array('max' => '2'));
|
||||||
|
|
||||||
|
$result = $this->typeGuesser->guessMaxLengthForConstraint($constraint);
|
||||||
|
$this->assertInstanceOf('Symfony\Component\Form\Guess\ValueGuess', $result);
|
||||||
|
$this->assertEquals(2, $result->getValue());
|
||||||
|
$this->assertEquals(Guess::HIGH_CONFIDENCE, $result->getConfidence());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGuessMaxLengthForConstraintWithMinValue()
|
||||||
|
{
|
||||||
|
$constraint = new Length(array('min' => '2'));
|
||||||
|
|
||||||
|
$result = $this->typeGuesser->guessMaxLengthForConstraint($constraint);
|
||||||
|
$this->assertNull($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataProviderTestGuessMaxLengthForConstraintWithType
|
||||||
|
*/
|
||||||
|
public function testGuessMaxLengthForConstraintWithType($type)
|
||||||
|
{
|
||||||
|
$constraint = new Type($type);
|
||||||
|
|
||||||
|
$result = $this->typeGuesser->guessMaxLengthForConstraint($constraint);
|
||||||
|
$this->assertInstanceOf('Symfony\Component\Form\Guess\ValueGuess', $result);
|
||||||
|
$this->assertEquals(null, $result->getValue());
|
||||||
|
$this->assertEquals(Guess::MEDIUM_CONFIDENCE, $result->getConfidence());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dataProviderTestGuessMaxLengthForConstraintWithType()
|
||||||
|
{
|
||||||
|
return array (
|
||||||
|
array('double'),
|
||||||
|
array('float'),
|
||||||
|
array('numeric'),
|
||||||
|
array('real')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\HttpKernel\DataCollector;
|
namespace Symfony\Component\HttpKernel\DataCollector;
|
||||||
|
|
||||||
use Symfony\Component\Debug\Exception\FlattenException;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\FlattenException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ExceptionDataCollector.
|
* ExceptionDataCollector.
|
||||||
|
@ -13,11 +13,11 @@ namespace Symfony\Component\HttpKernel\EventListener;
|
|||||||
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\Debug\Exception\FlattenException;
|
|
||||||
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
||||||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
||||||
use Symfony\Component\HttpKernel\KernelEvents;
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\FlattenException;
|
||||||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
|
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
|
||||||
|
|
||||||
use Symfony\Component\Debug\Exception\FlattenException;
|
|
||||||
use Symfony\Component\HttpKernel\DataCollector\ExceptionDataCollector;
|
use Symfony\Component\HttpKernel\DataCollector\ExceptionDataCollector;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\FlattenException;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
@ -30,10 +30,11 @@ class ExceptionDataCollectorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$c->collect(new Request(), new Response(),$e);
|
$c->collect(new Request(), new Response(),$e);
|
||||||
|
|
||||||
$this->assertTrue($c->hasException());
|
$this->assertTrue($c->hasException());
|
||||||
$this->assertEquals($flattened, $c->getException());
|
$this->assertEquals($flattened,$c->getException());
|
||||||
$this->assertSame('foo', $c->getMessage());
|
$this->assertSame('foo',$c->getMessage());
|
||||||
$this->assertSame(500, $c->getCode());
|
$this->assertSame(500,$c->getCode());
|
||||||
$this->assertSame('exception', $c->getName());
|
$this->assertSame('exception',$c->getName());
|
||||||
$this->assertSame($trace, $c->getTrace());
|
$this->assertSame($trace,$c->getTrace());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ namespace Symfony\Component\Security\Http\Authorization;
|
|||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is used by the ExceptionListener to translate an AccessDeniedException
|
* This is used by the ExceptionListener to translate an AccessDeniedException
|
||||||
|
Reference in New Issue
Block a user