1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* See class comment |
4
|
|
|
* |
5
|
|
|
* PHP Version 5 |
6
|
|
|
* |
7
|
|
|
* @category Netresearch |
8
|
|
|
* @package Netresearch\Kite\Task |
9
|
|
|
* @author Christian Opitz <[email protected]> |
10
|
|
|
* @license http://www.netresearch.de Netresearch Copyright |
11
|
|
|
* @link http://www.netresearch.de |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Netresearch\Kite\Task; |
15
|
|
|
use Netresearch\Kite\Task; |
16
|
|
|
use Symfony\Component\Process\PhpExecutableFinder; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class PharTask |
21
|
|
|
* |
22
|
|
|
* @category Netresearch |
23
|
|
|
* @package Netresearch\Kite\Task |
24
|
|
|
* @author Christian Opitz <[email protected]> |
25
|
|
|
* @license http://www.netresearch.de Netresearch Copyright |
26
|
|
|
* @link http://www.netresearch.de |
27
|
|
|
*/ |
28
|
|
|
class PharTask extends Task |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Configures the available options |
32
|
|
|
* |
33
|
|
|
* @return array |
34
|
|
|
*/ |
35
|
|
|
protected function configureVariables() |
36
|
|
|
{ |
37
|
|
|
return array( |
38
|
|
|
'from' => array( |
39
|
|
|
'type' => 'string', |
40
|
|
|
'required' => true, |
41
|
|
|
'label' => 'The path to the directory to create the phar from' |
42
|
|
|
), |
43
|
|
|
'to' => array( |
44
|
|
|
'type' => 'string', |
45
|
|
|
'required' => true, |
46
|
|
|
'label' => 'Path and filename of the resulting phar file' |
47
|
|
|
), |
48
|
|
|
'filter' => array( |
49
|
|
|
'type' => 'string', |
50
|
|
|
'label' => 'Only file paths matching this pcre regular expression will be included in the archive' |
51
|
|
|
), |
52
|
|
|
'cliStub' => array( |
53
|
|
|
'type' => 'string', |
54
|
|
|
'label' => 'Path to cli index file, relative to <info>comment</info>' |
55
|
|
|
), |
56
|
|
|
'webStub' => array( |
57
|
|
|
'type' => 'string', |
58
|
|
|
'label' => 'Path to web index file, relative to <info>comment</info>' |
59
|
|
|
), |
60
|
|
|
'alias' => array( |
61
|
|
|
'type' => 'string', |
62
|
|
|
'label' => 'Alias with which this Phar archive should be referred to in calls to stream functionality' |
63
|
|
|
), |
64
|
|
|
'metadata' => array( |
65
|
|
|
'type' => 'mixed', |
66
|
|
|
'label' => 'Anything containing information to store that describes the phar archive' |
67
|
|
|
) |
68
|
|
|
) + parent::configureVariables(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Actually execute this task |
73
|
|
|
* |
74
|
|
|
* @return \Phar |
75
|
|
|
*/ |
76
|
|
|
public function execute() |
77
|
|
|
{ |
78
|
|
|
$to = $this->get('to'); |
79
|
|
|
if (file_exists($to)) { |
80
|
|
|
$this->console->getFilesystem()->remove($to); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$executableFinder = new PhpExecutableFinder(); |
84
|
|
|
$php = $executableFinder->find(); |
85
|
|
|
$php .= ' -d phar.readonly=0'; |
86
|
|
|
|
87
|
|
|
$code = "<?php\n"; |
88
|
|
|
foreach (array('to', 'from', 'filter', 'cliStub', 'webStub', 'alias', 'metadata') as $var) { |
89
|
|
|
$value = $this->get($var); |
90
|
|
|
$code .= '$' . $var . " = unserialize('" . serialize($value) . "');\n"; |
91
|
|
|
} |
92
|
|
|
$code .= ' |
93
|
|
|
$phar = new \Phar($to); |
94
|
|
|
$phar->buildFromDirectory($from, $filter); |
95
|
|
|
if ($cliStub || $webStub) { |
96
|
|
|
$phar->setStub($phar->createDefaultStub($cliStub, $webStub)); |
97
|
|
|
} |
98
|
|
|
if ($alias) { |
99
|
|
|
$phar->setAlias($alias); |
100
|
|
|
} |
101
|
|
|
if ($metadata) { |
102
|
|
|
$phar->setMetadata($metadata); |
103
|
|
|
} |
104
|
|
|
?>'; |
105
|
|
|
|
106
|
|
|
$process = $this->console->createProcess($php); |
107
|
|
|
$process->setInput($code); |
108
|
|
|
$process->run(); |
109
|
|
|
|
110
|
|
|
return new \Phar($to); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
?> |
114
|
|
|
|