1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the SVN-Buddy library. |
4
|
|
|
* For the full copyright and license information, please view |
5
|
|
|
* the LICENSE file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @copyright Alexander Obuhovich <[email protected]> |
8
|
|
|
* @link https://github.com/console-helpers/svn-buddy |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ConsoleHelpers\SVNBuddy; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use ConsoleHelpers\ConsoleKit\Application as BaseApplication; |
15
|
|
|
use ConsoleHelpers\ConsoleKit\Container as BaseContainer; |
16
|
|
|
use ConsoleHelpers\SVNBuddy\Command\AggregateCommand; |
17
|
|
|
use ConsoleHelpers\SVNBuddy\Command\CleanupCommand; |
18
|
|
|
use ConsoleHelpers\SVNBuddy\Command\CommitCommand; |
19
|
|
|
use ConsoleHelpers\SVNBuddy\Command\CompletionCommand; |
20
|
|
|
use ConsoleHelpers\SVNBuddy\Command\ConfigCommand; |
21
|
|
|
use ConsoleHelpers\SVNBuddy\Command\Dev\MigrationCreateCommand; |
22
|
|
|
use ConsoleHelpers\SVNBuddy\Command\Dev\PharCreateCommand; |
23
|
|
|
use ConsoleHelpers\SVNBuddy\Command\LogCommand; |
24
|
|
|
use ConsoleHelpers\SVNBuddy\Command\MergeCommand; |
25
|
|
|
use ConsoleHelpers\SVNBuddy\Command\RevertCommand; |
26
|
|
|
use ConsoleHelpers\SVNBuddy\Command\SelfUpdateCommand; |
27
|
|
|
use ConsoleHelpers\SVNBuddy\Command\UpdateCommand; |
28
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\Connector\Connector; |
29
|
|
|
|
30
|
|
|
class Application extends BaseApplication |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Creates application. |
35
|
|
|
* |
36
|
|
|
* @param BaseContainer $container Container. |
37
|
|
|
*/ |
38
|
|
|
public function __construct(BaseContainer $container) |
39
|
|
|
{ |
40
|
|
|
parent::__construct($container); |
41
|
|
|
|
42
|
|
|
$helper_set = $this->getHelperSet(); |
43
|
|
|
$helper_set->set($this->dic['date_helper']); |
44
|
|
|
$helper_set->set($this->dic['size_helper']); |
45
|
|
|
$helper_set->set($this->dic['output_helper']); |
46
|
|
|
|
47
|
|
|
set_time_limit(0); |
48
|
|
|
ini_set('memory_limit', -1); |
49
|
|
|
|
50
|
|
|
putenv('LC_CTYPE=en_US.UTF-8'); // For SVN. |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Returns the long version of the application. |
55
|
|
|
* |
56
|
|
|
* @return string The long application version |
57
|
|
|
* |
58
|
|
|
* @api |
59
|
|
|
*/ |
60
|
|
|
public function getLongVersion() |
61
|
|
|
{ |
62
|
|
|
$version = parent::getLongVersion(); |
63
|
|
|
|
64
|
|
|
/** @var Connector $repository_connector */ |
65
|
|
|
$repository_connector = $this->dic['repository_connector']; |
66
|
|
|
$client_version = $repository_connector->getCommand('', '--version --quiet')->run(); |
67
|
|
|
|
68
|
|
|
return $version . ' (SVN <comment>v' . trim($client_version) . '</comment>)'; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
|
|
protected function getDefaultCommands() |
75
|
|
|
{ |
76
|
|
|
$default_commands = parent::getDefaultCommands(); |
77
|
|
|
|
78
|
|
|
$default_commands[] = new MergeCommand(); |
79
|
|
|
$default_commands[] = new CleanupCommand(); |
80
|
|
|
$default_commands[] = new RevertCommand(); |
81
|
|
|
$default_commands[] = new LogCommand(); |
82
|
|
|
$default_commands[] = new UpdateCommand(); |
83
|
|
|
$default_commands[] = new CommitCommand(); |
84
|
|
|
$default_commands[] = new AggregateCommand(); |
85
|
|
|
$default_commands[] = new CompletionCommand(); |
86
|
|
|
$default_commands[] = new ConfigCommand(); |
87
|
|
|
$default_commands[] = new SelfUpdateCommand(); |
88
|
|
|
|
89
|
|
|
if ( !$this->isPharFile() ) { |
90
|
|
|
$default_commands[] = new MigrationCreateCommand(); |
91
|
|
|
$default_commands[] = new PharCreateCommand(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $default_commands; |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
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_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.