Merge branch '5.2' into 5.x
* 5.2: [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
This commit is contained in:
commit
d7e059c05c
@ -146,7 +146,7 @@ abstract class AbstractDoctrineExtension extends Extension
|
||||
}
|
||||
|
||||
if (!$bundleConfig['dir']) {
|
||||
if (\in_array($bundleConfig['type'], ['annotation', 'staticphp'])) {
|
||||
if (\in_array($bundleConfig['type'], ['annotation', 'staticphp', 'attribute'])) {
|
||||
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingObjectDefaultName();
|
||||
} else {
|
||||
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingResourceConfigDirectory();
|
||||
@ -186,6 +186,10 @@ abstract class AbstractDoctrineExtension extends Extension
|
||||
$args[0] = array_merge(array_values($driverPaths), $args[0]);
|
||||
}
|
||||
$mappingDriverDef->setArguments($args);
|
||||
} elseif ('attribute' === $driverType) {
|
||||
$mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [
|
||||
array_values($driverPaths),
|
||||
]);
|
||||
} elseif ('annotation' == $driverType) {
|
||||
$mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [
|
||||
new Reference($this->getObjectManagerElementName('metadata.annotation_reader')),
|
||||
@ -227,8 +231,8 @@ abstract class AbstractDoctrineExtension extends Extension
|
||||
throw new \InvalidArgumentException(sprintf('Specified non-existing directory "%s" as Doctrine mapping source.', $mappingConfig['dir']));
|
||||
}
|
||||
|
||||
if (!\in_array($mappingConfig['type'], ['xml', 'yml', 'annotation', 'php', 'staticphp'])) {
|
||||
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')));
|
||||
if (!\in_array($mappingConfig['type'], ['xml', 'yml', 'annotation', 'php', 'staticphp', 'attribute'])) {
|
||||
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')));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,11 @@ class RequestMatcher implements RequestMatcherInterface
|
||||
}
|
||||
|
||||
foreach ($this->attributes as $key => $pattern) {
|
||||
if (!preg_match('{'.$pattern.'}', $request->attributes->get($key))) {
|
||||
$requestAttribute = $request->attributes->get($key);
|
||||
if (!\is_string($requestAttribute)) {
|
||||
return false;
|
||||
}
|
||||
if (!preg_match('{'.$pattern.'}', $requestAttribute)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -164,6 +164,19 @@ class RequestMatcherTest extends TestCase
|
||||
$this->assertFalse($matcher->matches($request));
|
||||
}
|
||||
|
||||
public function testAttributesWithClosure()
|
||||
{
|
||||
$matcher = new RequestMatcher();
|
||||
|
||||
$request = Request::create('/admin/foo');
|
||||
$request->attributes->set('_controller', function () {
|
||||
return new Response('foo');
|
||||
});
|
||||
|
||||
$matcher->matchAttribute('_controller', 'babar');
|
||||
$this->assertFalse($matcher->matches($request));
|
||||
}
|
||||
|
||||
public function testIps()
|
||||
{
|
||||
$matcher = new RequestMatcher();
|
||||
|
@ -20,7 +20,7 @@ class SocketStreamTest extends TestCase
|
||||
public function testSocketErrorNoConnection()
|
||||
{
|
||||
$this->expectException(TransportException::class);
|
||||
$this->expectExceptionMessageMatches('/Connection refused|unable to connect/');
|
||||
$this->expectExceptionMessageMatches('/Connection refused|unable to connect/i');
|
||||
$s = new SocketStream();
|
||||
$s->setTimeout(0.1);
|
||||
$s->setPort(9999);
|
||||
|
@ -326,7 +326,17 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
||||
}
|
||||
|
||||
try {
|
||||
return [$this->docBlockFactory->create($reflectionMethod, $this->createFromReflector($reflectionMethod->getDeclaringClass())), $prefix];
|
||||
$reflector = $reflectionMethod->getDeclaringClass();
|
||||
|
||||
foreach ($reflector->getTraits() as $trait) {
|
||||
if ($trait->hasMethod($methodName)) {
|
||||
$reflector = $trait;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return [$this->docBlockFactory->create($reflectionMethod, $this->createFromReflector($reflector)), $prefix];
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return null;
|
||||
} catch (\RuntimeException $e) {
|
||||
|
@ -344,6 +344,23 @@ class PhpDocExtractorTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider methodsDefinedByTraitsProvider
|
||||
*/
|
||||
public function testMethodsDefinedByTraits(string $property, Type $type)
|
||||
{
|
||||
$this->assertEquals([$type], $this->extractor->getTypes(DummyUsingTrait::class, $property));
|
||||
}
|
||||
|
||||
public function methodsDefinedByTraitsProvider(): array
|
||||
{
|
||||
return [
|
||||
['methodInTraitPrimitiveType', new Type(Type::BUILTIN_TYPE_STRING)],
|
||||
['methodInTraitObjectSameNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, DummyUsedInTrait::class)],
|
||||
['methodInTraitObjectDifferentNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider propertiesStaticTypeProvider
|
||||
*/
|
||||
|
@ -29,4 +29,28 @@ trait DummyTrait
|
||||
* @var Dummy
|
||||
*/
|
||||
private $propertyInTraitObjectDifferentNamespace;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMethodInTraitPrimitiveType()
|
||||
{
|
||||
return 'value';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DummyUsedInTrait
|
||||
*/
|
||||
public function getMethodInTraitObjectSameNamespace()
|
||||
{
|
||||
return new DummyUsedInTrait();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Dummy
|
||||
*/
|
||||
public function getMethodInTraitObjectDifferentNamespace()
|
||||
{
|
||||
return new Dummy();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user