Merge branch '3.1'

* 3.1:
  [TwigBridge] Add missing type hint to TwigRenderer
  [HttpFoundation] Fix UPSERT for PgSql >= 9.5
  [Form] fixed DateTime transformers
  [PropertyAccess][DX] Enhance exception that say that some methods are missing if they don't
  bumped Symfony version to 3.1.2
  updated VERSION for 3.1.1
  updated CHANGELOG for 3.1.1
  [Form] fixed EntityType test with query_builder option

Conflicts:
	src/Symfony/Component/HttpKernel/Kernel.php
	src/Symfony/Component/PropertyAccess/PropertyAccessor.php
This commit is contained in:
Nicolas Grekas 2016-06-16 07:23:20 +02:00
commit 3a3801a07c
13 changed files with 113 additions and 70 deletions

View File

@ -7,6 +7,32 @@ in 3.1 minor versions.
To get the diff for a specific change, go to https://github.com/symfony/symfony/commit/XXX where XXX is the change hash To get the diff for a specific change, go to https://github.com/symfony/symfony/commit/XXX where XXX is the change hash
To get the diff between two versions, go to https://github.com/symfony/symfony/compare/v3.1.0...v3.1.1 To get the diff between two versions, go to https://github.com/symfony/symfony/compare/v3.1.0...v3.1.1
* 3.1.1 (2016-06-15)
* bug #19048 [HttpFoundation] Use UPSERT for sessions stored in PgSql >= 9.5 (nicolas-grekas)
* bug #19042 [Cache] Fix double fetch in ProxyAdapter (nicolas-grekas)
* bug #19038 Fix feature detection for IE (Alsciende)
* bug #18915 [DependencyInjection] force enabling the external XML entity loaders (xabbuh)
* bug #19020 [Form] Fixed collapsed choice attributes (HeahDude)
* bug #19028 [Yaml] properly count skipped comment lines (xabbuh)
* bug #19009 [WebProfilerBundle] Fix invalid CSS style (romainneutron)
* bug #17733 [Yaml] Fix wrong line number when comments are inserted in the middle of a block. (paradajozsef)
* bug #18909 Fixed singular of committee (peterrehm)
* bug #18911 Fixed singular of committee (peterrehm)
* bug #18971 Do not inject web debug toolbar on attachments (peterrehm)
* bug #18944 [Ldap] Fixed issue with legacy client initialisation (csarrazi)
* bug #18974 Added missing APCU CacheProvider of doctrine/cache 1.6.x (Carsten Eilers)
* bug #18954 [HttpKernel] Fix RequestDataCollector starting the session (romainneutron)
* bug #18949 [Security] Fix DebugAccessDecisionManager when object is not a scalar (romainneutron)
* bug #18959 [WebProfilerBundle] Fixed forwarded request data in templates (HeahDude)
* bug #18943 [Ldap][Security] The Ldap user provider abstract service now has the correct number of arguments (csarrazi)
* bug #18925 [Console] Fix BC break introduced by #18101 (dunglas)
* bug #18908 [DependencyInjection] force enabling the external XML entity loaders (xabbuh)
* bug #18893 [DependencyInjection] Skip deep reference check for 'service_container' (RobertMe)
* bug #18812 Catch \Throwable (fprochazka)
* bug #18821 [Form] Removed UTC specification with timestamp (francisbesset)
* bug #18861 Fix for #18843 (inso)
* 3.1.0 (2016-05-30) * 3.1.0 (2016-05-30)
* bug #18889 [Console] SymfonyStyle: Fix alignment/prefixing of multi-line comments (chalasr) * bug #18889 [Console] SymfonyStyle: Fix alignment/prefixing of multi-line comments (chalasr)

View File

@ -243,7 +243,7 @@ class DbalSessionHandler implements \SessionHandlerInterface
return "INSERT OR REPLACE INTO $this->table ($this->idCol, $this->dataCol, $this->timeCol) VALUES (:id, :data, :time)"; return "INSERT OR REPLACE INTO $this->table ($this->idCol, $this->dataCol, $this->timeCol) VALUES (:id, :data, :time)";
case 'postgresql' === $platform && version_compare($this->con->getServerVersion(), '9.5', '>='): case 'postgresql' === $platform && version_compare($this->con->getServerVersion(), '9.5', '>='):
return "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->timeCol) VALUES (:id, :data, :time) ". return "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->timeCol) VALUES (:id, :data, :time) ".
"ON CONFLICT ($this->idCol) DO UPDATE SET ($this->dataCol, $this->timeCol) = (:data, :time) WHERE $this->idCol = :id"; "ON CONFLICT ($this->idCol) DO UPDATE SET ($this->dataCol, $this->timeCol) = (EXCLUDED.$this->dataCol, EXCLUDED.$this->timeCol)";
} }
} }
} }

View File

@ -209,8 +209,13 @@ class EntityTypeTest extends TypeTestCase
$field->submit('2'); $field->submit('2');
} }
public function testConfigureQueryBuilderWithClosureReturningNull() public function testConfigureQueryBuilderWithClosureReturningNullUseDefault()
{ {
$entity1 = new SingleIntIdEntity(1, 'Foo');
$entity2 = new SingleIntIdEntity(2, 'Bar');
$this->persist(array($entity1, $entity2));
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array( $field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
'em' => 'default', 'em' => 'default',
'class' => self::SINGLE_IDENT_CLASS, 'class' => self::SINGLE_IDENT_CLASS,
@ -219,7 +224,7 @@ class EntityTypeTest extends TypeTestCase
}, },
)); ));
$this->assertEquals(array(), $field->createView()->vars['choices']); $this->assertEquals(array(1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')), $field->createView()->vars['choices']);
} }
public function testSetDataSingleNull() public function testSetDataSingleNull()

View File

@ -12,6 +12,7 @@
namespace Symfony\Bridge\Twig\Form; namespace Symfony\Bridge\Twig\Form;
use Symfony\Component\Form\FormRenderer; use Symfony\Component\Form\FormRenderer;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
/** /**
* @author Bernhard Schussek <bschussek@gmail.com> * @author Bernhard Schussek <bschussek@gmail.com>
@ -23,7 +24,7 @@ class TwigRenderer extends FormRenderer implements TwigRendererInterface
*/ */
private $engine; private $engine;
public function __construct(TwigRendererEngineInterface $engine, $csrfTokenManager = null) public function __construct(TwigRendererEngineInterface $engine, CsrfTokenManagerInterface $csrfTokenManager = null)
{ {
parent::__construct($engine, $csrfTokenManager); parent::__construct($engine, $csrfTokenManager);

View File

@ -51,13 +51,11 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
/** /**
* Transforms a normalized date into a localized date. * Transforms a normalized date into a localized date.
* *
* @param \DateTime|\DateTimeInterface $dateTime A DateTime object * @param \DateTimeInterface $dateTime A DateTimeInterface object
* *
* @return array Localized date. * @return array Localized date.
* *
* @throws TransformationFailedException If the given value is not an * @throws TransformationFailedException If the given value is not a \DateTimeInterface
* instance of \DateTime or if the
* output timezone is not supported.
*/ */
public function transform($dateTime) public function transform($dateTime)
{ {
@ -81,11 +79,7 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
$dateTime = clone $dateTime; $dateTime = clone $dateTime;
} }
try { $dateTime = $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
$dateTime = $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
} catch (\Exception $e) {
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
}
} }
$result = array_intersect_key(array( $result = array_intersect_key(array(
@ -118,8 +112,6 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
* *
* @throws TransformationFailedException If the given value is not an array, * @throws TransformationFailedException If the given value is not an array,
* if the value could not be transformed * if the value could not be transformed
* or if the input timezone is not
* supported.
*/ */
public function reverseTransform($value) public function reverseTransform($value)
{ {

View File

@ -70,13 +70,12 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
/** /**
* Transforms a normalized date into a localized date string/array. * Transforms a normalized date into a localized date string/array.
* *
* @param \DateTime|\DateTimeInterface $dateTime A DateTime object * @param \DateTimeInterface $dateTime A DateTimeInterface object
* *
* @return string|array Localized date string/array. * @return string|array Localized date string/array.
* *
* @throws TransformationFailedException If the given value is not an instance * @throws TransformationFailedException If the given value is not a \DateTimeInterface
* of \DateTime or if the date could not * or if the date could not be transformed.
* be transformed.
*/ */
public function transform($dateTime) public function transform($dateTime)
{ {
@ -105,8 +104,7 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
* @return \DateTime Normalized date * @return \DateTime Normalized date
* *
* @throws TransformationFailedException if the given value is not a string, * @throws TransformationFailedException if the given value is not a string,
* if the date could not be parsed or * if the date could not be parsed
* if the input timezone is not supported
*/ */
public function reverseTransform($value) public function reverseTransform($value)
{ {
@ -132,11 +130,7 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
} }
if ('UTC' !== $this->inputTimezone) { if ('UTC' !== $this->inputTimezone) {
try { $dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
$dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
} catch (\Exception $e) {
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
}
} }
return $dateTime; return $dateTime;

View File

@ -19,7 +19,13 @@ use Symfony\Component\Form\Exception\TransformationFailedException;
class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
{ {
/** /**
* {@inheritdoc} * Transforms a normalized date into a localized date.
*
* @param \DateTimeInterface $dateTime A DateTimeInterface object
*
* @return string The formatted date.
*
* @throws TransformationFailedException If the given value is not a \DateTimeInterface
*/ */
public function transform($dateTime) public function transform($dateTime)
{ {
@ -32,7 +38,10 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
} }
if ($this->inputTimezone !== $this->outputTimezone) { if ($this->inputTimezone !== $this->outputTimezone) {
$dateTime = clone $dateTime; if (!$dateTime instanceof \DateTimeImmutable) {
$dateTime = clone $dateTime;
}
$dateTime = $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone)); $dateTime = $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
} }
@ -40,7 +49,14 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
} }
/** /**
* {@inheritdoc} * Transforms a formatted string following RFC 3339 into a normalized date.
*
* @param string $rfc3339 Formatted string
*
* @return \DateTime Normalized date
*
* @throws TransformationFailedException If the given value is not a string,
* if the value could not be transformed
*/ */
public function reverseTransform($rfc3339) public function reverseTransform($rfc3339)
{ {
@ -58,12 +74,8 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e); throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
} }
if ($this->outputTimezone !== $dateTime->getTimezone()->getName()) { if ($this->inputTimezone !== $dateTime->getTimezone()->getName()) {
try { $dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
$dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
} catch (\Exception $e) {
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
}
} }
if (preg_match('/(\d{4})-(\d{2})-(\d{2})/', $rfc3339, $matches)) { if (preg_match('/(\d{4})-(\d{2})-(\d{2})/', $rfc3339, $matches)) {

View File

@ -85,35 +85,29 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
* Transforms a DateTime object into a date string with the configured format * Transforms a DateTime object into a date string with the configured format
* and timezone. * and timezone.
* *
* @param \DateTime|\DateTimeInterface $value A DateTime object * @param \DateTimeInterface $dateTime A DateTimeInterface object
* *
* @return string A value as produced by PHP's date() function * @return string A value as produced by PHP's date() function
* *
* @throws TransformationFailedException If the given value is not a \DateTime * @throws TransformationFailedException If the given value is not a \DateTimeInterface
* instance or if the output timezone
* is not supported.
*/ */
public function transform($value) public function transform($dateTime)
{ {
if (null === $value) { if (null === $dateTime) {
return ''; return '';
} }
if (!$value instanceof \DateTimeInterface) { if (!$dateTime instanceof \DateTimeInterface) {
throw new TransformationFailedException('Expected a \DateTimeInterface.'); throw new TransformationFailedException('Expected a \DateTimeInterface.');
} }
if (!$value instanceof \DateTimeImmutable) { if (!$dateTime instanceof \DateTimeImmutable) {
$value = clone $value; $dateTime = clone $dateTime;
} }
try { $dateTime = $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
$value = $value->setTimezone(new \DateTimeZone($this->outputTimezone));
} catch (\Exception $e) {
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
}
return $value->format($this->generateFormat); return $dateTime->format($this->generateFormat);
} }
/** /**
@ -124,8 +118,7 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
* @return \DateTime An instance of \DateTime * @return \DateTime An instance of \DateTime
* *
* @throws TransformationFailedException If the given value is not a string, * @throws TransformationFailedException If the given value is not a string,
* if the date could not be parsed or * or could not be transformed
* if the input timezone is not supported.
*/ */
public function reverseTransform($value) public function reverseTransform($value)
{ {

View File

@ -24,25 +24,23 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
/** /**
* Transforms a DateTime object into a timestamp in the configured timezone. * Transforms a DateTime object into a timestamp in the configured timezone.
* *
* @param \DateTime|\DateTimeInterface $dateTime A DateTime object * @param \DateTimeInterface $dateTime A DateTimeInterface object
* *
* @return int A timestamp * @return int A timestamp
* *
* @throws TransformationFailedException If the given value is not an instance * @throws TransformationFailedException If the given value is not a \DateTimeInterface
* of \DateTime or if the output
* timezone is not supported.
*/ */
public function transform($value) public function transform($dateTime)
{ {
if (null === $value) { if (null === $dateTime) {
return; return;
} }
if (!$value instanceof \DateTimeInterface) { if (!$dateTime instanceof \DateTimeInterface) {
throw new TransformationFailedException('Expected a \DateTimeInterface.'); throw new TransformationFailedException('Expected a \DateTimeInterface.');
} }
return $value->getTimestamp(); return $dateTime->getTimestamp();
} }
/** /**
@ -53,7 +51,7 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
* @return \DateTime A \DateTime object * @return \DateTime A \DateTime object
* *
* @throws TransformationFailedException If the given value is not a timestamp * @throws TransformationFailedException If the given value is not a timestamp
* or if the given timestamp is invalid. * or if the given timestamp is invalid
*/ */
public function reverseTransform($value) public function reverseTransform($value)
{ {

View File

@ -30,14 +30,14 @@ class Cookie
/** /**
* Constructor. * Constructor.
* *
* @param string $name The name of the cookie * @param string $name The name of the cookie
* @param string $value The value of the cookie * @param string $value The value of the cookie
* @param int|string|\DateTime|\DateTimeInterface $expire The time the cookie expires * @param int|string|\DateTimeInterface $expire The time the cookie expires
* @param string $path The path on the server in which the cookie will be available on * @param string $path The path on the server in which the cookie will be available on
* @param string $domain The domain that the cookie is available to * @param string $domain The domain that the cookie is available to
* @param bool $secure Whether the cookie should only be transmitted over a secure HTTPS connection from the client * @param bool $secure Whether the cookie should only be transmitted over a secure HTTPS connection from the client
* @param bool $httpOnly Whether the cookie will be made accessible only through the HTTP protocol * @param bool $httpOnly Whether the cookie will be made accessible only through the HTTP protocol
* @param bool $raw Whether the cookie value should be sent with no url encoding * @param bool $raw Whether the cookie value should be sent with no url encoding
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */

View File

@ -678,7 +678,7 @@ class PdoSessionHandler implements \SessionHandlerInterface
return "INSERT OR REPLACE INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :lifetime, :time)"; return "INSERT OR REPLACE INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :lifetime, :time)";
case 'pgsql' === $this->driver && version_compare($this->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION), '9.5', '>='): case 'pgsql' === $this->driver && version_compare($this->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION), '9.5', '>='):
return "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :lifetime, :time) ". return "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :lifetime, :time) ".
"ON CONFLICT ($this->idCol) DO UPDATE SET ($this->dataCol, $this->lifetimeCol, $this->timeCol) = (:data, :lifetime, :time) WHERE $this->idCol = :id"; "ON CONFLICT ($this->idCol) DO UPDATE SET ($this->dataCol, $this->lifetimeCol, $this->timeCol) = (EXCLUDED.$this->dataCol, EXCLUDED.$this->lifetimeCol, EXCLUDED.$this->timeCol)";
} }
} }

View File

@ -758,6 +758,17 @@ class PropertyAccessor implements PropertyAccessorInterface
// we call the getter and hope the __call do the job // we call the getter and hope the __call do the job
$access[self::ACCESS_TYPE] = self::ACCESS_TYPE_MAGIC; $access[self::ACCESS_TYPE] = self::ACCESS_TYPE_MAGIC;
$access[self::ACCESS_NAME] = $setter; $access[self::ACCESS_NAME] = $setter;
} elseif (null !== $methods = $this->findAdderAndRemover($reflClass, $singulars)) {
$access[self::ACCESS_TYPE] = self::ACCESS_TYPE_NOT_FOUND;
$access[self::ACCESS_NAME] = sprintf(
'The property "%s" in class "%s" can be defined with the methods "%s()" but '.
'the new value must be an array or an instance of \Traversable, '.
'"%s" given.',
$property,
$reflClass->name,
implode('()", "', $methods),
is_object($value) ? get_class($value) : gettype($value)
);
} else { } else {
$access[self::ACCESS_TYPE] = self::ACCESS_TYPE_NOT_FOUND; $access[self::ACCESS_TYPE] = self::ACCESS_TYPE_NOT_FOUND;
$access[self::ACCESS_NAME] = sprintf( $access[self::ACCESS_NAME] = sprintf(

View File

@ -194,4 +194,15 @@ abstract class PropertyAccessorCollectionTest extends PropertyAccessorArrayAcces
$this->assertFalse($this->propertyAccessor->isWritable($car, 'axes', $axes)); $this->assertFalse($this->propertyAccessor->isWritable($car, 'axes', $axes));
} }
/**
* @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException
* expectedExceptionMessageRegExp /The property "axes" in class "Mock_PropertyAccessorCollectionTest_Car[^"]*" can be defined with the methods "addAxis()", "removeAxis()" but the new value must be an array or an instance of \Traversable, "string" given./
*/
public function testSetValueFailsIfAdderAndRemoverExistButValueIsNotTraversable()
{
$car = $this->getMock(__CLASS__.'_Car');
$this->propertyAccessor->setValue($car, 'axes', 'Not an array or Traversable');
}
} }