Skip to content

Commit 3700c2c

Browse files
committed
ContainerLoader: changed parameters and returned value of $generator (BC break!)
1 parent f82fb4c commit 3700c2c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/DI/ContainerLoader.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct($tempDirectory, $autoRebuild = FALSE)
3333

3434
/**
3535
* @param mixed
36-
* @param callable function(string $class): [code, files]
36+
* @param callable function(Nette\DI\Compiler $compiler): string|NULL
3737
* @return string
3838
*/
3939
public function load($key, $generator)
@@ -108,7 +108,11 @@ private function isExpired($file)
108108
*/
109109
protected function generate($class, $generator)
110110
{
111-
list($code, $files) = call_user_func($generator, $class);
111+
$compiler = new Compiler;
112+
$compiler->getContainerBuilder()->setClassName($class);
113+
$code = call_user_func_array($generator, array(& $compiler));
114+
$code = $code ?: implode("\n\n\n", $compiler->compile());
115+
$files = $compiler->getDependencies();
112116
$files = $files ? array_combine($files, $files) : array(); // workaround for PHP 5.3 array_combine
113117
return array(
114118
"<?php\n$code",

tests/DI/ContainerLoader.basic.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $key = array(1, 2);
1717
$className = $cache->getClassName($key);
1818
Assert::match('Container%[\w]+%', $className);
1919

20-
$container = $cache->load($key, function($class) {
21-
return array("class $class {}", array());
20+
$container = $cache->load($key, function() use ($className) {
21+
return "class $className {}";
2222
});
2323
Assert::type($className, new $container);

0 commit comments

Comments
 (0)