Skip to content

Commit 9fe3cce

Browse files
Merge branch '4.4' into 5.2
* 4.4: [DoctrineBridge] Allow bundles to define a driver type "attribute" fix test SocketStreamTest for Windows Fix issue with RequestMatcher when attribute is a closure [PropertyInfo] Use the right context for methods defined in traits
2 parents 449c60f + 32cce9f commit 9fe3cce

File tree

7 files changed

+78
-6
lines changed

7 files changed

+78
-6
lines changed

src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \Re
146146
}
147147

148148
if (!$bundleConfig['dir']) {
149-
if (\in_array($bundleConfig['type'], ['annotation', 'staticphp'])) {
149+
if (\in_array($bundleConfig['type'], ['annotation', 'staticphp', 'attribute'])) {
150150
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingObjectDefaultName();
151151
} else {
152152
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingResourceConfigDirectory();
@@ -186,6 +186,10 @@ protected function registerMappingDrivers(array $objectManager, ContainerBuilder
186186
$args[0] = array_merge(array_values($driverPaths), $args[0]);
187187
}
188188
$mappingDriverDef->setArguments($args);
189+
} elseif ('attribute' === $driverType) {
190+
$mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [
191+
array_values($driverPaths),
192+
]);
189193
} elseif ('annotation' == $driverType) {
190194
$mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [
191195
new Reference($this->getObjectManagerElementName('metadata.annotation_reader')),
@@ -227,8 +231,8 @@ protected function assertValidMappingConfiguration(array $mappingConfig, string
227231
throw new \InvalidArgumentException(sprintf('Specified non-existing directory "%s" as Doctrine mapping source.', $mappingConfig['dir']));
228232
}
229233

230-
if (!\in_array($mappingConfig['type'], ['xml', 'yml', 'annotation', 'php', 'staticphp'])) {
231-
throw new \InvalidArgumentException(sprintf('Can only configure "xml", "yml", "annotation", "php" or "staticphp" through the DoctrineBundle. Use your own bundle to configure other metadata drivers. You can register them by adding a new driver to the "%s" service definition.', $this->getObjectManagerElementName($objectManagerName.'_metadata_driver')));
234+
if (!\in_array($mappingConfig['type'], ['xml', 'yml', 'annotation', 'php', 'staticphp', 'attribute'])) {
235+
throw new \InvalidArgumentException(sprintf('Can only configure "xml", "yml", "annotation", "php", "staticphp" or "attribute" through the DoctrineBundle. Use your own bundle to configure other metadata drivers. You can register them by adding a new driver to the "%s" service definition.', $this->getObjectManagerElementName($objectManagerName.'_metadata_driver')));
232236
}
233237
}
234238

src/Symfony/Component/HttpFoundation/RequestMatcher.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ public function matches(Request $request)
164164
}
165165

166166
foreach ($this->attributes as $key => $pattern) {
167-
if (!preg_match('{'.$pattern.'}', $request->attributes->get($key))) {
167+
$requestAttribute = $request->attributes->get($key);
168+
if (!\is_string($requestAttribute)) {
169+
return false;
170+
}
171+
if (!preg_match('{'.$pattern.'}', $requestAttribute)) {
168172
return false;
169173
}
170174
}

src/Symfony/Component/HttpFoundation/Tests/RequestMatcherTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,19 @@ public function testAttributes()
164164
$this->assertFalse($matcher->matches($request));
165165
}
166166

167+
public function testAttributesWithClosure()
168+
{
169+
$matcher = new RequestMatcher();
170+
171+
$request = Request::create('/admin/foo');
172+
$request->attributes->set('_controller', function () {
173+
return new Response('foo');
174+
});
175+
176+
$matcher->matchAttribute('_controller', 'babar');
177+
$this->assertFalse($matcher->matches($request));
178+
}
179+
167180
public function testIps()
168181
{
169182
$matcher = new RequestMatcher();

src/Symfony/Component/Mailer/Tests/Transport/Smtp/Stream/SocketStreamTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class SocketStreamTest extends TestCase
2020
public function testSocketErrorNoConnection()
2121
{
2222
$this->expectException(TransportException::class);
23-
$this->expectExceptionMessageMatches('/Connection refused|unable to connect/');
23+
$this->expectExceptionMessageMatches('/Connection refused|unable to connect/i');
2424
$s = new SocketStream();
2525
$s->setTimeout(0.1);
2626
$s->setPort(9999);

src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,17 @@ private function getDocBlockFromMethod(string $class, string $ucFirstProperty, i
326326
}
327327

328328
try {
329-
return [$this->docBlockFactory->create($reflectionMethod, $this->createFromReflector($reflectionMethod->getDeclaringClass())), $prefix];
329+
$reflector = $reflectionMethod->getDeclaringClass();
330+
331+
foreach ($reflector->getTraits() as $trait) {
332+
if ($trait->hasMethod($methodName)) {
333+
$reflector = $trait;
334+
335+
break;
336+
}
337+
}
338+
339+
return [$this->docBlockFactory->create($reflectionMethod, $this->createFromReflector($reflector)), $prefix];
330340
} catch (\InvalidArgumentException $e) {
331341
return null;
332342
} catch (\RuntimeException $e) {

src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpDocExtractorTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,23 @@ public function propertiesDefinedByTraitsProvider(): array
344344
];
345345
}
346346

347+
/**
348+
* @dataProvider methodsDefinedByTraitsProvider
349+
*/
350+
public function testMethodsDefinedByTraits(string $property, Type $type)
351+
{
352+
$this->assertEquals([$type], $this->extractor->getTypes(DummyUsingTrait::class, $property));
353+
}
354+
355+
public function methodsDefinedByTraitsProvider(): array
356+
{
357+
return [
358+
['methodInTraitPrimitiveType', new Type(Type::BUILTIN_TYPE_STRING)],
359+
['methodInTraitObjectSameNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, DummyUsedInTrait::class)],
360+
['methodInTraitObjectDifferentNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)],
361+
];
362+
}
363+
347364
/**
348365
* @dataProvider propertiesStaticTypeProvider
349366
*/

src/Symfony/Component/PropertyInfo/Tests/Fixtures/TraitUsage/DummyTrait.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,28 @@ trait DummyTrait
2929
* @var Dummy
3030
*/
3131
private $propertyInTraitObjectDifferentNamespace;
32+
33+
/**
34+
* @return string
35+
*/
36+
public function getMethodInTraitPrimitiveType()
37+
{
38+
return 'value';
39+
}
40+
41+
/**
42+
* @return DummyUsedInTrait
43+
*/
44+
public function getMethodInTraitObjectSameNamespace()
45+
{
46+
return new DummyUsedInTrait();
47+
}
48+
49+
/**
50+
* @return Dummy
51+
*/
52+
public function getMethodInTraitObjectDifferentNamespace()
53+
{
54+
return new Dummy();
55+
}
3256
}

0 commit comments

Comments
 (0)