[DI] Allow using parameters in "prototype" resource paths

This commit is contained in:
Nicolas Grekas 2017-04-11 12:58:51 +02:00
parent 35afac00a0
commit d3fc86c709
2 changed files with 15 additions and 0 deletions

View File

@ -85,6 +85,8 @@ abstract class FileLoader extends BaseFileLoader
private function findClasses($namespace, $resource)
{
$parameterBag = $this->container->getParameterBag();
$resource = $parameterBag->unescapeValue($parameterBag->resolveValue($resource));
$classes = array();
$extRegexp = defined('HHVM_VERSION') ? '/\\.(?:php|hh)$/' : '/\\.php$/';
$prefixLen = null;

View File

@ -15,12 +15,14 @@ use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\FileLoader;
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar;
class FileLoaderTest extends TestCase
{
@ -73,6 +75,17 @@ class FileLoaderTest extends TestCase
$this->assertEquals(array_keys($expected), array_keys($actual), '->load() imports and merges imported files');
}
public function testRegisterClasses()
{
$container = new ContainerBuilder();
$container->setParameter('sub_dir', 'Sub');
$loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'));
$loader->registerClasses(new Definition(), 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\\', 'Prototype/%sub_dir%/*');
$this->assertTrue($container->has(Bar::class));
}
}
class TestFileLoader extends FileLoader