@@ -66,100 +66,112 @@ public function __invoke(Container $container, DirectoriesInterface $dirs): int
66
66
->withOutputPath ($ this ->workDir )
67
67
->withEnvFile ($ this ->envFileName );
68
68
69
+ $ container ->getBinder ('root ' )->bind (
70
+ DirectoriesInterface::class,
71
+ $ dirs ,
72
+ );
73
+
69
74
return $ container ->runScope (
70
75
bindings: new Scope (
71
- name: AppScope::Compiler,
72
76
bindings: [
73
77
DirectoriesInterface::class => $ dirs ,
74
78
],
75
79
),
76
- scope: function (
77
- DocumentCompiler $ compiler ,
78
- ConfigurationProvider $ configProvider ,
79
- ): int {
80
- try {
81
- // Get the appropriate loader based on options provided
82
- if ( $ this -> inlineJson !== null ) {
83
- $ this -> logger -> info ( ' Using inline JSON configuration... ' );
84
- $ loader = $ configProvider -> fromString ( $ this -> inlineJson );
85
- } elseif ( $ this -> configPath !== null ) {
86
- $ this -> logger -> info ( \sprintf ( ' Loading configuration from %s... ' , $ this -> configPath ));
87
- $ loader = $ configProvider -> fromPath ( $ this -> configPath );
88
- } else {
89
- $ this ->logger -> info ( ' Loading configuration from default location... ' );
90
- $ loader = $ configProvider -> fromDefaultLocation ( );
91
- }
92
- } catch ( ConfigLoaderException $ e ) {
93
- $ this ->logger ->error ( ' Failed to load configuration ' , [
94
- ' error ' => $ e -> getMessage (),
95
- ]);
96
-
97
- if ( $ this -> asJson ) {
98
- $ this -> output -> writeln ( \json_encode ([
99
- ' status ' => ' error ' ,
100
- ' message ' => 'Failed to load configuration ' ,
80
+ scope: fn ( Container $ container ): int => $ container -> runScope (
81
+ bindings: new Scope (
82
+ name: AppScope::Compiler ,
83
+ bindings: [
84
+ DirectoriesInterface::class => $ dirs ,
85
+ ],
86
+ ),
87
+ scope: function (
88
+ DocumentCompiler $ compiler ,
89
+ ConfigurationProvider $ configProvider ,
90
+ ): int {
91
+ try {
92
+ // Get the appropriate loader based on options provided
93
+ if ( $ this ->inlineJson !== null ) {
94
+ $ this -> logger -> info ( ' Using inline JSON configuration... ' );
95
+ $ loader = $ configProvider -> fromString ( $ this -> inlineJson );
96
+ } elseif ( $ this -> configPath !== null ) {
97
+ $ this ->logger ->info ( \sprintf ( ' Loading configuration from %s... ' , $ this -> configPath ));
98
+ $ loader = $ configProvider -> fromPath ( $ this -> configPath );
99
+ } else {
100
+ $ this -> logger -> info ( ' Loading configuration from default location... ' );
101
+ $ loader = $ configProvider -> fromDefaultLocation ();
102
+ }
103
+ } catch ( ConfigLoaderException $ e ) {
104
+ $ this -> logger -> error ( 'Failed to load configuration ' , [
101
105
'error ' => $ e ->getMessage (),
102
- ]));
103
- } else {
104
- $ this ->output ->error (\sprintf ('Failed to load configuration: %s ' , $ e ->getMessage ()));
106
+ ]);
107
+
108
+ if ($ this ->asJson ) {
109
+ $ this ->output ->writeln (\json_encode ([
110
+ 'status ' => 'error ' ,
111
+ 'message ' => 'Failed to load configuration ' ,
112
+ 'error ' => $ e ->getMessage (),
113
+ ]));
114
+ } else {
115
+ $ this ->output ->error (\sprintf ('Failed to load configuration: %s ' , $ e ->getMessage ()));
116
+ }
117
+
118
+ return Command::FAILURE ;
105
119
}
106
120
107
- return Command::FAILURE ;
108
- }
121
+ // Create the renderer for consistent output formatting
122
+ $ renderer = new GenerateCommandRenderer ($ this ->output );
123
+
124
+ // Display summary header
125
+ $ this ->output ->writeln ('' );
109
126
110
- // Create the renderer for consistent output formatting
111
- $ renderer = new GenerateCommandRenderer ($ this ->output );
127
+ $ config = new ConfigRegistryAccessor ($ loader ->load ());
112
128
113
- // Display summary header
114
- $ this ->output ->writeln ('' );
129
+ $ imports = $ config ->getImports ();
130
+ if ($ imports !== null ) {
131
+ $ renderer ->renderImports ($ imports );
132
+ }
115
133
116
- $ config = new ConfigRegistryAccessor ($ loader ->load ());
134
+ if ($ config ->getDocuments () === null || $ config ->getDocuments ()->getItems () === []) {
135
+ if ($ this ->asJson ) {
136
+ $ this ->output ->writeln (\json_encode ([
137
+ 'status ' => 'success ' ,
138
+ 'message ' => 'No documents found in configuration. ' ,
139
+ ]));
140
+ } else {
141
+ $ this ->output ->warning ('No documents found in configuration. ' );
142
+ }
143
+ return Command::SUCCESS ;
144
+ }
117
145
118
- $ imports = $ config ->getImports ();
119
- if ($ imports !== null ) {
120
- $ renderer ->renderImports ($ imports );
121
- }
146
+ $ result = [];
147
+
148
+ foreach ($ config ->getDocuments () as $ document ) {
149
+ $ this ->logger ->info (\sprintf ('Compiling %s... ' , $ document ->description ));
150
+
151
+ $ compiledDocument = $ compiler ->compile ($ document );
152
+ if (!$ this ->asJson ) {
153
+ $ renderer ->renderCompilationResult ($ document , $ compiledDocument );
154
+ } else {
155
+ $ result [] = [
156
+ 'output_path ' => $ compiledDocument ->outputPath ,
157
+ 'context_path ' => $ compiledDocument ->contextPath ,
158
+ ];
159
+ }
160
+ }
122
161
123
- if ($ config ->getDocuments () === null || $ config ->getDocuments ()->getItems () === []) {
124
162
if ($ this ->asJson ) {
125
163
$ this ->output ->writeln (\json_encode ([
126
164
'status ' => 'success ' ,
127
- 'message ' => 'No documents found in configuration. ' ,
165
+ 'message ' => 'Documents compiled successfully ' ,
166
+ 'result ' => $ result ,
128
167
]));
129
168
} else {
130
- $ this ->output ->warning ('No documents found in configuration. ' );
131
- }
132
- return Command::SUCCESS ;
133
- }
134
-
135
- $ result = [];
136
-
137
- foreach ($ config ->getDocuments () as $ document ) {
138
- $ this ->logger ->info (\sprintf ('Compiling %s... ' , $ document ->description ));
139
-
140
- $ compiledDocument = $ compiler ->compile ($ document );
141
- if (!$ this ->asJson ) {
142
- $ renderer ->renderCompilationResult ($ document , $ compiledDocument );
143
- } else {
144
- $ result [] = [
145
- 'output_path ' => $ compiledDocument ->outputPath ,
146
- 'context_path ' => $ compiledDocument ->contextPath ,
147
- ];
169
+ $ this ->output ->writeln ('' );
148
170
}
149
- }
150
-
151
- if ($ this ->asJson ) {
152
- $ this ->output ->writeln (\json_encode ([
153
- 'status ' => 'success ' ,
154
- 'message ' => 'Documents compiled successfully ' ,
155
- 'result ' => $ result ,
156
- ]));
157
- } else {
158
- $ this ->output ->writeln ('' );
159
- }
160
171
161
- return Command::SUCCESS ;
162
- },
172
+ return Command::SUCCESS ;
173
+ },
174
+ ),
163
175
);
164
176
}
165
177
}
0 commit comments