|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace luya\console; |
|
4
|
|
|
|
|
5
|
|
|
use luya\traits\ApplicationTrait; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* LUYA Console/CLI Application. |
|
9
|
|
|
* |
|
10
|
|
|
* @property \luya\console\ErrorHandler $errorHandler The error handler component. |
|
11
|
|
|
* |
|
12
|
|
|
* @author Basil Suter <[email protected]> |
|
13
|
|
|
* @since 1.0.0 |
|
14
|
|
|
*/ |
|
15
|
|
|
class Application extends \yii\console\Application |
|
16
|
|
|
{ |
|
17
|
|
|
use ApplicationTrait; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var bool Mute the Applications ouput, this is used to make application |
|
21
|
|
|
* cli tests with no output. The `luya\console\Controller` output/print methods are listening |
|
22
|
|
|
* to this property. |
|
23
|
|
|
*/ |
|
24
|
|
|
public $mute = false; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Provides an array with all LUYA core commands. |
|
28
|
|
|
* |
|
29
|
|
|
* Instead of overriding the core command application and merged the value we directly copied them. |
|
30
|
|
|
* |
|
31
|
|
|
* @see \yii\console\Application::coreCommands() |
|
32
|
|
|
*/ |
|
33
|
|
|
public function coreCommands() |
|
34
|
|
|
{ |
|
35
|
|
|
return [ |
|
|
|
|
|
|
36
|
|
|
// yii default commands |
|
37
|
|
|
'asset' => 'yii\console\controllers\AssetController', |
|
38
|
|
|
'cache' => 'yii\console\controllers\CacheController', |
|
39
|
|
|
'fixture' => 'yii\console\controllers\FixtureController', |
|
40
|
|
|
'help' => 'yii\console\controllers\HelpController', |
|
41
|
|
|
'message' => 'yii\console\controllers\MessageController', |
|
42
|
|
|
'serve' => [ |
|
43
|
|
|
'class' => 'yii\console\controllers\ServeController', |
|
44
|
|
|
'docroot' => '@app/public_html', |
|
45
|
|
|
], |
|
46
|
|
|
// luya default commands |
|
47
|
|
|
'migrate' => 'luya\console\commands\MigrateController', |
|
48
|
|
|
'module' => 'luya\console\commands\ModuleController', |
|
49
|
|
|
'theme' => 'luya\console\commands\ThemeController', |
|
50
|
|
|
'import' => 'luya\console\commands\ImportController', |
|
51
|
|
|
'health' => 'luya\console\commands\HealthController', |
|
52
|
|
|
]; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @inheritdoc |
|
57
|
|
|
*/ |
|
58
|
|
|
public function coreComponents() |
|
59
|
|
|
{ |
|
60
|
|
|
return array_merge($this->luyaCoreComponents(), [ |
|
61
|
|
|
'errorHandler' => ['class' => 'luya\console\ErrorHandler'], |
|
62
|
|
|
]); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.