55use Contributte \Console \Application ;
66use Contributte \Console \CommandLoader \ContainerCommandLoader ;
77use Contributte \Console \Exception \Logical \InvalidArgumentException ;
8+ use Contributte \DI \Helper \ExtensionDefinitionsHelper ;
89use Nette \DI \CompilerExtension ;
10+ use Nette \DI \Definitions \Definition ;
911use Nette \DI \Definitions \ServiceDefinition ;
1012use Nette \DI \Definitions \Statement ;
1113use Nette \DI \MissingServiceException ;
1517use Nette \Schema \Expect ;
1618use Nette \Schema \Schema ;
1719use Nette \Utils \Arrays ;
18- use Nette \Utils \Strings ;
1920use stdClass ;
2021use Symfony \Component \Console \Command \Command ;
2122use Symfony \Component \Console \CommandLoader \CommandLoaderInterface ;
@@ -49,8 +50,10 @@ public function getConfigSchema(): Schema
4950 'version ' => Expect::anyOf (Expect::string (), Expect::int (), Expect::float ()),
5051 'catchExceptions ' => Expect::bool (),
5152 'autoExit ' => Expect::bool (),
52- 'helperSet ' => Expect::string (),
53- 'helpers ' => Expect::listOf ('string ' ),
53+ 'helperSet ' => Expect::anyOf (Expect::string (), Expect::array (), Expect::type (Statement::class)),
54+ 'helpers ' => Expect::arrayOf (
55+ Expect::anyOf (Expect::string (), Expect::array (), Expect::type (Statement::class))
56+ ),
5457 'lazy ' => Expect::bool (true ),
5558 ]);
5659 }
@@ -67,6 +70,7 @@ public function loadConfiguration(): void
6770
6871 $ builder = $ this ->getContainerBuilder ();
6972 $ config = $ this ->config ;
73+ $ definitionsHelper = new ExtensionDefinitionsHelper ($ this ->compiler );
7074
7175 $ applicationDef = $ builder ->addDefinition ($ this ->prefix ('application ' ))
7276 ->setFactory (Application::class);
@@ -88,27 +92,26 @@ public function loadConfiguration(): void
8892 }
8993
9094 if ($ config ->helperSet !== null ) {
91- if (Strings::startsWith ($ config ->helperSet , '@ ' )) {
92- // Add already defined service
93- $ applicationDef ->addSetup ('setHelperSet ' , [$ config ->helperSet ]);
94- } else {
95- // Parse service definition
96- $ helperSetDef = $ builder ->addDefinition ($ this ->prefix ('helperSet ' ))
97- ->setFactory ($ config ->helperSet );
98- $ applicationDef ->addSetup ('setHelperSet ' , [$ helperSetDef ]);
95+ $ helperSetConfig = $ config ->helperSet ;
96+ $ helperSetPrefix = $ this ->prefix ('helperSet ' );
97+ $ helperSetDef = $ definitionsHelper ->getDefinitionFromConfig ($ helperSetConfig , $ helperSetPrefix );
98+
99+ if ($ helperSetDef instanceof Definition) {
100+ $ helperSetDef ->setAutowired (false );
99101 }
102+
103+ $ applicationDef ->addSetup ('setHelperSet ' , [$ helperSetDef ]);
100104 }
101105
102- foreach ($ config ->helpers as $ helperConfig ) {
103- if (Strings::startsWith ($ helperConfig , '@ ' )) {
104- // Add already defined service
105- $ applicationDef ->addSetup (new Statement ('?->getHelperSet()->set(?) ' , ['@self ' , $ helperConfig ]));
106- } else {
107- // Parse service definition
108- $ helperDef = $ builder ->addDefinition ($ this ->prefix ('helperSet ' ))
109- ->setFactory ($ helperConfig );
110- $ applicationDef ->addSetup (new Statement ('?->getHelperSet()->set(?) ' , ['@self ' , $ helperDef ]));
106+ foreach ($ config ->helpers as $ helperName => $ helperConfig ) {
107+ $ helperPrefix = $ this ->prefix ('helper. ' . $ helperName );
108+ $ helperDef = $ definitionsHelper ->getDefinitionFromConfig ($ helperConfig , $ helperPrefix );
109+
110+ if ($ helperDef instanceof Definition) {
111+ $ helperDef ->setAutowired (false );
111112 }
113+
114+ $ applicationDef ->addSetup ('?->getHelperSet()->set(?) ' , ['@self ' , $ helperDef ]);
112115 }
113116
114117 if ($ config ->lazy ) {
0 commit comments