Merge branch '4.0' into 4.1
* 4.0:
[minor] SCA
[Serializer] Minor tweaks for a67b650f12
allow_extra_attributes does not throw an exception as documented
[Cache] fix visibility of RedisTrait::init()
[Serializer] Updates DocBlock to a mixed param type
This commit is contained in:
commit
671e412417
@ -41,7 +41,7 @@ trait RedisTrait
|
||||
/**
|
||||
* @param \Redis|\RedisArray|\RedisCluster|\Predis\Client $redisClient
|
||||
*/
|
||||
public function init($redisClient, $namespace = '', $defaultLifetime = 0)
|
||||
private function init($redisClient, $namespace = '', $defaultLifetime = 0)
|
||||
{
|
||||
parent::__construct($namespace, $defaultLifetime);
|
||||
|
||||
|
@ -34,12 +34,12 @@ class DefaultsConfigurator extends AbstractServiceConfigurator
|
||||
*/
|
||||
final public function tag(string $name, array $attributes = array())
|
||||
{
|
||||
if (!is_string($name) || '' === $name) {
|
||||
if ('' === $name) {
|
||||
throw new InvalidArgumentException('The tag name in "_defaults" must be a non-empty string.');
|
||||
}
|
||||
|
||||
foreach ($attributes as $attribute => $value) {
|
||||
if (!is_scalar($value) && null !== $value) {
|
||||
if (null !== $value && !is_scalar($value)) {
|
||||
throw new InvalidArgumentException(sprintf('Tag "%s", attribute "%s" in "_defaults" must be of a scalar-type.', $name, $attribute));
|
||||
}
|
||||
}
|
||||
|
@ -28,10 +28,6 @@ class IntegerToLocalizedStringTransformer extends NumberToLocalizedStringTransfo
|
||||
*/
|
||||
public function __construct(?int $scale = 0, ?bool $grouping = false, int $roundingMode = self::ROUND_DOWN)
|
||||
{
|
||||
if (null === $roundingMode) {
|
||||
$roundingMode = self::ROUND_DOWN;
|
||||
}
|
||||
|
||||
parent::__construct(0, $grouping, $roundingMode);
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ final class PersistentToken implements PersistentTokenInterface
|
||||
if (empty($class)) {
|
||||
throw new \InvalidArgumentException('$class must not be empty.');
|
||||
}
|
||||
if ('' === $username || null === $username) {
|
||||
if ('' === $username) {
|
||||
throw new \InvalidArgumentException('$username must not be empty.');
|
||||
}
|
||||
if (empty($series)) {
|
||||
|
@ -37,10 +37,6 @@ class LdapUserProvider implements UserProviderInterface
|
||||
|
||||
public function __construct(LdapInterface $ldap, string $baseDn, string $searchDn = null, string $searchPassword = null, array $defaultRoles = array(), string $uidKey = 'sAMAccountName', string $filter = '({uid_key}={username})', string $passwordAttribute = null)
|
||||
{
|
||||
if (null === $uidKey) {
|
||||
$uidKey = 'sAMAccountName';
|
||||
}
|
||||
|
||||
$this->ldap = $ldap;
|
||||
$this->baseDn = $baseDn;
|
||||
$this->searchDn = $searchDn;
|
||||
|
@ -212,11 +212,17 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
||||
* @param array $context
|
||||
* @param bool $attributesAsString If false, return an array of {@link AttributeMetadataInterface}
|
||||
*
|
||||
* @throws LogicException if the 'allow_extra_attributes' context variable is false and no class metadata factory is provided
|
||||
*
|
||||
* @return string[]|AttributeMetadataInterface[]|bool
|
||||
*/
|
||||
protected function getAllowedAttributes($classOrObject, array $context, $attributesAsString = false)
|
||||
{
|
||||
if (!$this->classMetadataFactory) {
|
||||
if (isset($context[static::ALLOW_EXTRA_ATTRIBUTES]) && !$context[static::ALLOW_EXTRA_ATTRIBUTES]) {
|
||||
throw new LogicException(sprintf('A class metadata factory must be provided in the constructor when setting "%s" to false.', static::ALLOW_EXTRA_ATTRIBUTES));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ interface NormalizerInterface
|
||||
/**
|
||||
* Normalizes an object into a set of arrays/scalars.
|
||||
*
|
||||
* @param object $object Object to normalize
|
||||
* @param mixed $object Object to normalize
|
||||
* @param string $format Format the normalization result will be encoded as
|
||||
* @param array $context Context options for the normalizer
|
||||
*
|
||||
|
@ -19,6 +19,7 @@ use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
|
||||
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
|
||||
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||
use Symfony\Component\Serializer\SerializerAwareInterface;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
@ -52,7 +53,8 @@ class AbstractObjectNormalizerTest extends TestCase
|
||||
*/
|
||||
public function testDenormalizeWithExtraAttributes()
|
||||
{
|
||||
$normalizer = new AbstractObjectNormalizerDummy();
|
||||
$factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
|
||||
$normalizer = new AbstractObjectNormalizerDummy($factory);
|
||||
$normalizer->denormalize(
|
||||
array('fooFoo' => 'foo', 'fooBar' => 'bar'),
|
||||
__NAMESPACE__.'\Dummy',
|
||||
@ -144,6 +146,21 @@ class AbstractObjectNormalizerTest extends TestCase
|
||||
|
||||
return $denormalizer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that additional attributes throw an exception if no metadata factory is specified.
|
||||
*
|
||||
* @expectedException \Symfony\Component\Serializer\Exception\LogicException
|
||||
* @expectedExceptionMessage A class metadata factory must be provided in the constructor when setting "allow_extra_attributes" to false.
|
||||
*/
|
||||
public function testExtraAttributesException()
|
||||
{
|
||||
$normalizer = new ObjectNormalizer();
|
||||
|
||||
$normalizer->denormalize(array(), \stdClass::class, 'xml', array(
|
||||
'allow_extra_attributes' => false,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer
|
||||
|
@ -45,7 +45,7 @@ abstract class AbstractFileExtractor
|
||||
|
||||
private function toSplFileInfo(string $file): \SplFileInfo
|
||||
{
|
||||
return ($file instanceof \SplFileInfo) ? $file : new \SplFileInfo($file);
|
||||
return new \SplFileInfo($file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user