1 | <?php |
||
22 | abstract class AbstractCommand extends Command |
||
23 | { |
||
24 | const FOLDER_RESOURCES = '/../../app/Resources/config/'; |
||
25 | |||
26 | /** |
||
27 | * @var InputInterface |
||
28 | */ |
||
29 | protected $oInput; |
||
30 | |||
31 | /** |
||
32 | * @var OutputInterface |
||
33 | */ |
||
34 | protected $oOutput; |
||
35 | |||
36 | /** |
||
37 | * @var ContainerBuilder |
||
38 | */ |
||
39 | private static $oContainer; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | private static $sHomeDir = ''; |
||
45 | |||
46 | /** |
||
47 | * Executes the current command. |
||
48 | * |
||
49 | * This method is not abstract because you can use this class |
||
50 | * as a concrete class. In this case, instead of defining the |
||
51 | * execute() method, you set the code to execute by passing |
||
52 | * a Closure to the setCode() method. |
||
53 | * |
||
54 | * @param InputInterface $oInput An InputInterface instance |
||
55 | * @param OutputInterface $oOutput An OutputInterface instance |
||
56 | * |
||
57 | * @return integer null or 0 if everything went fine, or an error code |
||
58 | * |
||
59 | * @throws \LogicException When this abstract method is not implemented |
||
60 | * |
||
61 | * @see setCode() |
||
62 | */ |
||
63 | 10 | protected function execute(InputInterface $oInput, OutputInterface $oOutput) |
|
80 | |||
81 | /** |
||
82 | * @return int |
||
83 | */ |
||
84 | abstract protected function process(); |
||
85 | |||
86 | /** |
||
87 | * @return ContainerBuilder |
||
88 | */ |
||
89 | protected function getContainer() |
||
119 | |||
120 | /** |
||
121 | * @return bool |
||
122 | */ |
||
123 | protected function isAppRunable() |
||
139 | |||
140 | /** |
||
141 | * @return string |
||
142 | */ |
||
143 | 2 | protected function getHomeDir() |
|
160 | |||
161 | /** |
||
162 | * @return string |
||
163 | */ |
||
164 | 1 | protected function getCacheDir() |
|
171 | } |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.