]> git.mxchange.org Git - friendica.git/blob - src/Core/Console.php
Rename social.disable_cw pconfig to system.disable_cw
[friendica.git] / src / Core / Console.php
1 <?php
2
3 namespace Friendica\Core;
4
5 /**
6  * Description of Console
7  *
8  * @author Hypolite Petovan <mrpetovan@gmail.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                 'config'                 => __NAMESPACE__ . '\Console\Config',
18                 'createdoxygen'          => __NAMESPACE__ . '\Console\CreateDoxygen',
19                 'docbloxerrorchecker'    => __NAMESPACE__ . '\Console\DocBloxErrorChecker',
20                 'dbstructure'            => __NAMESPACE__ . '\Console\DatabaseStructure',
21                 'extract'                => __NAMESPACE__ . '\Console\Extract',
22                 'globalcommunityblock'   => __NAMESPACE__ . '\Console\GlobalCommunityBlock',
23                 'globalcommunitysilence' => __NAMESPACE__ . '\Console\GlobalCommunitySilence',
24                 'maintenance'            => __NAMESPACE__ . '\Console\Maintenance',
25                 'newpassword'            => __NAMESPACE__ . '\Console\NewPassword',
26                 'php2po'                 => __NAMESPACE__ . '\Console\PhpToPo',
27                 'po2php'                 => __NAMESPACE__ . '\Console\PoToPhp',
28                 'typo'                   => __NAMESPACE__ . '\Console\Typo',
29         ];
30
31         protected function getHelp()
32         {
33                 $help = <<<HELP
34 Usage: bin/console [--version] [-h|--help|-?] <command> [<args>] [-v]
35
36 Commands:
37         config                 Edit site config
38         createdoxygen          Generate Doxygen headers
39         dbstructure            Do database updates
40         docbloxerrorchecker    Check the file tree for DocBlox errors
41         extract                Generate translation string file for the Friendica project (deprecated)
42         globalcommunityblock   Block remote profile from interacting with this node
43         globalcommunitysilence Silence remote profile from global community page
44         help                   Show help about a command, e.g (bin/console help config)
45         maintenance            Set maintenance mode for this node
46         newpassword            Set a new password for a given user
47         php2po                 Generate a messages.po file from a strings.php file
48         po2php                 Generate a strings.php file from a messages.po file
49         typo                   Checks for parse errors in Friendica files
50
51 Options:
52         -h|--help|-? Show help information
53         -v           Show more debug information.
54 HELP;
55                 return $help;
56         }
57
58         protected function doExecute()
59         {
60                 if ($this->getOption('v')) {
61                         $this->out('Executable: ' . $this->executable);
62                         $this->out('Arguments: ' . var_export($this->args, true));
63                         $this->out('Options: ' . var_export($this->options, true));
64                 }
65
66                 $showHelp = false;
67                 $subHelp = false;
68                 $command = null;
69
70                 if ($this->getOption('version')) {
71                         $this->out('Friendica Console version ' . FRIENDICA_VERSION);
72
73                         return 0;
74                 } elseif ((count($this->options) === 0 || $this->getOption($this->customHelpOptions) === true || $this->getOption($this->customHelpOptions) === 1) && count($this->args) === 0
75                 ) {
76                         $showHelp = true;
77                 } elseif (count($this->args) >= 2 && $this->getArgument(0) == 'help') {
78                         $command = $this->getArgument(1);
79                         $subHelp = true;
80                         array_shift($this->args);
81                         array_shift($this->args);
82                 } elseif (count($this->args) >= 1) {
83                         $command = $this->getArgument(0);
84                         array_shift($this->args);
85                 }
86
87                 if (is_null($command)) {
88                         $this->out($this->getHelp());
89                         return 0;
90                 }
91
92                 $console = $this->getSubConsole($command);
93
94                 if ($subHelp) {
95                         $console->setOption($this->customHelpOptions, true);
96                 }
97
98                 return $console->execute();
99         }
100
101         private function getSubConsole($command)
102         {
103                 if ($this->getOption('v')) {
104                         $this->out('Command: ' . $command);
105                 }
106
107                 if (!isset($this->subConsoles[$command])) {
108                         throw new \Asika\SimpleConsole\CommandArgsException('Command ' . $command . ' doesn\'t exist');
109                 }
110
111                 $subargs = $this->args;
112                 array_unshift($subargs, $this->executable);
113
114                 $className = $this->subConsoles[$command];
115
116                 $subconsole = new $className($subargs);
117
118                 foreach ($this->options as $name => $value) {
119                         $subconsole->setOption($name, $value);
120                 }
121
122                 return $subconsole;
123         }
124
125 }