8000 Merge branch '3.4' into translation-loader-interface · symfony/symfony@e3ad468 · GitHub
[go: up one dir, main page]

Skip to content

Commit e3ad468

Browse files
authored
Merge branch '3.4' into translation-loader-interface
2 parents 1ba7a2a + 531b294 commit e3ad468

File tree

77 files changed

+890
-1268
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+890
-1268
lines changed

UPGRADE-3.3.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,16 +367,14 @@ Yaml
367367

368368
* Deprecated support for implicitly parsing non-string mapping keys as strings.
369369
Mapping keys that are no strings will lead to a `ParseException` in Symfony
370-
4.0. Use the `PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as
371-
strings.
370+
4.0. Use quotes to opt-in for keys to be parsed as strings.
372371

373372
Before:
374373

375374
```php
376375
$yaml = <<<YAML
377376
null: null key
378377
true: boolean true
379-
1: integer key
380378
2.0: float key
381379
YAML;
382380

@@ -388,13 +386,12 @@ Yaml
388386
```php
389387

390388
$yaml = <<<YAML
391-
null: null key
392-
true: boolean true
393-
1: integer key
394-
2.0: float key
389+
"null": null key
390+
"true": boolean true
391+
"2.0": float key
395392
YAML;
396393

397-
Yaml::parse($yaml, Yaml::PARSE_KEYS_AS_STRINGS);
394+
Yaml::parse($yaml);
398395
```
399396

400397
* Omitting the key of a mapping is deprecated and will throw a `ParseException` in Symfony 4.0.

UPGRADE-4.0.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,12 @@ FrameworkBundle
336336
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass` class
337337
has been removed. Use the `Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass`
338338
class instead.
339-
339+
340340
* Using the `KERNEL_DIR` environment variable and the automatic guessing based
341341
on the `phpunit.xml` file location have been removed from the `KernelTestCase::getKernelClass()`
342342
method implementation. Set the `KERNEL_CLASS` environment variable to the
343343
fully-qualified class name of your Kernel or override the `KernelTestCase::createKernel()`
344344
or `KernelTestCase::getKernelClass()` method instead.
345-
346-
* The methods `KernelTestCase::getPhpUnitXmlDir()` and `KernelTestCase::getPhpUnitCliConfigArgument()`
347-
have been removed.
348345

349346
* The `Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory` class has been removed.
350347
Use `Symfony\Component\Validator\ContainerConstraintValidatorFactory` instead.
@@ -556,10 +553,10 @@ TwigBridge
556553

557554
* The `TwigRendererEngine::setEnvironment()` method has been removed.
558555
Pass the Twig Environment as second argument of the constructor instead.
559-
556+
560557
* Removed `Symfony\Bridge\Twig\Command\DebugCommand::set/getTwigEnvironment` and the ability
561558
to pass a command name as first argument.
562-
559+
563560
* Removed `Symfony\Bridge\Twig\Command\LintCommand::set/getTwigEnvironment` and the ability
564561
to pass a command name as first argument.
565562

@@ -645,16 +642,15 @@ Yaml
645642
throws a `ParseException`.
646643

647644
* Removed support for implicitly parsing non-string mapping keys as strings.
648-
Mapping keys that are no strings will result in a `ParseException`. Use the
649-
`PARSE_KEYS_AS_STRINGS` flag to opt-in for keys to be parsed as strings.
645+
Mapping keys that are no strings will result in a `ParseException`. Use
646+
quotes to opt-in for keys to be parsed as strings.
650647

651648
Before:
652649

653650
```php
654651
$yaml = <<<YAML
655652
null: null key
656653
true: boolean true
657-
1: integer key
658654
2.0: float key
659655
YAML;
660656

@@ -666,13 +662,12 @@ Yaml
666662
```php
667663

668664
$yaml = <<<YAML
669-
null: null key
670-
true: boolean true
671-
1: integer key
672-
2.0: float key
665+
"null": null key
666+
"true": boolean true
667+
"2.0": float key
673668
YAML;
674669

675-
Yaml::parse($yaml, Yaml::PARSE_KEYS_AS_STRINGS);
670+
Yaml::parse($yaml);
676671
```
677672

678673
* Omitting the key of a mapping is not supported anymore and throws a `ParseException`.

src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,17 @@ public function getProperties($class, array $context = array())
5050
return;
5151
}
5252

53-
return array_merge($metadata->getFieldNames(), $metadata->getAssociationNames());
53+
$properties = array_merge($metadata->getFieldNames(), $metadata->getAssociationNames());
54+
55+
if ($metadata instanceof ClassMetadataInfo && class_exists('Doctrine\ORM\Mapping\Embedded') && $metadata->embeddedClasses) {
56+
$properties = array_filter($properties, function ($property) {
57+
return false === strpos($property, '.');
58+
});
59+
60+
$properties = array_merge($properties, array_keys($metadata->embeddedClasses));
61+
}
62+
63+
return $properties;
5464
}
5565

5666
/**
@@ -105,6 +115,10 @@ public function getTypes($class, $property, array $context = array())
105115
));
106116
}
107117

118+
if ($metadata instanceof ClassMetadataInfo && class_exists('Doctrine\ORM\Mapping\Embedded') && isset($metadata->embeddedClasses[$property])) {
119+
return array(new Type(Type::BUILTIN_TYPE_OBJECT, false, $metadata->embeddedClasses[$property]['class']));
120+
}
121+
108122
if ($metadata->hasField($property)) {
109123
$typeOfField = $metadata->getTypeOfField($property);
110124
$nullable = $metadata instanceof ClassMetadataInfo && $metadata->isNullable($property);

src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ public function testGetProperties()
6666
);
6767
}
6868

69+
public function testGetPropertiesWithEmbedded()
70+
{
71+
if (!class_exists('Doctrine\ORM\Mapping\Embedded')) {
72+
$this->markTestSkipped('@Embedded is not available in Doctrine ORM lower than 2.5.');
73+
}
74+
75+
$this->assertEquals(
76+
array(
77+
'id',
78+
'embedded',
79+
),
80+
$this->extractor->getProperties('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded')
81+
);
82+
}
83+
6984
/**
7085
* @dataProvider typesProvider
7186
*/
@@ -74,6 +89,27 @@ public function testExtract($property, array $type = null)
7489
$this->assertEquals($type, $this->extractor->getTypes('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy', $property, array()));
7590
}
7691

92+
public function testExtractWithEmbedded()
93+
{
94+
if (!class_exists('Doctrine\ORM\Mapping\Embedded')) {
95+
$this->markTestSkipped('@Embedded is not available in Doctrine ORM lower than 2.5.');
96+
}
97+
98+
$expectedTypes = array(new Type(
99+
Type::BUILTIN_TYPE_OBJECT,
100+
false,
101+
'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineEmbeddable'
102+
));
103+
104+
$actualTypes = $this->extractor->getTypes(
105+
'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded',
106+
'embedded',
107+
array()
108+
);
109+
110+
$this->assertEquals($expectedTypes, $actualTypes);
111+
}
112+
77113
public function typesProvider()
78114
{
79115
return array(
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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\PropertyInfo\Fixtures;
13+
14+
use Doctrine\ORM\Mapping\Column;
15+
use Doctrine\ORM\Mapping\Embeddable;
16+
17+
/**
18+
* @Embeddable
19+
*
20+
* @author Udaltsov Valentin <udaltsov.valentin@gmail.com>
21+
*/
22+
class DoctrineEmbeddable
23+
{
24+
/**
25+
* @Column(type="string")
26+
*/
27+
protected $field;
28+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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\PropertyInfo\Fixtures;
13+
14+
use Doctrine\ORM\Mapping\Column;
15+
use Doctrine\ORM\Mapping\Entity;
16+
use Doctrine\ORM\Mapping\Id;
17+
use Doctrine\ORM\Mapping\Embedded;
18+
19+
/**
20+
* @Entity
21+
*
22+
* @author Udaltsov Valentin <udaltsov.valentin@gmail.com>
23+
*/
24+
class DoctrineWithEmbedded
25+
{
26+
/**
27+
* @Id
28+
* @Column(type="smallint")
29+
*/
30+
public $id;
31+
32+
/**
33+
* @Embedded(class="DoctrineEmbeddable")
34+
*/
35+
protected $embedded;
36+
}

src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,20 @@ public function isProxyCandidate(Definition $definition)
6565
/**
6666
* {@inheritdoc}
6767
*/
68-
public function getProxyFactoryCode(Definition $definition, $id, $methodName = null)
68+
public function getProxyFactoryCode(Definition $definition, $id, $factoryCode = null)
6969
{
7070
$instantiation = 'return';
7171

7272
if ($definition->isShared()) {
7373
$instantiation .= " \$this->services['$id'] =";
7474
}
7575

76-
if (func_num_args() >= 3) {
77-
$methodName = func_get_arg(2);
78-
} else {
79-
@trigger_error(sprintf('You must use the third argument of %s to define the method to call to construct your service since version 3.1, not using it won\'t be supported in 4.0.', __METHOD__), E_USER_DEPRECATED);
80-
$methodName = 'get'.Container::camelize($id).'Service';
76+
if (null === $factoryCode) {
77 F438 +
@trigger_error(sprintf('The "%s()" method expects a third argument defining the code to execute to construct your service since version 3.4, providing it will be required in 4.0.', __METHOD__), E_USER_DEPRECATED);
78+
$factoryCode = '$this->get'.Container::camelize($id).'Service(false)';
79+
} elseif (false === strpos($factoryCode, '(')) {
80+
@trigger_error(sprintf('The "%s()" method expects its third argument to define the code to execute to construct your service since version 3.4, providing it will be required in 4.0.', __METHOD__), E_USER_DEPRECATED);
81+
$factoryCode = "\$this->$factoryCode(false)";
8182
}
8283
$proxyClass = $this->getProxyClassName($definition);
8384

@@ -92,7 +93,7 @@ public function getProxyFactoryCode(Definition $definition, $id, $methodName = n
9293
9394
$instantiation $constructorCall(
9495
function (&\$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface \$proxy) {
95-
\$wrappedInstance = \$this->$methodName(false);
96+
\$wrappedInstance = $factoryCode;
9697
9798
\$proxy->setProxyInitializer(null);
9899

src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Dumper/PhpDumperTest.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,9 @@ class PhpDumperTest extends TestCase
2727
{
2828
public function testDumpContainerWithProxyService()
2929
{
30-
$container = new ContainerBuilder();
31-
32-
$container->register('foo', 'stdClass');
33-
$container->getDefinition('foo')->setLazy(true);
34-
$container->compile();
35-
36-
$dumper = new PhpDumper($container);
37-
38-
$dumper->setProxyDumper(new ProxyDumper());
39-
40-
$dumpedString = $dumper->dump();
41-
4230
$this->assertStringMatchesFormatFile(
4331
__DIR__.'/../Fixtures/php/lazy_service_structure.txt',
44-
$dumpedString,
32+
$this->dumpLazyServiceProjectServiceContainer(),
4533
'->dump() does generate proxy lazy loading logic.'
4634
);
4735
}
@@ -51,17 +39,15 @@ public function testDumpContainerWithProxyService()
5139
*/
5240
public function testDumpContainerWithProxyServiceWillShareProxies()
5341
{
54-
if (class_exists(StaticProxyConstructor::class)) { // detecting ProxyManager v2
55-
require_once __DIR__.'/../Fixtures/php/lazy_service_with_hints.php';
56-
} else {
57-
require_once __DIR__.'/../Fixtures/php/lazy_service.php';
42+
if (!class_exists('LazyServiceProjectServiceContainer', false)) {
43+
eval('?>'.$this->dumpLazyServiceProjectServiceContainer());
5844
}
5945

6046
$container = new \LazyServiceProjectServiceContainer();
6147

62-
/* @var $proxy \stdClass_c1d194250ee2e2b7d2eab8b8212368a8 */
6348
$proxy = $container->get('foo');
64-
$this->assertInstanceOf('stdClass_c1d194250ee2e2b7d2eab8b8212368a8', $proxy);
49+
$this->assertInstanceOf('stdClass', $proxy);
50+
$this->assertInstanceOf('ProxyManager\Proxy\LazyLoadingInterface', $proxy);
6551
$this->assertSame($proxy, $container->get('foo'));
6652

6753
$this->assertFalse($proxy->isProxyInitialized());
@@ -71,4 +57,19 @@ public function testDumpContainerWithProxyServiceWillShareProxies()
7157
$this->assertTrue($proxy->isProxyInitialized());
7258
$this->assertSame($proxy, $container->get('foo'));
7359
}
60+
61+
private function dumpLazyServiceProjectServiceContainer()
62+
{
63+
$container = new ContainerBuilder();
64+
65+
$container->register('foo', 'stdClass');
66+
$container->getDefinition('foo')->setLazy(true);
67+
$container->compile();
68+
69+
$dumper = new PhpDumper($container);
70+
71+
$dumper->setProxyDumper(new ProxyDumper());
72+
73+
return $dumper->dump(array('class' => 'LazyServiceProjectServiceContainer'));
74+
}
7475
}

0 commit comments

Comments
 (0)
0