Last active
October 10, 2018 06:44
-
-
Save bazo/358977a9c27d7ed92ef8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Nette\Application\UI\Presenter; | |
use Nette\DI\CompilerExtension; | |
/** | |
* Auto register presenters as services | |
* @author Martin Bažík <[email protected]> | |
*/ | |
class PresenterExtension extends CompilerExtension | |
{ | |
private $defaults = [ | |
'robotLoaderVarName' => 'robotLoader' | |
]; | |
public function loadConfiguration() | |
{ | |
$config = $this->getConfig($this->defaults); | |
$builder = $this->getContainerBuilder(); | |
$robotLoaderVarName = $config['robotLoaderVarName']; | |
global $$robotLoaderVarName; | |
$classes = $$robotLoaderVarName->getIndexedClasses(); | |
foreach ($classes as $class => $file) { | |
$r = new ReflectionClass($class); | |
if (!$r->isAbstract() and $r->isSubclassOf(Presenter::class)) { | |
$defName = str_replace('\\', '_', $r->getName()); | |
$builder | |
->addDefinition($defName) | |
->setClass($class) | |
->setAutowired(FALSE) | |
; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've got more time for testing now and had problem:
I really don't understand the output of your discussion with David. Could you sum up pls?