8000 Move "build dir" to constructor · symfony/symfony@463940b · GitHub
[go: up one dir, main page]

Skip to content

Commit 463940b

Browse files
committed
Move "build dir" to constructor
1 parent 783ab2e commit 463940b

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,17 @@ class ConfigBuilderGenerator implements ConfigBuilderGeneratorInterface
3131
{
3232
private $classes;
3333

34+
private $outputDir;
35+
36+
public function __construct(string $outputDir)
37+
{
38+
$this->outputDir = $outputDir;
39+
}
40+
3441
/**
3542
* @return \Closure that will return the root config class
3643
*/
37-
public function build(ConfigurationInterface $configuration, string $outputDir): \Closure
44+
public function build(ConfigurationInterface $configuration): \Closure
3845
{
3946
$this->classes = [];
4047

@@ -51,7 +58,7 @@ public function NAME(): string
5158
}
5259
', ['ALIAS' => $rootNode->getPath()]);
5360

54-
$this->writeClasses($outputDir);
61+
$this->writeClasses($outputDir = $this->outputDir);
5562
$loader = \Closure::fromCallable(function () use ($outputDir, $rootClass) {
5663
$str = $outputDir.\DIRECTORY_SEPARATOR.$rootClass->getDirectory().\DIRECTORY_SEPARATOR.$rootClass->getFilename();
5764
require_once $str;

src/Symfony/Component/Config/Builder/ConfigBuilderGeneratorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ interface ConfigBuilderGeneratorInterface
2323
/**
2424
* @return \Closure that will return the root config class
2525
*/
26-
public function build(ConfigurationInterface $configuration, string $outputDir): \Closure;
26+
public function build(ConfigurationInterface $configuration): \Closure;
2727
}

src/Symfony/Component/Config/Tests/Builder/GeneratedConfigTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ private function generateConfigBuilder(string $configurationClass)
106106

107107
$outputDir = sys_get_temp_dir();
108108
// This line is helpful for debugging
109-
$outputDir = __DIR__.'/.build';
109+
// $outputDir = __DIR__.'/.build';
110110

111-
$loader = (new ConfigBuilderGenerator())->build(new $configurationClass(), $outputDir);
111+
$loader = (new ConfigBuilderGenerator($outputDir))->build(new $configurationClass());
112112

113113
return $loader();
114114
}

src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@
3333
class PhpFileLoader extends FileLoader
3434
{
3535
protected $autoRegisterAliasesForSinglyImplementedInterfaces = false;
36-
private $buildDir;
3736
private $generator;
3837

39-
public function __construct(ContainerBuilder $container, FileLocatorInterface $locator, string $env = null, string $buildDir = null, ConfigBuilderGeneratorInterface $generator = null)
38+
public function __construct(ContainerBuilder $container, FileLocatorInterface $locator, string $env = null, ConfigBuilderGeneratorInterface $generator = null)
4039
{
4140
parent::__construct($container, $locator, $env);
42-
$this->buildDir = $buildDir;
4341
$this->generator = $generator;
4442
}
4543

@@ -122,7 +120,7 @@ private function executeCallback(callable $callback, ContainerConfigurator $cont
122120
default:
123121
try {
124122
$configBuilder = $this->configBuilder($type);
125-
} catch (InvalidArgumentException $e) {
123+
} catch (InvalidArgumentException | \LogicException $e) {
126124
throw new \InvalidArgumentException(sprintf('Could not resolve argument "%s" for "%s".', $type.' '.$parameter->getName(), $path), 0, $e);
127125
}
128126
$configBuilders[] = $configBuilder;
@@ -147,8 +145,8 @@ private function configBuilder(string $namespace): ConfigBuilderInterface
147145
throw new \LogicException('You cannot use the config builder as the Config component is not installed. Try running "composer require symfony/config".');
148146
}
149147

150-
if (null === $this->buildDir) {
151-
throw new \LogicException('You cannot use the config builder without providing a path to the directory where to store the generated ConfigBuilders.');
148+
if (null === $this->generator) {
149+
throw new \LogicException('You cannot use the ConfigBuilders without providing a class implementing ConfigBuilderGeneratorInterface.');
152150
}
153151

154152
// If class exists and implements ConfigBuilderInterface
@@ -175,8 +173,7 @@ private function configBuilder(string $namespace): ConfigBuilderInterface
175173
}
176174

177175
$configuration = $extension->getConfiguration([], $this->container);
178-
$this->generator = $this->generator ?? new ConfigBuilderGenerator();
179-
$loader = $this->generator->build($configuration, $this->buildDir);
176+
$loader = $this->generator->build($configuration);
180177

181178
return $loader();
182179
}

src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use PHPUnit\Framework\TestCase;
1717
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
18+
use Symfony\Component\Config\Builder\ConfigBuilderGenerator;
1819
use Symfony\Component\Config\FileLocator;
1920
use Symfony\Component\DependencyInjection\ContainerBuilder;
2021
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
@@ -64,7 +65,7 @@ public function testConfig($file)
6465
$fixtures = realpath(__DIR__.'/../Fixtures');
6566
$container = new ContainerBuilder();
6667
$container->registerExtension(new \AcmeExtension());
67-
$loader = new PhpFileLoader($container, new FileLocator(), 'prod', sys_get_temp_dir());
68+
$loader = new PhpFileLoader($container, new FileLocator(), 'prod', new ConfigBuilderGenerator(sys_get_temp_dir()));
6869
$loader->load($fixtures.'/config/'.$file.'.php');
6970

7071
$container->compile();

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
1515
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
16+
use Symfony\Component\Config\Builder\ConfigBuilderGenerator;
1617
use Symfony\Component\Config\ConfigCache;
1718
use Symfony\Component\Config\Loader\DelegatingLoader;
1819
use Symfony\Component\Config\Loader\LoaderResolver;
@@ -758,7 +759,7 @@ protected function getContainerLoader(ContainerInterface $container)
758759
new XmlFileLoader($container, $locator, $env),
759760
new YamlFileLoader($container, $locator, $env),
760761
new IniFileLoader($container, $locator, $env),
761-
new PhpFileLoader($container, $locator, $env, $this->getBuildDir()),
762+
new PhpFileLoader($container, $locator, $env, new ConfigBuilderGenerator($this->getBuildDir())),
762763
new GlobFileLoader($container, $locator, $env),
763764
new DirectoryLoader($container, $locator, $env),
764765
new ClosureLoader($container, $env),

0 commit comments

Comments
 (0)
0