bug #22372 [DI] Allow using parameters in "prototype" resource paths (nicolas-grekas)

This PR was merged into the 3.3-dev branch.

Discussion
----------

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

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #22016
| License       | MIT
| Doc PR        | -

Commits
-------

d3fc86c709 [DI] Allow using parameters in "prototype" resource paths
This commit is contained in:
Fabien Potencier 2017-04-11 11:36:38 -07:00
commit 5b4091ed7c
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