]> git.mxchange.org Git - friendica.git/blob - src/Core/Console.php
Fix types in doc blocks/prototypes
[friendica.git] / src / Core / Console.php
1 <?php
2
3 namespace Friendica\Core;
4
5 /**
6  * Description of Console
7  *
8  * @author Hypolite Petovan <hypolite@mrpetovan.com>
9  */
10 class Console extends \Asika\SimpleConsole\Console
11 {
12         // Disables the default help handling
13         protected $helpOptions = [];
14         protected $customHelpOptions = ['h', 'help', '?'];
15
16         protected $subConsoles = [
17                 'cache'                  => __NAMESPACE__ . '\Console\Cache',
18                 'config'                 => __NAMESPACE__ . '\Console\Config',
19                 'createdoxygen'          => __NAMESPACE__ . '\Console\CreateDoxygen',
20                 'docbloxerrorchecker'    => __NAMESPACE__ . '\Console\DocBloxErrorChecker',
21                 'dbstructure'            => __NAMESPACE__ . '\Console\DatabaseStructure',
22                 'extract'                => __NAMESPACE__ . '\Console\Extract',
23                 'globalcommunityblock'   => __NAMESPACE__ . '\Console\GlobalCommunityBlock',
24                 'globalcommunitysilence' => __NAMESPACE__ . '\Console\GlobalCommunitySilence',
25                 'archivecontact'         => __NAMESPACE__ . '\Console\ArchiveContact',
26                 'autoinstall'            => __NAMESPACE__ . '\Console\AutomaticInstallation',
27                 'maintenance'            => __NAMESPACE__ . '\Console\Maintenance',
28                 'newpassword'            => __NAMESPACE__ . '\Console\NewPassword',
29                 'php2po'                 => __NAMESPACE__ . '\Console\PhpToPo',
30                 'po2php'                 => __NAMESPACE__ . '\Console\PoToPhp',
31                 'typo'                   => __NAMESPACE__ . '\Console\Typo',
32                 'postupdate'             => __NAMESPACE__ . '\Console\PostUpdate',
33                 'storage'                => __NAMESPACE__ . '\Console\Storage',
34         ];
35
36         protected function getHelp()
37         {
38                 $help = <<<HELP
39 Usage: bin/console [--version] [-h|--help|-?] <command> [<args>] [-v]
40
41 Commands:
42         cache                  Manage node cache
43         config                 Edit site config
44         createdoxygen          Generate Doxygen headers
45         dbstructure            Do database updates
46         docbloxerrorchecker    Check the file tree for DocBlox errors
47         extract                Generate translation string file for the Friendica project (deprecated)
48         globalcommunityblock   Block remote profile from interacting with this node
49         globalcommunitysilence Silence remote profile from global community page
50         archivecontact         Archive a contact when you know that it isn't existing anymore
51         help                   Show help about a command, e.g (bin/console help config)
52         autoinstall            Starts automatic installation of friendica based on values from htconfig.php
53         maintenance            Set maintenance mode for this node
54         newpassword            Set a new password for a given user
55         php2po                 Generate a messages.po file from a strings.php file
56         po2php                 Generate a strings.php file from a messages.po file
57         typo                   Checks for parse errors in Friendica files
58         postupdate             Execute pending post update scripts (can last days)
59         storage                Manage storage backend
60
61 Options:
62         -h|--help|-? Show help information
63         -v           Show more debug information.
64 HELP;
65                 return $help;
66         }
67
68         protected function doExecute()
69         {
70                 if ($this->getOption('v')) {
71                         $this->out('Executable: ' . $this->executable);
72                         $this->out('Arguments: ' . var_export($this->args, true));
73                         $this->out('Options: ' . var_export($this->options, true));
74                 }
75
76                 $subHelp = false;
77                 $command = null;
78
79                 if ($this->getOption('version')) {
80                         $this->out('Friendica Console version ' . FRIENDICA_VERSION);
81
82                         return 0;
83                 } elseif ((count($this->options) === 0 || $this->getOption($this->customHelpOptions) === true || $this->getOption($this->customHelpOptions) === 1) && count($this->args) === 0
84                 ) {
85                 } elseif (count($this->args) >= 2 && $this->getArgument(0) == 'help') {
86                         $command = $this->getArgument(1);
87                         $subHelp = true;
88                         array_shift($this->args);
89                         array_shift($this->args);
90                 } elseif (count($this->args) >= 1) {
91                         $command = $this->getArgument(0);
92                         array_shift($this->args);
93                 }
94
95                 if (is_null($command)) {
96                         $this->out($this->getHelp());
97                         return 0;
98                 }
99
100                 $console = $this->getSubConsole($command);
101
102                 if ($subHelp) {
103                         $console->setOption($this->customHelpOptions, true);
104                 }
105
106                 return $console->execute();
107         }
108
109         private function getSubConsole($command)
110         {
111                 if ($this->getOption('v')) {
112                         $this->out('Command: ' . $command);
113                 }
114
115                 if (!isset($this->subConsoles[$command])) {
116                         throw new \Asika\SimpleConsole\CommandArgsException('Command ' . $command . ' doesn\'t exist');
117                 }
118
119                 $subargs = $this->args;
120                 array_unshift($subargs, $this->executable);
121
122                 $className = $this->subConsoles[$command];
123
124                 /** @var Console $subconsole */
125                 $subconsole = new $className($subargs);
126
127                 foreach ($this->options as $name => $value) {
128                         $subconsole->setOption($name, $value);
129                 }
130
131                 return $subconsole;
132         }
133
134 }