@@ -29,17 +29,16 @@ class PresenterFactory extends Nette\Object implements IPresenterFactory
2929 /** @var array */
3030 private $ cache = array ();
3131
32- /** @var Nette\DI\Container */
33- private $ container ;
32+ /** @var callable */
33+ private $ factory ;
3434
35- /** @var string */
36- private $ touchToRebuild ;
3735
38-
39- public function __construct (Nette \DI \Container $ container , $ touchToRebuild = NULL )
36+ /**
37+ * @param callable function(string $class): IPresenter
38+ */
39+ public function __construct ($ factory = NULL )
4040 {
41- $ this ->container = $ container ;
42- $ this ->touchToRebuild = $ touchToRebuild ;
41+ $ this ->factory = $ factory ?: function ($ class ) { return new $ class ; };
4342 }
4443
4544
@@ -50,25 +49,7 @@ public function __construct(Nette\DI\Container $container, $touchToRebuild = NUL
5049 */
5150 public function createPresenter ($ name )
5251 {
53- $ class = $ this ->getPresenterClass ($ name );
54- $ services = array_keys ($ this ->container ->findByTag ('nette.presenter ' ), $ class );
55- if (count ($ services ) > 1 ) {
56- throw new InvalidPresenterException ("Multiple services of type $ class found: " . implode (', ' , $ services ) . '. ' );
57-
58- } elseif (!$ services ) {
59- if ($ this ->touchToRebuild ) {
60- touch ($ this ->touchToRebuild );
61- }
62-
63- $ presenter = $ this ->container ->createInstance ($ class );
64- $ this ->container ->callInjects ($ presenter );
65- if ($ presenter instanceof UI \Presenter && $ presenter ->invalidLinkMode === NULL ) {
66- $ presenter ->invalidLinkMode = $ this ->container ->parameters ['debugMode ' ] ? UI \Presenter::INVALID_LINK_WARNING : UI \Presenter::INVALID_LINK_SILENT ;
67- }
68- return $ presenter ;
69- }
70-
71- return $ this ->container ->createService ($ services [0 ]);
52+ return call_user_func ($ this ->factory , $ this ->getPresenterClass ($ name ));
7253 }
7354
7455
0 commit comments