Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * $Id: IoncubeEncoderTask.php 325 2007-12-20 15:44:58Z hans $
4
 *
5
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
 *
17
 * This software consists of voluntary contributions made by many individuals
18
 * and is licensed under the LGPL. For more information please see
19
 * <http://phing.info>.
20
 */
21
 
22
require_once 'phing/Task.php';
23
require_once 'phing/tasks/ext/ioncube/IoncubeComment.php';
24
 
25
/**
26
 * Invokes the ionCube Encoder (PHP4 or PHP5)
27
 *
28
 * @author Michiel Rook <michiel.rook@gmail.com>
29
 * @author Andrew Eddie <andrew.eddie@jamboworks.com>
30
 * @version $Id: IoncubeEncoderTask.php 325 2007-12-20 15:44:58Z hans $
31
 * @package phing.tasks.ext.ioncube
32
 * @since 2.2.0
33
 */
34
class IoncubeEncoderTask extends Task
35
{
36
	private $ionSwitches = array();
37
 
38
	private $ionOptions = array();
39
 
40
	private $ionOptionsXS = array();
41
 
42
	private $comments = array();
43
 
44
	private $encoderName = 'ioncube_encoder';
45
 
46
	private $fromDir = '';
47
 
48
	private $ioncubePath = '/usr/local/ioncube';
49
 
50
	private $phpVersion = '5';
51
 
52
	private $targetOption = '';
53
 
54
	private $toDir = '';
55
 
56
	/**
57
	 * Adds a comment to be used in encoded files
58
	 */
59
	function addComment(IoncubeComment $comment)
60
	{
61
		$this->comments[] = $comment;
62
	}
63
 
64
	/**
65
	 * Sets the allowed server
66
	 */
67
	function setAllowedServer($value)
68
	{
69
		$this->ionOptionsXS['allowed-server'] = $value;
70
	}
71
 
72
	/**
73
	 * Returns the allowed server setting
74
	 */
75
	function getAllowedServer()
76
	{
77
		return $this->ionOptionsXS['allowed-server'];
78
	}
79
 
80
	/**
81
	 * Sets the binary option
82
	 */
83
	function setBinary($value)
84
	{
85
		$this->ionSwitches['binary'] = $value;
86
	}
87
 
88
	/**
89
	 * Returns the binary option
90
	 */
91
	function getBinary()
92
	{
93
		return $this->ionSwitches['binary'];
94
	}
95
 
96
	/**
97
	 * Sets files or folders to copy (separated by space)
98
	 */
99
	function setCopy($value)
100
	{
101
		$this->ionOptionsXS['copy'] = $value;
102
	}
103
 
104
	/**
105
	 * Returns the copy setting
106
	 */
107
	function getCopy()
108
	{
109
		return $this->ionOptionsXS['copy'];
110
	}
111
 
112
	/**
113
	 * Sets additional file patterns, files or directories to encode,
114
	 * or to reverse the effect of copy (separated by space)
115
	 */
116
	function setEncode($value)
117
	{
118
		$this->ionOptionsXS['encode'] = $value;
119
	}
120
 
121
	/**
122
	 * Returns the encode setting
123
	 */
124
	function getEncode()
125
	{
126
		return $this->enionOptionsXS['encode'];
127
	}
128
 
129
	/**
130
	 * Sets regexps of additional files to encrypt (separated by space)
131
	 */
132
	function setEncrypt($value)
133
	{
134
		$this->ionOptionsXS['encrypt'] = $value;
135
	}
136
 
137
	/**
138
	 * Returns regexps of additional files to encrypt (separated by space)
139
	 */
140
	function getEncrypt()
141
	{
142
		return $this->ionOptionsXS['encrypt'];
143
	}
144
 
145
	/**
146
	 * Sets a period after which the files expire
147
	 */
148
	function setExpirein($value)
149
	{
150
		$this->ionOptions['expire-in'] = $value;
151
	}
152
 
153
	/**
154
	 * Returns the expireIn setting
155
	 */
156
	function getExpirein()
157
	{
158
		return $this->ionOptions['expire-in'];
159
	}
160
 
161
	/**
162
	 * Sets a YYYY-MM-DD date to expire the files
163
	 */
164
	function setExpireon($value)
165
	{
166
		$this->ionOptions['expire-on'] = $value;
167
	}
168
 
169
	/**
170
	 * Returns the expireOn setting
171
	 */
172
	function getExpireon()
173
	{
174
		return $this->ionOptions['expire-on'];
175
	}
176
 
177
	/**
178
	 * Sets the source directory
179
	 */
180
	function setFromDir($value)
181
	{
182
		$this->fromDir = $value;
183
	}
184
 
185
	/**
186
	 * Returns the source directory
187
	 */
188
	function getFromDir()
189
	{
190
		return $this->fromDir;
191
	}
192
 
193
	/**
194
	 * Set files and directories to ignore entirely and exclude from the target directory
195
	 * (separated by space).
196
	 */
197
	function setIgnore($value)
198
	{
199
		$this->ionOptionsXS['ignore'] = $value;
200
	}
201
 
202
	/**
203
	 * Returns the ignore setting
204
	 */
205
	function getIgnore()
206
	{
207
		return $this->ionOptionsXS['ignore'];
208
	}
209
 
210
	/**
211
	 * Sets the path to the ionCube encoder
212
	 */
213
	function setIoncubePath($value)
214
	{
215
		$this->ioncubePath = $value;
216
	}
217
 
218
	/**
219
	 * Returns the path to the ionCube encoder
220
	 */
221
	function getIoncubePath()
222
	{
223
		return $this->ioncubePath;
224
	}
225
 
226
	/**
227
	 * Set files and directories not to be ignored (separated by space).
228
	 */
229
	function setKeep($value)
230
	{
231
		$this->ionOptionsXS['keep'] = $value;
232
	}
233
 
234
	/**
235
	 * Returns the ignore setting
236
	 */
237
	function getKeep()
238
	{
239
		return $this->ionOptionsXS['keep'];
240
	}
241
 
242
	/**
243
	 * Sets the path to the license file to use
244
	 */
245
	function setLicensePath($value)
246
	{
247
		$this->ionOptions['with-license'] = $value;
248
	}
249
 
250
	/**
251
	 * Returns the path to the license file to use
252
	 */
253
	function getLicensePath()
254
	{
255
		return $this->ionOptions['with-license'];
256
	}
257
 
258
	/**
259
	 * Sets the no-doc-comments option
260
	 */
261
	function setNoDocComments($value)
262
	{
263
		$this->ionSwitches['no-doc-comment'] = $value;
264
	}
265
 
266
	/**
267
	 * Returns the no-doc-comments option
268
	 */
269
	function getNoDocComments()
270
	{
271
		return $this->ionSwitches['no-doc-comment'];
272
	}
273
 
274
	/**
275
	 * Sets the obfuscate option
276
	 */
277
	function setObfuscate($value)
278
	{
279
		$this->ionOptionsXS['obfuscate'] = $value;
280
	}
281
 
282
	/**
283
	 * Returns the optimize option
284
	 */
285
	function getObfuscate()
286
	{
287
		return $this->ionOptionsXS['obfuscate'];
288
	}
289
 
290
	/**
291
	 * Sets the obfuscation key (required if using the obfuscate option)
292
	 */
293
	function setObfuscationKey($value)
294
	{
295
		$this->ionOptions['obfuscation-key'] = $value;
296
	}
297
 
298
	/**
299
	 * Returns the optimize option
300
	 */
301
	function getObfuscationKey()
302
	{
303
		return $this->ionOptions['obfuscation-key'];
304
	}
305
 
306
	/**
307
	 * Sets the optimize option
308
	 */
309
	function setOptimize($value)
310
	{
311
		$this->ionOptions['optimize'] = $value;
312
	}
313
 
314
	/**
315
	 * Returns the optimize option
316
	 */
317
	function getOptimize()
318
	{
319
		return $this->ionOptions['optimize'];
320
	}
321
 
322
	/**
323
	 * Sets the passphrase to use when encoding files
324
	 */
325
	function setPassPhrase($value)
326
	{
327
		$this->ionOptions['passphrase'] = $value;
328
	}
329
 
330
	/**
331
	 * Returns the passphrase to use when encoding files
332
	 */
333
	function getPassPhrase()
334
	{
335
		return $this->ionOptions['passphrase'];
336
	}
337
 
338
	/**
339
	 * Sets the version of PHP to use (defaults to 5)
340
	 */
341
	function setPhpVersion($value)
342
	{
343
		$this->phpVersion = $value;
344
	}
345
 
346
	/**
347
	 * Returns the version of PHP to use (defaults to 5)
348
	 */
349
	function getPhpVersion()
350
	{
351
		return $this->phpVersion;
352
	}
353
 
354
	/**
355
	 * Sets the target directory
356
	 */
357
	function setToDir($value)
358
	{
359
		$this->toDir = $value;
360
	}
361
 
362
	/**
363
	 * Returns the target directory
364
	 */
365
	function getToDir()
366
	{
367
		return $this->toDir;
368
	}
369
 
370
	/**
371
	 * Sets the without-runtime-loader-support option
372
	 */
373
	function setWithoutRuntimeLoaderSupport($value)
374
	{
375
		$this->ionSwitches['without-runtime-loader-support'] = $value;
376
	}
377
 
378
	/**
379
	 * Returns the without-runtime-loader-support option
380
	 */
381
	function getWithoutRuntimeLoaderSupport()
382
	{
383
		return $this->ionSwitches['without-runtime-loader-support'];
384
	}
385
 
386
	/**
387
	 * Sets the option to use when encoding target directory already exists (defaults to none)
388
	 */
389
	function setTargetOption($targetOption)
390
	{
391
		$this->targetOption = $targetOption;
392
	}
393
 
394
	/**
395
	 * Returns he option to use when encoding target directory already exists (defaults to none)
396
	 */
397
	function getTargetOption()
398
	{
399
		return $this->targetOption;
400
	}
401
 
402
	/**
403
	 * The main entry point
404
	 *
405
	 * @throws BuildException
406
	 */
407
	function main()
408
	{
409
		$arguments = $this->constructArguments();
410
 
411
		$encoder = new PhingFile($this->ioncubePath, $this->encoderName . ($this->phpVersion == 5 ? '5' : ''));
412
 
413
		$this->log("Running ionCube Encoder...");
414
 
415
		exec($encoder->__toString() . ' ' . $arguments . " 2>&1", $output, $return);
416
 
417
        if ($return != 0)
418
        {
419
			throw new BuildException("Could not execute ionCube Encoder: " . implode(' ', $output));
420
        }
421
	}
422
 
423
	/**
424
	 * Constructs an argument string for the ionCube encoder
425
	 */
426
	private function constructArguments()
427
	{
428
		$arguments = '';
429
 
430
		foreach ($this->ionSwitches as $name => $value)
431
		{
432
			if ($value)
433
			{
434
				$arguments.= "--$name ";
435
			}
436
		}
437
 
438
		foreach ($this->ionOptions as $name => $value)
439
		{
440
			$arguments.= "--$name '$value' ";
441
		}
442
 
443
		foreach ($this->ionOptionsXS as $name => $value)
444
		{
445
			foreach (explode(' ', $value) as $arg)
446
			{
447
				$arguments.= "--$name '$arg' ";
448
			}
449
		}
450
 
451
		foreach ($this->comments as $comment)
452
		{
453
			$arguments.= "--add-comment '" . $comment->getValue() . "' ";
454
		}
455
 
456
		if (!empty($this->targetOption))
457
		{
458
			switch ($this->targetOption)
459
			{
460
				case "replace":
461
				case "merge":
462
				case "update":
463
				case "rename":
464
				{
465
					$arguments.= "--" . $this->targetOption . "-target ";
466
				} break;
467
 
468
				default:
469
				{
470
					throw new BuildException("Unknown target option '" . $this->targetOption . "'");
471
				} break;
472
			}
473
		}
474
 
475
		if ($this->fromDir != '')
476
		{
477
			$arguments .= $this->fromDir . ' ';
478
		}
479
 
480
		if ($this->toDir != '')
481
		{
482
			$arguments .= "-o " . $this->toDir . ' ';
483
		}
484
 
485
		return $arguments;
486
	}
487
}