8000 Merge branch '4.3' into 4.4 · symfony/symfony@926ded8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 926ded8

Browse files
committed
Merge branch '4.3' into 4.4
* 4.3: Fix inconsistency in json format regarding DST value changed type hints do not process private properties from parent class [HttpClient] fix unregistering the debug buffer when using curl don't add embedded properties to wrapping class metadata [Messenger] set amqp content_type based on serialization format [Mailer] fixed the possibility to set a From header from MessageListener
2 parents 491c0d5 + 33f3933 commit 926ded8

File tree

16 files changed

+306
-71
lines changed

16 files changed

+306
-71
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
13+
14+
use Doctrine\ORM\Mapping as ORM;
15+
16+
/**
17+
* @ORM\Embeddable
18+
*/
19+
class DoctrineLoaderEmbed
20+
{
21+
/**
22+
* @ORM\Column(length=25)
23+
*/
24+
public $embeddedMaxLength;
25+
}

src/Symfony/Bridge/Doctrine/Tests/Fixtures/DoctrineLoaderEntity.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @author Kévin Dunglas <dunglas@gmail.com>
2323
*/
24-
class DoctrineLoaderEntity
24+
class DoctrineLoaderEntity extends DoctrineLoaderParentEntity
2525
{
2626
/**
2727
* @ORM\Id
@@ -55,4 +55,9 @@ class DoctrineLoaderEntity
5555
* @ORM\Column(unique=true)
5656
*/
5757
public $alreadyMappedUnique;
58+
59+
/**
60+
* @ORM\Embedded(class=DoctrineLoaderEmbed::class)
61+
*/
62+
public $embedded;
5863
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
13+
14+
use Doctrine\ORM\Mapping as ORM;
15+
16+
/**
17+
* @ORM\MappedSuperclass
18+
*/
19+
class DoctrineLoaderParentEntity
20+
{
21+
/**
22+
* @ORM\Column(length=35)
23+
*/
24+
public $publicParentMaxLength;
25+
26+
/**
27+
* @ORM\Column(length=30)
28+
*/
29+
private $privateParentMaxLength;
30+
31+
public function getPrivateParentMaxLength()
32+
{
33+
return $this->privateParentMaxLength;
34+
}
35+
36+
public function setPrivateParentMaxLength($privateParentMaxLength): void
37+
{
38+
$this->privateParentMaxLength = $privateParentMaxLength;
39+
}
40+
}

src/Symfony/Bridge/Doctrine/Tests/Validator/DoctrineLoaderTest.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
1616
use Symfony\Bridge\Doctrine\Tests\Fixtures\BaseUser;
17+
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoctrineLoaderEmbed;
1718
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoctrineLoaderEntity;
19+
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoctrineLoaderParentEntity;
1820
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
1921
use Symfony\Bridge\Doctrine\Validator\DoctrineLoader;
2022
use Symfony\Component\Validator\Constraints\Length;
23+
use Symfony\Component\Validator\Mapping\CascadingStrategy;
2124
use Symfony\Component\Validator\Mapping\ClassMetadata;
25+
use Symfony\Component\Validator\Mapping\TraversalStrategy;
2226
use Symfony\Component\Validator\Tests\Fixtures\Entity;
2327
use Symfony\Component\Validator\Validation;
2428
use Symfony\Component\Validator\ValidatorBuilder;
@@ -36,7 +40,7 @@ public function testLoadClassMetadata()
3640

3741
$validator = Validation::createValidatorBuilder()
3842
->enableAnnotationMapping()
39-
->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{^Symfony\\\\Bridge\\\\Doctrine\\\\Tests\\\\Fixtures\\\\DoctrineLoaderEntity$}'))
43+
->addLoader(new DoctrineLoader(DoctrineTestHelper::createTestEntityManager(), '{^Symfony\\\\Bridge\\\\Doctrine\\\\Tests\\\\Fixtures\\\\DoctrineLoader}'))
4044
->getValidator()
4145
;
4246

@@ -71,6 +75,39 @@ public function testLoadClassMetadata()
7175
$this->assertInstanceOf(Length::class, $alreadyMappedMaxLengthConstraints[0]);
7276
$this->assertSame(10, $alreadyMappedMaxLengthConstraints[0]->max);
7377
$this->assertSame(1, $alreadyMappedMaxLengthConstraints[0]->min);
78+
79+
$publicParentMaxLengthMetadata = $classMetadata->getPropertyMetadata('publicParentMaxLength');
80+
$this->assertCount(1, $publicParentMaxLengthMetadata);
81+
$publicParentMaxLengthConstraints = $publicParentMaxLengthMetadata[0]->getConstraints();
82+
$this->assertCount(1, $publicParentMaxLengthConstraints);
83+
$this->assertInstanceOf(Length::class, $publicParentMaxLengthConstraints[0]);
84+
$this->assertSame(35, $publicParentMaxLengthConstraints[0]->max);
85+
86+
$embeddedMetadata = $classMetadata->getPropertyMetadata('embedded');
87+
$this->assertCount(1, $embeddedMetadata);
88+
$this->assertSame(CascadingStrategy::CASCADE, $embeddedMetadata[0]->getCascadingStrategy());
89+
$this->assertSame(TraversalStrategy::IMPLICIT, $embeddedMetadata[0]->getTraversalStrategy());
90+
91+
$parentClassMetadata = $validator->getMetadataFor(new DoctrineLoaderParentEntity());
92+
93+
$publicParentMaxLengthMetadata = $parentClassMetadata->getPropertyMetadata('publicParentMaxLength');
94+
$this->assertCount(0, $publicParentMaxLengthMetadata);
95+
96+
$privateParentMaxLengthMetadata = $parentClassMetadata->getPropertyMetadata('privateParentMaxLength');
97+
$this->assertCount(1, $privateParentMaxLengthMetadata);
98+
$privateParentMaxLengthConstraints = $privateParentMaxLengthMetadata[0]->getConstraints();
99+
$this->assertCount(1, $privateParentMaxLengthConstraints);
100+
$this->assertInstanceOf(Length::class, $privateParentMaxLengthConstraints[0]);
101+
$this->assertSame(30, $privateParentMaxLengthConstraints[0]->max);
102+
103+
$embeddedClassMetadata = $validator->getMetadataFor(new DoctrineLoaderEmbed());
104+
105+
$embeddedMaxLengthMetadata = $embeddedClassMetadata->getPropertyMetadata('embeddedMaxLength');
106+
$this->assertCount(1, $embeddedMaxLengthMetadata);
107+
$embeddedMaxLengthConstraints = $embeddedMaxLengthMetadata[0]->getConstraints();
108+
$this->assertCount(1, $embeddedMaxLengthConstraints);
109+
$this->assertInstanceOf(Length::class, $embeddedMaxLengthConstraints[0]);
110+
$this->assertSame(25, $embeddedMaxLengthConstraints[0]->max);
74111
}
75112

76113
public function testFieldMappingsConfiguration()

src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Doctrine\ORM\Mapping\MappingException as OrmMappingException;
1818
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
1919
use Symfony\Component\Validator\Constraints\Length;
20+
use Symfony\Component\Validator\Constraints\Valid;
2021
use Symfony\Component\Validator\Mapping\ClassMetadata;
2122
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
2223

@@ -78,7 +79,11 @@ public function loadClassMetadata(ClassMetadata $metadata): bool
7879

7980
$constraint = $this->getLengthConstraint($metadata, $mapping['fieldName']);
8081
if (null === $constraint) {
81-
$metadata->addPropertyConstraint($mapping['fieldName'], new Length(['max' => $mapping['length']]));
82+
if (isset($mapping['originalClass'])) {
83+
$metadata->addPropertyConstraint($mapping['declaredField'], new Valid());
84+
} elseif (property_exists($className, $mapping['fieldName'])) {
85+
$metadata->addPropertyConstraint($mapping['fieldName'], new Length(['max' => $mapping['length']]));
86+
}
8287
} elseif (null === $constraint->max) {
8388
// If a Length constraint exists and no max length has been explicitly defined, set it
8489
$constraint->max = $mapping['length'];

src/Symfony/Component/HttpClient/Response/CurlResponse.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public function getInfo(string $type = null)
167167
if (!\in_array(curl_getinfo($this->handle, CURLINFO_PRIVATE), ['headers', 'content'], true)) {
168168
rewind($this->debugBuffer);
169169
$info['debug'] = stream_get_contents($this->debugBuffer);
170+
curl_setopt($this->handle, CURLOPT_VERBOSE, false);
170171
fclose($this->debugBuffer);
171172
$this->debugBuffer = null;
172173
$this->finalInfo = $info;
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Mailer;
13+
14+
use Symfony\Component\Mailer\Exception\LogicException;
15+
use Symfony\Component\Mime\Address;
16+
use Symfony\Component\Mime\Header\Headers;
17+
use Symfony\Component\Mime\Message;
18+
19+
/**
20+
* @author Fabien Potencier <fabien@symfony.com>
21+
*
22+
* @experimental in 4.3
23+
*
24+
* @internal
25+
*/
26+
final class DelayedSmtpEnvelope extends SmtpEnvelope
27+
{
28+
private $senderSet = false;
29+
private $recipientsSet = false;
30+
private $message;
31+
32+
public function __construct(Message $message)
33+
{
34+
$this->message = $message;
35+
}
36+
37+
public function setSender(Address $sender): void
38+
{
39+
parent::setSender($sender);
40+
41+
$this->senderSet = true;
42+
}
43+
44+
public function getSender(): Address
45+
{
46+
if ($this->senderSet) {
47+
return parent::getSender();
48+
}
49+
50+
return self::getSenderFromHeaders($this->message->getHeaders());
51+
}
52+
53+
public function setRecipients(array $recipients): void
54+
{
55+
parent::setRecipients($recipients);
56+
57+
$this->recipientsSet = parent::getRecipients();
58+
}
59+
60+
/**
61+
* @return Address[]
62+
*/
63+
public function getRecipients(): array
64+
{
65+
if ($this->recipientsSet) {
66+
return parent::getRecipients();
67+
}
68+
69+
return self::getRecipientsFromHeaders($this->message->getHeaders());
70+
}
71+
72+
private static function getRecipientsFromHeaders(Headers $headers): array
73+
{
74+
$recipients = [];
75+
foreach (['to', 'cc', 'bcc'] as $name) {
76+
foreach ($headers->getAll($name) as $header) {
77+
$recipients = array_merge($recipients, $header->getAddresses());
78+
}
79+
}
80+
81+
return $recipients;
82+
}
83+
84+
private static function getSenderFromHeaders(Headers $headers): Address
85+
{
86+
if ($return = $headers->get('Return-Path')) {
87+
return $return->getAddress();
88+
}
89+
if ($sender = $headers->get('Sender')) {
90+
return $sender->getAddress();
91+
}
92+
if ($from = $headers->get('From')) {
93+
return $from->getAddresses()[0];
94+
}
95+
96+
throw new LogicException('Unable to determine the sender of the message.');
97+
}
98+
}

src/Symfony/Component/Mailer/SmtpEnvelope.php

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
namespace Symfony\Component\Mailer;
1313

1414
use Symfony\Component\Mailer\Exception\InvalidArgumentException;
15-
use Symfony\Component\Mailer\Exception\LogicException;
1615
use Symfony\Component\Mime\Address;
17-
use Symfony\Component\Mime\Header\Headers;
18-
use Symfony\Component\Mime\Message;
1916
use Symfony\Component\Mime\NamedAddress;
2017
use Symfony\Component\Mime\RawMessage;
2118

@@ -40,14 +37,7 @@ public function __construct(Address $sender, array $recipients)
4037

4138
public static function create(RawMessage $message): self
4239
{
43-
if ($message instanceof Message) {
44-
$headers = $message->getHeaders();
45-
46-
return new self(self::getSenderFromHeaders($headers), self::getRecipientsFromHeaders($headers));
47-
}
48-
49-
// FIXME: parse the raw message to create the envelope?
50-
throw new InvalidArgumentException(sprintf('Unable to create an SmtpEnvelope from a "%s" message.', RawMessage::class));
40+
return new DelayedSmtpEnvelope($message);
5141
}
5242

5343
public function setSender(Address $sender): void
@@ -84,31 +74,4 @@ public function getRecipients(): array
8474
{
8575
return $this->recipients;
8676
}
87-
88-
private static function getRecipientsFromHeaders(Headers $headers): array
89-
{
90-
$recipients = [];
91-
foreach (['to', 'cc', 'bcc'] as $name) {
92-
foreach ($headers->getAll($name) as $header) {
93-
$recipients = array_merge($recipients, $header->getAddresses());
94-
}
95-
}
96-
97-
return $recipients;
98-
}
99-
100-
private static function getSenderFromHeaders(Headers $headers): Address
101-
{
102-
if ($return = $headers->get('Return-Path')) {
103-
return $return->getAddress();
104-
}
105-
if ($sender = $headers->get('Sender')) {
106-
return $sender->getAddress();
107-
}
108-
if ($from = $headers->get('From')) {
109-
return $from->getAddresses()[0];
110-
}
111-
112-
throw new LogicException('Unable to determine the sender of the message.');
113-
}
11477
}

src/Symfony/Component/Mailer/Tests/SmtpEnvelopeTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@ public function testSenderFromHeaders()
7272
$this->assertEquals('from@symfony.com', $e->getSender()->getAddress());
7373
}
7474

75-
public function testSenderFromHeadersWithoutData()
75+
public function testSenderFromHeadersWithoutFrom()
7676
{
77-
$this->expectException(\LogicException::class);
7877
$headers = new Headers();
7978
$headers->addMailboxListHeader('To', ['from@symfony.com']);
80-
SmtpEnvelope::create(new Message($headers));
79+
$e = SmtpEnvelope::create($message = new Message($headers));
80+
$message->getHeaders()->addMailboxListHeader('From', ['from@symfony.com']);
81+
$this->assertEquals('from@symfony.com', $e->getSender()->getAddress());
8182
}
8283

8384
public function testRecipientsFromHeaders()
@@ -90,10 +91,4 @@ public function testRecipientsFromHeaders()
9091
$e = SmtpEnvelope::create(new Message($headers));
9192
$this->assertEquals([new Address('to@symfony.com'), new Address('cc@symfony.com'), new Address('bcc@symfony.com')], $e->getRecipients());
9293
}
93-
94-
public function testCreateWithRawMessage()
95-
{
96-
$this->expectException(\InvalidArgumentException::class);
97-
SmtpEnvelope::create(new RawMessage(''));
98-
}
9994 17AE
}

src/Symfony/Component/Mailer/Transport/AbstractTransport.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Psr\Log\NullLogger;
1616
use Symfony\Component\EventDispatcher\EventDispatcher;
1717
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
18+
use Symfony\Component\Mailer\DelayedSmtpEnvelope;
1819
use Symfony\Component\Mailer\Event\MessageEvent;
1920
use Symfony\Component\Mailer\Exception\TransportException;
2021
use Symfony\Component\Mailer\SentMessage;
@@ -62,7 +63,7 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
6263
$envelope = clone $envelope;
6364
} else {
6465
try {
65-
$envelope = SmtpEnvelope::create($message);
66+
$envelope = new DelayedSmtpEnvelope($message);
6667
} catch (\Exception $e) {
6768
throw new TransportException('Cannot send message without a valid envelope.', 0, $e);
6869
}

0 commit comments

Comments
 (0)
0