1: <?php
2:
3: namespace Himedia\Padocc\Task\Base;
4:
5: use Himedia\Padocc\AttributeProperties;
6: use Himedia\Padocc\Task;
7:
8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
20: class Composer extends Task
21: {
22: 23: 24:
25: protected function init()
26: {
27: parent::init();
28:
29: $this->aAttrProperties = array(
30: 'dir' => AttributeProperties::DIR | AttributeProperties::REQUIRED
31: | AttributeProperties::ALLOW_PARAMETER,
32: 'options' => 0
33: );
34: }
35:
36: 37: 38: 39:
40: public static function getTagName()
41: {
42: return 'composer';
43: }
44:
45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55:
56: public function check ()
57: {
58: parent::check();
59:
60: if (empty($this->aAttValues['options'])) {
61: $this->aAttValues['options'] = '--no-dev';
62: }
63: }
64:
65: 66: 67: 68: 69: 70:
71: protected function centralExecute ()
72: {
73: parent::centralExecute();
74: $this->getLogger()->info('+++');
75:
76: $sInstallCmdPattern = '%1$s install --working-dir "%2$s" %3$s';
77: $sWGetCmd = 'wget -q --no-check-certificate http://getcomposer.org/installer -O - | php';
78: $sCURLCmd = 'curl -sS https://getcomposer.org/installer | php';
79: $sCheckCmd = 'which composer 1>/dev/null 2>&1 && echo -n 1 || echo -n 0; '
80: . 'which wget 1>/dev/null 2>&1 && echo -n 1 || echo -n 0; '
81: . 'which curl 1>/dev/null 2>&1 && echo 1 || echo 0';
82:
83: $aDirs = $this->processPath($this->aAttValues['dir']);
84: foreach ($aDirs as $sDir) {
85: list(, , $sLocalPath) = $this->oShell->isRemotePath($sDir);
86: $aResult = $this->oShell->execSSH($sCheckCmd, $sDir);
87: $isComposerInstalled = (substr($aResult[0], 0, 1) === '1');
88: $isWGetInstalled = (substr($aResult[0], 1, 1) === '1');
89: $isCURLInstalled = (substr($aResult[0], 2, 1) === '1');
90:
91:
92: if ($isComposerInstalled) {
93: $sComposerBin = 'composer';
94: $sDownloadCmd = '';
95: } elseif ($isWGetInstalled) {
96: $sComposerBin = 'php composer.phar';
97: $sDownloadCmd = $sWGetCmd;
98: } elseif ($isCURLInstalled) {
99: $sComposerBin = 'php composer.phar';
100: $sDownloadCmd = $sCURLCmd;
101: } else {
102: $sMsg = 'Composer is not installed, but nor are both wget and curl to install it!';
103: throw new \RuntimeException($sMsg);
104: }
105:
106:
107: if (! empty($sDownloadCmd)) {
108: $this->getLogger()->info('Install composer:+++');
109: $aResult = $this->oShell->execSSH($sDownloadCmd, $sDir);
110: $this->getLogger()->info(implode("\n", $aResult) . '---');
111: }
112:
113:
114: $this->getLogger()->info("Execute composer on '$sDir':+++");
115: $sCmd = sprintf($sInstallCmdPattern, $sComposerBin, $sLocalPath, $this->aAttValues['options']);
116: $aResult = $this->oShell->execSSH($sCmd, $sDir);
117: $this->getLogger()->info(implode("\n", $aResult) . '---');
118: }
119:
120: $this->getLogger()->info('---');
121: }
122: }
123: