Merge branch '4.2'
* 4.2: [FrameworkBundle] decouple debug:autowiring from phpdocumentor/reflection-docblock Fix env fallback to an unresolved variable [DI] map snake-case ids of service subscribers to camel-case autowiring aliases
This commit is contained in:
commit
48658d957a
@ -11,8 +11,6 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor;
|
||||
|
||||
use phpDocumentor\Reflection\DocBlockFactory;
|
||||
use phpDocumentor\Reflection\DocBlockFactoryInterface;
|
||||
use Symfony\Component\Console\Descriptor\DescriptorInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
@ -293,21 +291,16 @@ abstract class Descriptor implements DescriptorInterface
|
||||
public static function getClassDescription(string $class, string &$resolvedClass = null): string
|
||||
{
|
||||
$resolvedClass = $class;
|
||||
|
||||
if (!interface_exists(DocBlockFactoryInterface::class)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
try {
|
||||
$r = new \ReflectionClass($class);
|
||||
$resolvedClass = $r->name;
|
||||
|
||||
if ($docComment = $r->getDocComment()) {
|
||||
return DocBlockFactory::createInstance()
|
||||
->create($docComment)
|
||||
->getSummary();
|
||||
$docComment = preg_split('#\n\s*\*\s*[\n@]#', substr($docComment, 3, -2), 2)[0];
|
||||
|
||||
return trim(preg_replace('#\s*\n\s*\*\s*#', ' ', $docComment));
|
||||
}
|
||||
} catch (\ReflectionException | \InvalidArgumentException $e) {
|
||||
} catch (\ReflectionException $e) {
|
||||
}
|
||||
|
||||
return '';
|
||||
|
@ -195,6 +195,22 @@ abstract class AbstractDescriptorTest extends TestCase
|
||||
return $this->getDescriptionTestData(ObjectsProvider::getCallables());
|
||||
}
|
||||
|
||||
/** @dataProvider getClassDescriptionTestData */
|
||||
public function testGetClassDecription($object, $expectedDescription)
|
||||
{
|
||||
$this->assertEquals($expectedDescription, $this->getDescriptor()->getClassDescription($object));
|
||||
}
|
||||
|
||||
public function getClassDescriptionTestData()
|
||||
{
|
||||
return array(
|
||||
array(ClassWithDocCommentOnMultipleLines::class, 'This is the first line of the description. This is the second line.'),
|
||||
array(ClassWithDocCommentWithoutInitialSpace::class, 'Foo.'),
|
||||
array(ClassWithoutDocComment::class, ''),
|
||||
array(ClassWithDocComment::class, 'This is a class with a doc comment.'),
|
||||
);
|
||||
}
|
||||
|
||||
abstract protected function getDescriptor();
|
||||
|
||||
abstract protected function getFormat();
|
||||
|
@ -221,3 +221,24 @@ class ClassWithoutDocComment
|
||||
class ClassWithDocComment
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the first line of the description.
|
||||
* This is the second line.
|
||||
*
|
||||
* This is the third and shouldn't be shown.
|
||||
*
|
||||
* @annot should not be parsed
|
||||
*/
|
||||
class ClassWithDocCommentOnMultipleLines
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
*Foo.
|
||||
*
|
||||
* @annot should not be parsed
|
||||
*/
|
||||
class ClassWithDocCommentWithoutInitialSpace
|
||||
{
|
||||
}
|
||||
|
@ -80,7 +80,6 @@
|
||||
},
|
||||
"suggest": {
|
||||
"ext-apcu": "For best performance of the system caches",
|
||||
"phpdocumentor/reflection-docblock": "For display additional information in debug:container",
|
||||
"symfony/console": "For using the console commands",
|
||||
"symfony/form": "For using forms",
|
||||
"symfony/serializer": "For using the serializer service",
|
||||
|
@ -91,6 +91,11 @@ class RegisterServiceSubscribersPass extends AbstractRecursivePass
|
||||
$name = null;
|
||||
}
|
||||
|
||||
if (null !== $name && !$this->container->has($name) && !$this->container->has($type.' $'.$name)) {
|
||||
$camelCaseName = lcfirst(str_replace(' ', '', ucwords(preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', ' ', $name))));
|
||||
$name = $this->container->has($type.' $'.$camelCaseName) ? $camelCaseName : $name;
|
||||
}
|
||||
|
||||
$subscriberMap[$key] = new TypedReference((string) $serviceMap[$key], $type, $optionalBehavior ?: ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $name);
|
||||
unset($serviceMap[$key]);
|
||||
}
|
||||
|
@ -1534,11 +1534,15 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
return $value;
|
||||
}
|
||||
|
||||
foreach ($bag->getEnvPlaceholders() as $env => $placeholders) {
|
||||
if (isset($placeholders[$value])) {
|
||||
$bag = new ParameterBag($bag->all());
|
||||
$envPlaceholders = $bag->getEnvPlaceholders();
|
||||
if (isset($envPlaceholders[$name][$value])) {
|
||||
$bag = new ParameterBag($bag->all());
|
||||
|
||||
return $bag->unescapeValue($bag->get("env($name)"));
|
||||
return $bag->unescapeValue($bag->get("env($name)"));
|
||||
}
|
||||
foreach ($envPlaceholders as $env => $placeholders) {
|
||||
if (isset($placeholders[$value])) {
|
||||
return $this->getEnv($env);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,11 +204,17 @@ class RegisterServiceSubscribersPassTest extends TestCase
|
||||
$subscriber = new class() implements ServiceSubscriberInterface {
|
||||
public static function getSubscribedServices()
|
||||
{
|
||||
return array('some.service' => 'stdClass');
|
||||
return array(
|
||||
'some.service' => 'stdClass',
|
||||
'some_service' => 'stdClass',
|
||||
'another_service' => 'stdClass',
|
||||
);
|
||||
}
|
||||
};
|
||||
$container->register('some.service', 'stdClass');
|
||||
$container->setAlias('stdClass $someService', 'some.service');
|
||||
$container->setAlias('stdClass $some_service', 'some.service');
|
||||
$container->setAlias('stdClass $anotherService', 'some.service');
|
||||
$container->register('foo', \get_class($subscriber))
|
||||
->addMethodCall('setContainer', array(new Reference(PsrContainerInterface::class)))
|
||||
->addTag('container.service_subscriber');
|
||||
@ -221,6 +227,8 @@ class RegisterServiceSubscribersPassTest extends TestCase
|
||||
|
||||
$expected = array(
|
||||
'some.service' => new ServiceClosureArgument(new TypedReference('stdClass', 'stdClass', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'some.service')),
|
||||
'some_service' => new ServiceClosureArgument(new TypedReference('stdClass', 'stdClass', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'some_service')),
|
||||
'another_service' => new ServiceClosureArgument(new TypedReference('stdClass', 'stdClass', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'anotherService')),
|
||||
);
|
||||
$this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));
|
||||
|
||||
@ -228,6 +236,8 @@ class RegisterServiceSubscribersPassTest extends TestCase
|
||||
|
||||
$expected = array(
|
||||
'some.service' => new ServiceClosureArgument(new TypedReference('some.service', 'stdClass')),
|
||||
'some_service' => new ServiceClosureArgument(new TypedReference('stdClass $some_service', 'stdClass')),
|
||||
'another_service' => new ServiceClosureArgument(new TypedReference('stdClass $anotherService', 'stdClass')),
|
||||
);
|
||||
$this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));
|
||||
}
|
||||
|
@ -738,6 +738,20 @@ class ContainerBuilderTest extends TestCase
|
||||
$this->assertSame('someFooBar', $container->getParameter('baz'));
|
||||
}
|
||||
|
||||
public function testFallbackEnv()
|
||||
{
|
||||
putenv('DUMMY_FOO=foo');
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->setParameter('foo', '%env(DUMMY_FOO)%');
|
||||
$container->setParameter('bar', 'bar%env(default:foo:DUMMY_BAR)%');
|
||||
|
||||
$container->compile(true);
|
||||
putenv('DUMMY_FOO');
|
||||
|
||||
$this->assertSame('barfoo', $container->getParameter('bar'));
|
||||
}
|
||||
|
||||
public function testCastEnv()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
Reference in New Issue
Block a user