|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* composer scripthandler base class |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Graviton\CoreBundle\Composer; |
|
7
|
|
|
|
|
8
|
|
|
use Symfony\Component\Process\Process; |
|
9
|
|
|
use Symfony\Component\Process\PhpExecutableFinder; |
|
10
|
|
|
use Composer\Script\CommandEvent; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Base class for Composer ScriptHandlers |
|
14
|
|
|
* |
|
15
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
16
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
17
|
|
|
* @link http://swisscom.ch |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class ScriptHandlerBase |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Composer variables are declared static so that an event could update |
|
23
|
|
|
* a composer.json and set new options, making them immediately available |
|
24
|
|
|
* to forthcoming listeners. |
|
25
|
|
|
*/ |
|
26
|
|
|
protected static $options = array( |
|
27
|
|
|
'symfony-app-dir' => 'app', |
|
28
|
|
|
); |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Returns some options - adapted from Sensio DistributionBundle Command |
|
32
|
|
|
* |
|
33
|
|
|
* @param CommandEvent $event Event |
|
34
|
|
|
* |
|
35
|
|
|
* @return array Options |
|
36
|
|
|
*/ |
|
37
|
|
|
protected static function getOptions(CommandEvent $event) |
|
38
|
|
|
{ |
|
39
|
|
|
$options = array_merge(self::$options, $event->getComposer()->getPackage()->getExtra()); |
|
40
|
|
|
$options['process-timeout'] = $event->getComposer()->getConfig()->get('process-timeout'); |
|
41
|
|
|
return $options; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Executes a command |
|
46
|
|
|
* |
|
47
|
|
|
* @param CommandEvent $event Event |
|
48
|
|
|
* @param string $consoleDir Console dir |
|
49
|
|
|
* @param string $cmd Command |
|
50
|
|
|
* @param int $timeout Timeout |
|
51
|
|
|
* |
|
52
|
|
|
* @return void |
|
53
|
|
|
*/ |
|
54
|
|
|
protected static function executeCommand(CommandEvent $event, $consoleDir, $cmd, $timeout = 300) |
|
55
|
|
|
{ |
|
56
|
|
|
$php = escapeshellarg(self::getPhp(false)); |
|
57
|
|
|
$console = escapeshellarg($consoleDir.'/console'); |
|
58
|
|
|
if ($event->getIO()->isDecorated()) { |
|
59
|
|
|
$console .= ' --ansi'; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$process = new Process($php.' '.$console.' '.$cmd, null, null, null, $timeout); |
|
63
|
|
|
$process->run( |
|
64
|
|
|
function ($type, $buffer) use ($event) { |
|
65
|
|
|
$event->getIO()->write($buffer, false); |
|
66
|
|
|
} |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
if (!$process->isSuccessful()) { |
|
70
|
|
|
throw new \RuntimeException( |
|
71
|
|
|
sprintf( |
|
72
|
|
|
'An error occurred when executing the "%s" command.', |
|
73
|
|
|
escapeshellarg($cmd) |
|
74
|
|
|
) |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Finds the path to the php executable |
|
82
|
|
|
* |
|
83
|
|
|
* @param bool $includeArgs include args |
|
84
|
|
|
* |
|
85
|
|
|
* @return bool|false|null|string path |
|
|
|
|
|
|
86
|
|
|
*/ |
|
87
|
|
|
protected static function getPhp($includeArgs = true) |
|
88
|
|
|
{ |
|
89
|
|
|
$phpFinder = new PhpExecutableFinder(); |
|
90
|
|
|
if (!$phpPath = $phpFinder->find($includeArgs)) { |
|
91
|
|
|
throw new \RuntimeException( |
|
92
|
|
|
'The php executable could not be found, add it to your PATH environment variable and try again' |
|
93
|
|
|
); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return $phpPath; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.