@@ -49,13 +49,14 @@ public function __construct(Configuration $configuration) {
4949 $ this ->config = $ configuration ;
5050 $ this ->client = new Client ($ configuration );
5151
52- $ twigLoader = new \Twig_Loader_Filesystem (__DIR__ . '/../templates ' );
53- $ this ->twig = new \Twig_Environment ($ twigLoader , ['debug ' => true , 'strict_variables ' => true , 'autoescape ' => false ]);
52+ $ twigLoader = new \Twig_Loader_Filesystem (__DIR__ .'/../templates ' );
53+ $ this ->twig =
54+ new \Twig_Environment ($ twigLoader , ['debug ' => true , 'strict_variables ' => true , 'autoescape ' => false ]);
5455 $ this ->twig ->addExtension (new \Twig_Extensions_Extension_Text ());
5556 $ this ->twig ->addFilter (
5657 new \Twig_Filter (
5758 'ucfirst ' ,
58- function ($ in ) {
59+ function ($ in ) {
5960 return ucfirst ($ in );
6061 },
6162 ['is_safe ' => ['html ' ]]
@@ -83,7 +84,7 @@ function ($in) {
8384 }
8485
8586 $ this ->requestDir = sprintf ('%s/CloudStackRequest ' , $ this ->srcDir );
86- if (!is_dir ($ this ->requestDir )&& !mkdir ($ this ->requestDir )) {
87+ if (!is_dir ($ this ->requestDir ) && !mkdir ($ this ->requestDir )) {
8788 throw new \RuntimeException (sprintf ('Unable to create directory "%s" ' , $ this ->requestDir ));
8889 }
8990 }
@@ -92,88 +93,106 @@ function ($in) {
9293 * Execute generation of CloudStack API client
9394 */
9495 public function generate () {
96+ $ log = $ this ->config ->getLogger ();
97+
98+ $ log ->info ("Compiling APIs from {$ this ->config ->getHost ()}... " );
9599 $ this ->compileAPIs ();
96100 ksort ($ this ->apis , SORT_NATURAL );
97101
102+ $ log ->info ('Writing static templates... ' );
98103 $ this ->writeOutStaticTemplates ();
104+ $ log ->info ('Writing Client class... ' );
99105 $ this ->writeOutClient ();
100106
107+ $ log ->info ('Writing Request Models... ' );
101108 $ this ->writeOutRequestModels ();
109+ $ log ->info ('Writing Shared Response Models... ' );
102110 $ this ->writeOutSharedResponseModels ();
111+ $ log ->info ('Writing Response Models... ' );
103112 $ this ->writeOutResponseModels ();
104113 }
105114
115+ /**
116+ * @param string $file
117+ * @param string $data
118+ * @return bool|int
119+ */
120+ protected function writeFile (string $ file , string $ data ) {
121+ $ this ->config ->getLogger ()->debug ('Writing ' .mb_strlen ($ data ).' bytes to ' .$ file );
122+ return file_put_contents ($ file , $ data );
123+ }
124+
106125 protected function writeOutStaticTemplates () {
107126 $ args = ['config ' => $ this ->config , 'capabilities ' => $ this ->getCapabilities ()];
108127
109- file_put_contents (
110- $ this ->config ->getOutputDir () . '/LICENSE ' ,
111- file_get_contents (__DIR__ . '/../LICENSE ' )
128+ $ this -> writeFile (
129+ $ this ->config ->getOutputDir (). '/LICENSE ' ,
130+ file_get_contents (__DIR__ . '/../LICENSE ' )
112131 );
113132
114- file_put_contents (
115- $ this ->config ->getOutputDir () . '/composer.json ' ,
133+ $ this -> writeFile (
134+ $ this ->config ->getOutputDir (). '/composer.json ' ,
116135 $ this ->twig ->load ('composer.json.twig ' )->render ($ args )
117136 );
118137
119- file_put_contents (
120- $ this ->srcDir . '/CloudStackConfiguration.php ' ,
138+ $ this -> writeFile (
139+ $ this ->srcDir . '/CloudStackConfiguration.php ' ,
121140 $ this ->twig ->load ('configuration.php.twig ' )->render ($ args )
122141 );
123142
124- file_put_contents (
125- $ this ->filesDir . '/constants.php ' ,
143+ $ this -> writeFile (
144+ $ this ->filesDir . '/constants.php ' ,
126145 $ this ->twig ->load ('constants.php.twig ' )->render ($ args )
127146 );
128147
129- file_put_contents (
148+ $ this -> writeFile (
130149 $ this ->srcDir .'/CloudStackEventTypes.php ' ,
131150 $ this ->twig ->load ('eventTypes.php.twig ' )->render ($ args )
132151 );
133152
134- file_put_contents (
135- $ this ->responseDir . '/AsyncJobStartResponse.php ' ,
153+ $ this -> writeFile (
154+ $ this ->responseDir . '/AsyncJobStartResponse.php ' ,
136155 $ this ->twig ->load ('responses/asyncJobStart.php.twig ' )->render ($ args )
137156 );
138157
139- file_put_contents (
140- $ this ->responseDir . '/AccessVmConsoleProxyResponse.php ' ,
158+ $ this -> writeFile (
159+ $ this ->responseDir . '/AccessVmConsoleProxyResponse.php ' ,
141160 $ this ->twig ->load ('responses/accessVmConsoleProxy.php.twig ' )->render ($ args )
142161 );
143162
144- file_put_contents (
145- $ this ->responseTypesDir . '/DateType.php ' ,
163+ $ this -> writeFile (
164+ $ this ->responseTypesDir . '/DateType.php ' ,
146165 $ this ->twig ->load ('responses/dateType.php.twig ' )->render ($ args )
147166 );
148167
149- file_put_contents (
150- $ this ->srcDir . '/CloudStackHelpers.php ' ,
168+ $ this -> writeFile (
169+ $ this ->srcDir . '/CloudStackHelpers.php ' ,
151170 $ this ->twig ->load ('helpers.php.twig ' )->render ($ args )
152171 );
153172
154- file_put_contents (
173+ $ this -> writeFile (
155174 $ this ->requestDir .'/CloudStackRequestInterfaces.php ' ,
156175 $ this ->twig ->load ('requests/interfaces.php.twig ' )->render ($ args )
157176 );
158177
159- file_put_contents (
178+ $ this -> writeFile (
160179 $ this ->requestDir .'/AccessVmConsoleProxyRequest.php ' ,
161180 $ this ->twig ->load ('requests/accessVmConsoleProxy.php.twig ' )->render ($ args )
162181 );
163182
164- file_put_contents (
183+ $ this -> writeFile (
165184 $ this ->srcDir .'/CloudStackExceptions.php ' ,
166185 $ this ->twig ->load ('exceptions.php.twig ' )->render ($ args )
167186 );
168187 }
169188
170189 protected function writeOutClient () {
171- file_put_contents (
172- $ this ->srcDir . '/CloudStackClient.php ' ,
190+ $ this -> writeFile (
191+ $ this ->srcDir . '/CloudStackClient.php ' ,
173192 $ this ->twig ->load ('client.php.twig ' )->render ([
174- 'config ' => $ this ->config ,
193+ 'config ' => $ this ->config ,
175194 'capabilities ' => $ this ->getCapabilities (),
176- 'apis ' => $ this ->apis ,
195+ 'apis ' => $ this ->apis ,
177196 ])
178197 );
179198 }
@@ -182,13 +201,13 @@ protected function writeOutRequestModels() {
182201 $ capabilities = $ this ->getCapabilities ();
183202 $ template = $ this ->twig ->load ('requests/model.php.twig ' );
184203
185- foreach ($ this ->apis as $ api ) {
204+ foreach ($ this ->apis as $ api ) {
186205 $ className = $ api ->getRequestClassName ();
187- file_put_contents (
188- $ this ->requestDir . '/ ' .$ className . '.php ' ,
206+ $ this -> writeFile (
207+ $ this ->requestDir . '/ ' .$ className. '.php ' ,
189208 $ template ->render ([
190- 'api ' => $ api ,
191- 'config ' => $ this ->config ,
209+ 'api ' => $ api ,
210+ 'config ' => $ this ->config ,
192211 'capabilities ' => $ capabilities ,
193212 ])
194213 );
@@ -201,13 +220,12 @@ protected function writeOutSharedResponseModels() {
201220
202221 foreach ($ this ->sharedObjectMap as $ name => $ class ) {
203222 $ class ->getProperties ()->nameSort ();
204-
205223 $ className = $ class ->getClassName ();
206- file_put_contents (
207- $ this ->responseDir . '/ ' . $ className . '.php ' ,
224+ $ this -> writeFile (
225+ $ this ->responseDir . '/ ' . $ className. '.php ' ,
208226 $ template ->render ([
209- 'obj ' => $ class ,
210- 'config ' => $ this ->config ,
227+ 'obj ' => $ class ,
228+ 'config ' => $ this ->config ,
211229 'capabilities ' => $ capabilities ,
212230 ])
213231 );
@@ -222,11 +240,11 @@ protected function writeOutResponseModels() {
222240 $ response = $ api ->getResponse ();
223241 $ className = $ response ->getClassName ();
224242
225- file_put_contents (
226- $ this ->responseDir . '/ ' . $ className . '.php ' ,
243+ $ this -> writeFile (
244+ $ this ->responseDir . '/ ' . $ className. '.php ' ,
227245 $ template ->render ([
228- 'obj ' => $ response ,
229- 'config ' => $ this ->config ,
246+ 'obj ' => $ response ,
247+ 'config ' => $ this ->config ,
230248 'capabilities ' => $ capabilities ,
231249 ])
232250 );
0 commit comments