1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the teamneusta/magallanes-task-typo3 package. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2017 neusta GmbH | Ein team neusta Unternehmen |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License |
10
|
|
|
*/ |
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace TeamNeusta\Magallanes\Task\TYPO3; |
14
|
|
|
|
15
|
|
|
use Mage\Task\AbstractTask; |
16
|
|
|
use Symfony\Component\Process\Process; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class AbstractTypo3Task |
20
|
|
|
* |
21
|
|
|
* @author Benjamin Kluge <[email protected]> |
22
|
|
|
* @package TeamNeusta\Magallanes\Task\TYPO3 |
23
|
|
|
*/ |
24
|
|
|
abstract class AbstractTypo3Task extends AbstractTask |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* namePrefix |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $namePrefix = 'typo3/'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* getName |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
public function getName(): string |
39
|
|
|
{ |
40
|
|
|
return $this->namePrefix.$this->name; |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* getDescription |
45
|
|
|
* |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
|
|
public function getDescription(): string |
49
|
|
|
{ |
50
|
|
|
return $this->description; |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* getContextCommand |
55
|
|
|
* |
56
|
|
|
* @param $cmd |
57
|
|
|
* @param array $options |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
protected function getContextCommand($cmd, array $options): string |
61
|
|
|
{ |
62
|
|
|
if (!empty($options['context'])) { |
63
|
|
|
return sprintf( |
64
|
|
|
'export TYPO3_CONTEXT="%s" && ', |
65
|
|
|
$options['context'] |
66
|
|
|
).$cmd; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $cmd; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* getOptions |
74
|
|
|
* |
75
|
|
|
* @param array $defaults |
76
|
|
|
* @return array |
77
|
|
|
*/ |
78
|
|
|
protected function getOptions(array $defaults): array |
79
|
|
|
{ |
80
|
|
|
$options = array_merge( |
81
|
|
|
['context' => null], |
82
|
|
|
$defaults, |
83
|
|
|
$this->runtime->getMergedOption('typo3') |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
return array_filter($options); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* executeCommand |
91
|
|
|
* |
92
|
|
|
* @param $command |
93
|
|
|
* @return bool |
94
|
|
|
*/ |
95
|
|
|
protected function executeCommand($command): bool |
96
|
|
|
{ |
97
|
|
|
/** @var Process $process */ |
98
|
|
|
$process = $this->runtime->runCommand(trim($command)); |
99
|
|
|
|
100
|
|
|
return $process->isSuccessful(); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: