1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
15
|
|
|
* |
16
|
|
|
* This software consists of voluntary contributions made by many individuals |
17
|
|
|
* and is licensed under the LGPL. For more information please see |
18
|
|
|
* <http://phing.info>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace Phing\Task\Ext; |
22
|
|
|
|
23
|
|
|
use Phing\Exception\BuildException; |
24
|
|
|
use Phing\Io\BufferedReader; |
25
|
|
|
use Phing\Io\File; |
26
|
|
|
use Phing\Io\FileReader; |
27
|
|
|
use Phing\Io\FileWriter; |
28
|
|
|
use Phing\Io\IOException; |
29
|
|
|
use Phing\Project; |
30
|
|
|
use Phing\Task; |
31
|
|
|
use Phing\Util\Properties; |
32
|
|
|
use Phing\Util\StringHelper; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* A phing task for generating output by using Smarty. |
36
|
|
|
* |
37
|
|
|
* This is based on the TexenTask from Apache's Velocity engine. This class |
38
|
|
|
* was originally proted in order to provide a template compiling system for |
39
|
|
|
* Torque. |
40
|
|
|
* |
41
|
|
|
* TODO: |
42
|
|
|
* - Add Path / useClasspath support? |
43
|
|
|
* |
44
|
|
|
* @author Hans Lellelid <[email protected]> (SmartyTask) |
45
|
|
|
* @author Jason van Zyl <[email protected]> (TexenTask) |
46
|
|
|
* @author Robert Burrell Donkin <[email protected]> |
47
|
|
|
* @package phing.tasks.ext |
48
|
|
|
*/ |
49
|
|
|
class SmartyTask extends Task |
50
|
|
|
{ |
51
|
|
|
/** |
52
|
|
|
* Smarty template engine. |
53
|
|
|
* |
54
|
|
|
* @var Smarty |
55
|
|
|
*/ |
56
|
|
|
protected $context; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Variables that are assigned to the context on parse/compile. |
60
|
|
|
* |
61
|
|
|
* @var array |
62
|
|
|
*/ |
63
|
|
|
protected $properties = []; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* This is the control template that governs the output. |
67
|
|
|
* It may or may not invoke the services of worker |
68
|
|
|
* templates. |
69
|
|
|
* |
70
|
|
|
* @var string |
71
|
|
|
*/ |
72
|
|
|
protected $controlTemplate; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* This is where Smarty will look for templates |
76
|
|
|
* using the file template loader. |
77
|
|
|
* |
78
|
|
|
* @var string |
79
|
|
|
*/ |
80
|
|
|
protected $templatePath; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* This is where texen will place all the output |
84
|
|
|
* that is a product of the generation process. |
85
|
|
|
* |
86
|
|
|
* @var string |
87
|
|
|
*/ |
88
|
|
|
protected $outputDirectory; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* This is the file where the generated text |
92
|
|
|
* will be placed. |
93
|
|
|
* |
94
|
|
|
* @var string |
95
|
|
|
*/ |
96
|
|
|
protected $outputFile; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* <p> |
100
|
|
|
* These are properties that are fed into the |
101
|
|
|
* initial context from a properties file. This |
102
|
|
|
* is simply a convenient way to set some values |
103
|
|
|
* that you wish to make available in the context. |
104
|
|
|
* </p> |
105
|
|
|
* <p> |
106
|
|
|
* These values are not critical, like the template path |
107
|
|
|
* or output path, but allow a convenient way to |
108
|
|
|
* set a value that may be specific to a particular |
109
|
|
|
* generation task. |
110
|
|
|
* </p> |
111
|
|
|
* <p> |
112
|
|
|
* For example, if you are generating scripts to allow |
113
|
|
|
* user to automatically create a database, then |
114
|
|
|
* you might want the <code>$databaseName</code> |
115
|
|
|
* to be placed |
116
|
|
|
* in the initial context so that it is available |
117
|
|
|
* in a script that might look something like the |
118
|
|
|
* following: |
119
|
|
|
* <code><pre> |
120
|
|
|
* #!bin/sh |
121
|
|
|
* |
122
|
|
|
* echo y | mysqladmin create $databaseName |
123
|
|
|
* </pre></code> |
124
|
|
|
* The value of <code>$databaseName</code> isn't critical to |
125
|
|
|
* output, and you obviously don't want to change |
126
|
|
|
* the ant task to simply take a database name. |
127
|
|
|
* So initial context values can be set with |
128
|
|
|
* properties file. |
129
|
|
|
* |
130
|
|
|
* @var array |
131
|
|
|
*/ |
132
|
|
|
protected $contextProperties; |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Smarty compiles templates before parsing / replacing tokens in them. |
136
|
|
|
* By default it will try ./templates_c, but you may wish to override this. |
137
|
|
|
* |
138
|
|
|
* @var string |
139
|
|
|
*/ |
140
|
|
|
protected $compilePath; |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Whether to force Smarty to recompile templates. |
144
|
|
|
* Smarty does check file modification time, but you can set this |
145
|
|
|
* to be *sure* that the template will be compiled (of course it will |
146
|
|
|
* be slower if you do). |
147
|
|
|
* |
148
|
|
|
* @var boolean |
149
|
|
|
*/ |
150
|
|
|
protected $forceCompile = false; |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Smarty can use config files. |
154
|
|
|
* This tells Smarty where to look for the config files. |
155
|
|
|
* |
156
|
|
|
* @var string |
157
|
|
|
*/ |
158
|
|
|
protected $configPath; |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Customize the left delimiter for Smarty tags. |
162
|
|
|
* |
163
|
|
|
* @var string |
164
|
|
|
*/ |
165
|
|
|
protected $leftDelimiter; |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Customize the right delimiter for Smarty tags. |
169
|
|
|
* |
170
|
|
|
* @var string |
171
|
|
|
*/ |
172
|
|
|
protected $rightDelimiter; |
173
|
|
|
|
174
|
|
|
// ----------------------------------------------------------------------- |
175
|
|
|
// The following getters & setters are used by phing to set properties |
176
|
|
|
// specified in the XML for the smarty task. |
177
|
|
|
// ----------------------------------------------------------------------- |
178
|
|
|
|
179
|
|
|
public function init() |
180
|
|
|
{ |
181
|
|
|
// This check returns true for smarty 3 and false otherwise. |
182
|
|
|
if (stream_resolve_include_path('SmartyBC.class.php')) { |
183
|
|
|
include_once 'SmartyBC.class.php'; |
184
|
|
|
} else { |
185
|
|
|
include_once 'Smarty.class.php'; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
if (!class_exists('Smarty')) { |
189
|
|
|
throw new BuildException("To use SmartyTask, you must have the path to Smarty.class.php on your include_path or your \$PHP_CLASSPATH environment variable."); |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* [REQUIRED] Set the control template for the |
195
|
|
|
* generating process. |
196
|
|
|
* |
197
|
|
|
* @param string $controlTemplate |
198
|
|
|
* @return void |
199
|
|
|
*/ |
200
|
|
|
public function setControlTemplate($controlTemplate) |
201
|
|
|
{ |
202
|
|
|
$this->controlTemplate = $controlTemplate; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Get the control template for the |
207
|
|
|
* generating process. |
208
|
|
|
* |
209
|
|
|
* @return string |
210
|
|
|
*/ |
211
|
|
|
public function getControlTemplate() |
212
|
|
|
{ |
213
|
|
|
return $this->controlTemplate; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* [REQUIRED] Set the path where Smarty will look |
218
|
|
|
* for templates using the file template |
219
|
|
|
* loader. |
220
|
|
|
* |
221
|
|
|
* @param $templatePath |
222
|
|
|
* @return void |
223
|
|
|
*/ |
224
|
|
|
public function setTemplatePath($templatePath) |
225
|
|
|
{ |
226
|
|
|
$resolvedPath = ""; |
227
|
|
|
$tok = strtok($templatePath, ","); |
228
|
|
|
while ($tok) { |
229
|
|
|
// resolve relative path from basedir and leave |
230
|
|
|
// absolute path untouched. |
231
|
|
|
$fullPath = $this->project->resolveFile($tok); |
232
|
|
|
$cpath = $fullPath->getCanonicalPath(); |
233
|
|
|
if ($cpath === false) { |
234
|
|
|
$this->log("Template directory does not exist: " . $fullPath->getAbsolutePath()); |
235
|
|
|
} else { |
236
|
|
|
$resolvedPath .= $cpath; |
237
|
|
|
} |
238
|
|
|
$tok = strtok(","); |
239
|
|
|
if ($tok) { |
240
|
|
|
$resolvedPath .= ","; |
241
|
|
|
} |
242
|
|
|
} |
243
|
|
|
$this->templatePath = $resolvedPath; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Get the path where Smarty will look |
248
|
|
|
* for templates using the file template |
249
|
|
|
* loader. |
250
|
|
|
* |
251
|
|
|
* @return string |
252
|
|
|
*/ |
253
|
|
|
public function getTemplatePath() |
254
|
|
|
{ |
255
|
|
|
return $this->templatePath; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* [REQUIRED] Set the output directory. It will be |
260
|
|
|
* created if it doesn't exist. |
261
|
|
|
* |
262
|
|
|
* @param IOException $outputDirectory |
263
|
|
|
* @return void |
264
|
|
|
* @throws \Exception |
265
|
|
|
*/ |
266
|
|
|
public function setOutputDirectory(IOException $outputDirectory) |
267
|
|
|
{ |
268
|
|
|
try { |
269
|
|
|
if (!$outputDirectory->exists()) { |
|
|
|
|
270
|
|
|
$this->log( |
271
|
|
|
"Output directory does not exist, creating: " . $outputDirectory->getPath(), |
|
|
|
|
272
|
|
|
Project::MSG_VERBOSE |
273
|
|
|
); |
274
|
|
|
if (!$outputDirectory->mkdirs()) { |
|
|
|
|
275
|
|
|
throw new IOException("Unable to create Ouptut directory: " . $outputDirectory->getAbsolutePath()); |
|
|
|
|
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
$this->outputDirectory = $outputDirectory->getCanonicalPath(); |
|
|
|
|
279
|
|
|
} catch (IOException $ioe) { |
280
|
|
|
throw new BuildException($ioe->getMessage()); |
281
|
|
|
} |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Get the output directory. |
286
|
|
|
* |
287
|
|
|
* @return string |
288
|
|
|
*/ |
289
|
|
|
public function getOutputDirectory() |
290
|
|
|
{ |
291
|
|
|
return $this->outputDirectory; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* [REQUIRED] Set the output file for the |
296
|
|
|
* generation process. |
297
|
|
|
* |
298
|
|
|
* @param $outputFile |
299
|
|
|
* @return void |
300
|
|
|
*/ |
301
|
|
|
public function setOutputFile($outputFile) |
302
|
|
|
{ |
303
|
|
|
$this->outputFile = $outputFile; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Get the output file for the |
308
|
|
|
* generation process. |
309
|
|
|
* |
310
|
|
|
* @return string |
311
|
|
|
*/ |
312
|
|
|
public function getOutputFile() |
313
|
|
|
{ |
314
|
|
|
return $this->outputFile; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* Set the path Smarty uses as a "cache" for compiled templates. |
319
|
|
|
* |
320
|
|
|
* @param string $compilePath |
321
|
|
|
*/ |
322
|
|
|
public function setCompilePath($compilePath) |
323
|
|
|
{ |
324
|
|
|
$this->compilePath = $compilePath; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* Get the path Smarty uses for compiling templates. |
329
|
|
|
* |
330
|
|
|
* @return string |
331
|
|
|
*/ |
332
|
|
|
public function getCompilePath() |
333
|
|
|
{ |
334
|
|
|
return $this->compilePath; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* Set whether Smarty should always recompile templates. |
339
|
|
|
* |
340
|
|
|
* @param boolean $force |
341
|
|
|
* @return void |
342
|
|
|
*/ |
343
|
|
|
public function setForceCompile($force) |
344
|
|
|
{ |
345
|
|
|
$this->forceCompile = (bool) $force; |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* Get whether Smarty should always recompile template. |
350
|
|
|
* |
351
|
|
|
* @return boolean |
352
|
|
|
*/ |
353
|
|
|
public function getForceCompile() |
354
|
|
|
{ |
355
|
|
|
return $this->forceCompile; |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* Set where Smarty looks for config files. |
360
|
|
|
* |
361
|
|
|
* @param string $configPath |
362
|
|
|
* @return void |
363
|
|
|
*/ |
364
|
|
|
public function setConfigPath($configPath) |
365
|
|
|
{ |
366
|
|
|
$this->configPath = $configPath; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* Get the path that Smarty uses for looking for config files. |
371
|
|
|
* |
372
|
|
|
* @return string |
373
|
|
|
*/ |
374
|
|
|
public function getConfigPath() |
375
|
|
|
{ |
376
|
|
|
return $this->configPath; |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
/** |
380
|
|
|
* Set Smarty template left delimiter. |
381
|
|
|
* |
382
|
|
|
* @param string $delim |
383
|
|
|
* @return void |
384
|
|
|
*/ |
385
|
|
|
public function setLeftDelimiter($delim) |
386
|
|
|
{ |
387
|
|
|
$this->leftDelimiter = $delim; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* Get Smarty template right delimiter |
392
|
|
|
* |
393
|
|
|
* @return string |
394
|
|
|
*/ |
395
|
|
|
public function getLeftDelimiter() |
396
|
|
|
{ |
397
|
|
|
return $this->leftDelimiter; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* Set Smarty template right delimiter. |
402
|
|
|
* |
403
|
|
|
* @param string $delim |
404
|
|
|
* @return void |
405
|
|
|
*/ |
406
|
|
|
public function setRightDelimiter($delim) |
407
|
|
|
{ |
408
|
|
|
$this->rightDelimiter = $delim; |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* Get Smarty template right delimiter |
413
|
|
|
* |
414
|
|
|
* @return string |
415
|
|
|
*/ |
416
|
|
|
public function getRightDelimiter() |
417
|
|
|
{ |
418
|
|
|
return $this->rightDelimiter; |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* Set the context properties that will be |
423
|
|
|
* fed into the initial context be the |
424
|
|
|
* generating process starts. |
425
|
|
|
* |
426
|
|
|
* @param string $file |
427
|
|
|
* @throws BuildException |
428
|
|
|
* @return void |
429
|
|
|
*/ |
430
|
|
|
public function setContextProperties($file) |
431
|
|
|
{ |
432
|
|
|
$sources = explode(",", $file); |
433
|
|
|
$this->contextProperties = new Properties(); |
|
|
|
|
434
|
|
|
|
435
|
|
|
// Always try to get the context properties resource |
436
|
|
|
// from a file first. Templates may be taken from a JAR |
437
|
|
|
// file but the context properties resource may be a |
438
|
|
|
// resource in the filesystem. If this fails than attempt |
439
|
|
|
// to get the context properties resource from the |
440
|
|
|
// classpath. |
441
|
|
|
for ($i = 0, $sourcesLength = count($sources); $i < $sourcesLength; $i++) { |
442
|
|
|
$source = new Properties(); |
443
|
|
|
|
444
|
|
|
try { |
445
|
|
|
// resolve relative path from basedir and leave |
446
|
|
|
// absolute path untouched. |
447
|
|
|
$fullPath = $this->project->resolveFile($sources[$i]); |
448
|
|
|
$this->log("Using contextProperties file: " . $fullPath->__toString()); |
449
|
|
|
$source->load($fullPath); |
450
|
|
|
} catch (\Exception $e) { |
451
|
|
|
throw new BuildException( |
452
|
|
|
"Context properties file " . $sources[$i] . |
453
|
|
|
" could not be found in the file system!" |
454
|
|
|
); |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
$keys = $source->keys(); |
458
|
|
|
|
459
|
|
|
foreach ($keys as $key) { |
460
|
|
|
$name = $key; |
461
|
|
|
$value = $this->project->replaceProperties($source->getProperty($name)); |
462
|
|
|
$this->contextProperties->setProperty($name, $value); |
463
|
|
|
} |
464
|
|
|
} |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
/** |
468
|
|
|
* Get the context properties that will be |
469
|
|
|
* fed into the initial context be the |
470
|
|
|
* generating process starts. |
471
|
|
|
* |
472
|
|
|
* @return \Properties |
|
|
|
|
473
|
|
|
*/ |
474
|
|
|
public function getContextProperties() |
475
|
|
|
{ |
476
|
|
|
return $this->contextProperties; |
|
|
|
|
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
// --------------------------------------------------------------- |
480
|
|
|
// End of XML setters & getters |
481
|
|
|
// --------------------------------------------------------------- |
482
|
|
|
|
483
|
|
|
/** |
484
|
|
|
* Creates a Smarty object. |
485
|
|
|
* |
486
|
|
|
* @return \Smarty initialized (cleared) Smarty context. |
487
|
|
|
* @throws \Exception the execute method will catch |
488
|
|
|
* and rethrow as a <code>BuildException</code> |
489
|
|
|
*/ |
490
|
|
|
public function initControlContext() |
491
|
|
|
{ |
492
|
|
|
$this->context->clear_all_assign(); |
493
|
|
|
|
494
|
|
|
return $this->context; |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* Execute the input script with Smarty |
499
|
|
|
* |
500
|
|
|
* @throws BuildException |
501
|
|
|
* BuildExceptions are thrown when required attributes are missing. |
502
|
|
|
* Exceptions thrown by Smarty are rethrown as BuildExceptions. |
503
|
|
|
*/ |
504
|
|
|
public function main() |
505
|
|
|
{ |
506
|
|
|
|
507
|
|
|
// Make sure the template path is set. |
508
|
|
|
if (empty($this->templatePath)) { |
509
|
|
|
throw new BuildException("The template path needs to be defined!"); |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
// Make sure the control template is set. |
513
|
|
|
if ($this->controlTemplate === null) { |
514
|
|
|
throw new BuildException("The control template needs to be defined!"); |
515
|
|
|
} |
516
|
|
|
|
517
|
|
|
// Make sure the output directory is set. |
518
|
|
|
if ($this->outputDirectory === null) { |
519
|
|
|
throw new BuildException("The output directory needs to be defined!"); |
520
|
|
|
} |
521
|
|
|
|
522
|
|
|
// Make sure there is an output file. |
523
|
|
|
if ($this->outputFile === null) { |
524
|
|
|
throw new BuildException("The output file needs to be defined!"); |
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
// Setup Smarty runtime. |
528
|
|
|
|
529
|
|
|
// Smarty uses one object to store properties and to store |
530
|
|
|
// the context for the template (unlike Smarty). We setup this object, calling it |
531
|
|
|
// $this->context, and then initControlContext simply zeros out |
532
|
|
|
// any assigned variables. |
533
|
|
|
// |
534
|
|
|
// Use the smarty backwards compatibility layer if existent. |
535
|
|
|
if (class_exists('SmartyBC')) { |
536
|
|
|
$this->context = new \SmartyBC(); |
|
|
|
|
537
|
|
|
} else { |
538
|
|
|
$this->context = new \Smarty(); |
539
|
|
|
} |
540
|
|
|
|
541
|
|
|
if ($this->compilePath !== null) { |
542
|
|
|
$this->log("Using compilePath: " . $this->compilePath); |
543
|
|
|
$this->context->compile_dir = $this->compilePath; |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
if ($this->configPath !== null) { |
547
|
|
|
$this->log("Using configPath: " . $this->configPath); |
548
|
|
|
$this->context->config_dir = $this->configPath; |
|
|
|
|
549
|
|
|
} |
550
|
|
|
|
551
|
|
|
if ($this->forceCompile !== null) { |
552
|
|
|
$this->context->force_compile = $this->forceCompile; |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
if ($this->leftDelimiter !== null) { |
556
|
|
|
$this->context->left_delimiter = $this->leftDelimiter; |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
if ($this->rightDelimiter !== null) { |
560
|
|
|
$this->context->right_delimiter = $this->rightDelimiter; |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
if ($this->templatePath !== null) { |
564
|
|
|
$this->log("Using templatePath: " . $this->templatePath); |
565
|
|
|
$this->context->template_dir = $this->templatePath; |
|
|
|
|
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
$smartyCompilePath = new IOException($this->context->compile_dir); |
569
|
|
|
if (!$smartyCompilePath->exists()) { |
570
|
|
|
$this->log( |
571
|
|
|
"Compile directory does not exist, creating: " . $smartyCompilePath->getPath(), |
572
|
|
|
Project::MSG_VERBOSE |
573
|
|
|
); |
574
|
|
|
if (!$smartyCompilePath->mkdirs()) { |
575
|
|
|
throw new BuildException("Smarty needs a place to compile templates; specify a 'compilePath' or create " . $this->context->compile_dir); |
576
|
|
|
} |
577
|
|
|
} |
578
|
|
|
|
579
|
|
|
// Make sure the output directory exists, if it doesn't |
580
|
|
|
// then create it. |
581
|
|
|
$file = new IOException($this->outputDirectory); |
582
|
|
|
if (!$file->exists()) { |
583
|
|
|
$this->log("Output directory does not exist, creating: " . $file->getAbsolutePath()); |
584
|
|
|
$file->mkdirs(); |
585
|
|
|
} |
586
|
|
|
|
587
|
|
|
$path = $this->outputDirectory . DIRECTORY_SEPARATOR . $this->outputFile; |
588
|
|
|
$this->log("Generating to file " . $path); |
589
|
|
|
|
590
|
|
|
$writer = new FileWriter($path); |
591
|
|
|
|
592
|
|
|
// The generator and the output path should |
593
|
|
|
// be placed in the init context here and |
594
|
|
|
// not in the generator class itself. |
595
|
|
|
$c = $this->initControlContext(); |
596
|
|
|
|
597
|
|
|
// Set any variables that need to always |
598
|
|
|
// be loaded |
599
|
|
|
$this->populateInitialContext($c); |
600
|
|
|
|
601
|
|
|
// Feed all the options into the initial |
602
|
|
|
// control context so they are available |
603
|
|
|
// in the control/worker templates. |
604
|
|
|
if ($this->contextProperties !== null) { |
605
|
|
|
foreach ($this->contextProperties->keys() as $property) { |
606
|
|
|
$value = $this->contextProperties->getProperty($property); |
607
|
|
|
|
608
|
|
|
// Special exception (from Texen) |
609
|
|
|
// for properties ending in file.contents: |
610
|
|
|
// in that case we dump the contents of the file |
611
|
|
|
// as the "value" for the Property. |
612
|
|
|
if (StringHelper::endsWith("file.contents", $property)) { |
613
|
|
|
// pull in contents of file specified |
614
|
|
|
|
615
|
|
|
$property = substr($property, 0, strpos($property, "file.contents") - 1); |
616
|
|
|
|
617
|
|
|
// reset value, and then |
618
|
|
|
// read in the contents of the file into that var |
619
|
|
|
$value = ""; |
620
|
|
|
$f = new File($this->project->resolveFile($value)->getCanonicalPath()); |
621
|
|
|
if ($f->exists()) { |
622
|
|
|
try { |
623
|
|
|
$br = new BufferedReader(new FileReader($f)); |
624
|
|
|
$value = $br->read(); |
625
|
|
|
} catch (\Exception $e) { |
626
|
|
|
throw $e; |
627
|
|
|
} |
628
|
|
|
} |
629
|
|
|
} // if ends with file.contents |
630
|
|
|
|
631
|
|
|
if (StringHelper::isBoolean($value)) { |
632
|
|
|
$value = StringHelper::booleanValue($value); |
633
|
|
|
} |
634
|
|
|
|
635
|
|
|
$c->assign($property, $value); |
636
|
|
|
} // foreach property |
637
|
|
|
} // if contextProperties !== null |
638
|
|
|
|
639
|
|
|
try { |
640
|
|
|
//$c->display($this->controlTemplate); |
641
|
|
|
$writer->write($c->fetch($this->controlTemplate)); |
642
|
|
|
$writer->close(); |
643
|
|
|
} catch (IOException $ioe) { |
644
|
|
|
$writer->close(); |
645
|
|
|
throw new BuildException("Cannot write parsed template."); |
646
|
|
|
} |
647
|
|
|
|
648
|
|
|
$this->cleanup(); |
649
|
|
|
} |
650
|
|
|
|
651
|
|
|
/** |
652
|
|
|
* <p>Place useful objects into the initial context.</p> |
653
|
|
|
* |
654
|
|
|
* <p>TexenTask places <code>Date().toString()</code> into the |
655
|
|
|
* context as <code>$now</code>. Subclasses who want to vary the |
656
|
|
|
* objects in the context should override this method.</p> |
657
|
|
|
* |
658
|
|
|
* <p><code>$generator</code> is not put into the context in this |
659
|
|
|
* method.</p> |
660
|
|
|
* |
661
|
|
|
* @param \Smarty $context context to populate, as retrieved from |
662
|
|
|
* {@link #initControlContext()}. |
663
|
|
|
* @return void |
664
|
|
|
*/ |
665
|
|
|
protected function populateInitialContext(\Smarty $context) |
|
|
|
|
666
|
|
|
{ |
667
|
|
|
} |
668
|
|
|
|
669
|
|
|
/** |
670
|
|
|
* A hook method called at the end of {@link #execute()} which can |
671
|
|
|
* be overridden to perform any necessary cleanup activities (such |
672
|
|
|
* as the release of database connections, etc.). By default, |
673
|
|
|
* does nothing. |
674
|
|
|
* |
675
|
|
|
* @return void |
676
|
|
|
* @throws \Exception Problem cleaning up. |
677
|
|
|
*/ |
678
|
|
|
protected function cleanup() |
679
|
|
|
{ |
680
|
|
|
} |
681
|
|
|
} |
682
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.