|
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\UpdateCommand; |
|
27
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\Connector\Connector; |
|
28
|
|
|
|
|
29
|
|
|
class Application extends BaseApplication |
|
30
|
|
|
{ |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Creates application. |
|
34
|
|
|
* |
|
35
|
|
|
* @param BaseContainer $container Container. |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(BaseContainer $container) |
|
38
|
|
|
{ |
|
39
|
|
|
parent::__construct($container); |
|
40
|
|
|
|
|
41
|
|
|
$helper_set = $this->getHelperSet(); |
|
42
|
|
|
$helper_set->set($this->dic['date_helper']); |
|
43
|
|
|
$helper_set->set($this->dic['size_helper']); |
|
44
|
|
|
$helper_set->set($this->dic['output_helper']); |
|
45
|
|
|
|
|
46
|
|
|
set_time_limit(0); |
|
47
|
|
|
ini_set('memory_limit', -1); |
|
48
|
|
|
|
|
49
|
|
|
putenv('LC_CTYPE=en_US.UTF-8'); // For SVN. |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Returns the long version of the application. |
|
54
|
|
|
* |
|
55
|
|
|
* @return string The long application version |
|
56
|
|
|
* |
|
57
|
|
|
* @api |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getLongVersion() |
|
60
|
|
|
{ |
|
61
|
|
|
$version = parent::getLongVersion(); |
|
62
|
|
|
|
|
63
|
|
|
/** @var Connector $repository_connector */ |
|
64
|
|
|
$repository_connector = $this->dic['repository_connector']; |
|
65
|
|
|
$client_version = $repository_connector->getCommand('', '--version --quiet')->run(); |
|
66
|
|
|
|
|
67
|
|
|
return $version . ' (SVN <comment>v' . trim($client_version) . '</comment>)'; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritdoc} |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function getDefaultCommands() |
|
74
|
|
|
{ |
|
75
|
|
|
$default_commands = parent::getDefaultCommands(); |
|
76
|
|
|
|
|
77
|
|
|
$default_commands[] = new MergeCommand(); |
|
78
|
|
|
$default_commands[] = new CleanupCommand(); |
|
79
|
|
|
$default_commands[] = new RevertCommand(); |
|
80
|
|
|
$default_commands[] = new LogCommand(); |
|
81
|
|
|
$default_commands[] = new UpdateCommand(); |
|
82
|
|
|
$default_commands[] = new CommitCommand(); |
|
83
|
|
|
$default_commands[] = new AggregateCommand(); |
|
84
|
|
|
$default_commands[] = new CompletionCommand(); |
|
85
|
|
|
$default_commands[] = new ConfigCommand(); |
|
86
|
|
|
|
|
87
|
|
|
if ( !$this->isPharFile() ) { |
|
88
|
|
|
$default_commands[] = new MigrationCreateCommand(); |
|
89
|
|
|
$default_commands[] = new PharCreateCommand(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return $default_commands; |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Detects, when we're inside PHAR file. |
|
97
|
|
|
* |
|
98
|
|
|
* @return boolean |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function isPharFile() |
|
101
|
|
|
{ |
|
102
|
|
|
return strpos(__DIR__, 'phar://') === 0; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|
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.