Merge branch '5.1'

* 5.1:
  fix: clarify parameter name to comply with deprecations from #34074
  [Sendgrid-Mailer] Fixed envelope recipients on sendgridApiTransport
  mark the AssertingContextualValidator class as internal
  Fix the parameter names in the SecurityFactoryInterface::create() method
  [Serializer][ClassDiscriminatorMapping] Fix getMappedObjectType() when a discriminator child extends another one
  make return type correct
This commit is contained in:
Fabien Potencier 2020-08-18 13:41:45 +02:00
commit fbcdbf99a4
12 changed files with 79 additions and 12 deletions

View File

@ -207,30 +207,30 @@ abstract class AbstractController implements ServiceSubscriberInterface
}
/**
* Checks if the attributes are granted against the current authentication token and optionally supplied subject.
* Checks if the attribute is granted against the current authentication token and optionally supplied subject.
*
* @throws \LogicException
*/
protected function isGranted($attributes, $subject = null): bool
protected function isGranted($attribute, $subject = null): bool
{
if (!$this->container->has('security.authorization_checker')) {
throw new \LogicException('The SecurityBundle is not registered in your application. Try running "composer require symfony/security-bundle".');
}
return $this->container->get('security.authorization_checker')->isGranted($attributes, $subject);
return $this->container->get('security.authorization_checker')->isGranted($attribute, $subject);
}
/**
* Throws an exception unless the attributes are granted against the current authentication token and optionally
* Throws an exception unless the attribute is granted against the current authentication token and optionally
* supplied subject.
*
* @throws AccessDeniedException
*/
protected function denyAccessUnlessGranted($attributes, $subject = null, string $message = 'Access Denied.'): void
protected function denyAccessUnlessGranted($attribute, $subject = null, string $message = 'Access Denied.'): void
{
if (!$this->isGranted($attributes, $subject)) {
if (!$this->isGranted($attribute, $subject)) {
$exception = $this->createAccessDeniedException($message);
$exception->setAttributes($attributes);
$exception->setAttributes($attribute);
$exception->setSubject($subject);
throw $exception;

View File

@ -29,7 +29,7 @@ interface SecurityFactoryInterface
* - the listener id
* - the entry point id
*/
public function create(ContainerBuilder $container, string $id, array $config, string $userProvider, ?string $defaultEntryPoint);
public function create(ContainerBuilder $container, string $id, array $config, string $userProviderId, ?string $defaultEntryPointId);
/**
* Defines the position at which the provider is called.

View File

@ -148,7 +148,7 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
/**
* Returns an iterator to iterate over children (implements \IteratorAggregate).
*
* @return \ArrayIterator|FormView[] The iterator
* @return \ArrayIterator<string, FormView> The iterator
*/
public function getIterator()
{

View File

@ -192,4 +192,34 @@ class SendgridApiTransportTest extends TestCase
$this->assertArrayHasKey('email', $payload['reply_to']);
$this->assertSame($replyTo, $payload['reply_to']['email']);
}
public function testEnvelopeSenderAndRecipients()
{
$from = 'from@example.com';
$to = 'to@example.com';
$envelopeFrom = 'envelopefrom@example.com';
$envelopeTo = 'envelopeto@example.com';
$email = new Email();
$email->from($from)
->to($to)
->cc('cc@example.com')
->bcc('bcc@example.com')
->text('content');
$envelope = new Envelope(new Address($envelopeFrom), [new Address($envelopeTo)]);
$transport = new SendgridApiTransport('ACCESS_KEY');
$method = new \ReflectionMethod(SendgridApiTransport::class, 'getPayload');
$method->setAccessible(true);
$payload = $method->invoke($transport, $email, $envelope);
$this->assertArrayHasKey('from', $payload);
$this->assertArrayHasKey('email', $payload['from']);
$this->assertSame($envelopeFrom, $payload['from']['email']);
$this->assertArrayHasKey('personalizations', $payload);
$this->assertArrayHasKey('to', $payload['personalizations'][0]);
$this->assertArrayHasKey('email', $payload['personalizations'][0]['to'][0]);
$this->assertCount(1, $payload['personalizations'][0]['to']);
$this->assertSame($envelopeTo, $payload['personalizations'][0]['to'][0]['email']);
}
}

View File

@ -84,7 +84,7 @@ class SendgridApiTransport extends AbstractApiTransport
}
$personalization = [
'to' => array_map($addressStringifier, $email->getTo()),
'to' => array_map($addressStringifier, $this->getRecipients($email, $envelope)),
'subject' => $email->getSubject(),
];
if ($emails = array_map($addressStringifier, $email->getCc())) {

View File

@ -19,7 +19,7 @@ namespace Symfony\Component\Security\Core\Authorization;
interface AuthorizationCheckerInterface
{
/**
* Checks if the attributes are granted against the current authentication token and optionally supplied subject.
* Checks if the attribute is granted against the current authentication token and optionally supplied subject.
*
* @param mixed $attribute A single attribute to vote on (can be of any type, string and instance of Expression are supported by the core)
* @param mixed $subject

View File

@ -23,6 +23,18 @@ class ClassDiscriminatorMapping
{
$this->typeProperty = $typeProperty;
$this->typesMapping = $typesMapping;
uasort($this->typesMapping, static function (string $a, string $b): int {
if (is_a($a, $b, true)) {
return -1;
}
if (is_a($b, $a, true)) {
return 1;
}
return 0;
});
}
public function getTypeProperty(): string

View File

@ -16,7 +16,8 @@ use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
/**
* @DiscriminatorMap(typeProperty="type", mapping={
* "first"="Symfony\Component\Serializer\Tests\Fixtures\AbstractDummyFirstChild",
* "second"="Symfony\Component\Serializer\Tests\Fixtures\AbstractDummySecondChild"
* "second"="Symfony\Component\Serializer\Tests\Fixtures\AbstractDummySecondChild",
* "third"="Symfony\Component\Serializer\Tests\Fixtures\AbstractDummyThirdChild",
* })
*/
abstract class AbstractDummy

View File

@ -0,0 +1,16 @@
<?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\Serializer\Tests\Fixtures;
final class AbstractDummyThirdChild extends AbstractDummyFirstChild
{
}

View File

@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping;
use Symfony\Component\Serializer\Tests\Fixtures\AbstractDummyFirstChild;
use Symfony\Component\Serializer\Tests\Fixtures\AbstractDummySecondChild;
use Symfony\Component\Serializer\Tests\Fixtures\AbstractDummyThirdChild;
/**
* @author Samuel Roze <samuel.roze@gmail.com>
@ -35,9 +36,11 @@ class ClassDiscriminatorMappingTest extends TestCase
{
$mapping = new ClassDiscriminatorMapping('type', [
'first' => AbstractDummyFirstChild::class,
'third' => AbstractDummyThirdChild::class,
]);
$this->assertEquals('first', $mapping->getMappedObjectType(new AbstractDummyFirstChild()));
$this->assertNull($mapping->getMappedObjectType(new AbstractDummySecondChild()));
$this->assertSame('third', $mapping->getMappedObjectType(new AbstractDummyThirdChild()));
}
}

View File

@ -21,6 +21,7 @@ use Symfony\Component\Serializer\Tests\Fixtures\AbstractDummy;
use Symfony\Component\Serializer\Tests\Fixtures\AbstractDummyFirstChild;
use Symfony\Component\Serializer\Tests\Fixtures\AbstractDummySecondChild;
use Symfony\Component\Serializer\Tests\Fixtures\IgnoreDummy;
use Symfony\Component\Serializer\Tests\Fixtures\AbstractDummyThirdChild;
use Symfony\Component\Serializer\Tests\Mapping\TestClassMetadataFactory;
/**
@ -66,6 +67,7 @@ class AnnotationLoaderTest extends TestCase
$expected = new ClassMetadata(AbstractDummy::class, new ClassDiscriminatorMapping('type', [
'first' => AbstractDummyFirstChild::class,
'second' => AbstractDummySecondChild::class,
'third' => AbstractDummyThirdChild::class,
]));
$expected->addAttributeMetadata(new AttributeMetadata('foo'));

View File

@ -385,6 +385,9 @@ class ConstraintViolationAssertion
}
}
/**
* @internal
*/
class AssertingContextualValidator implements ContextualValidatorInterface
{
private $context;