mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Updating i18n shell to start using new OptionParser class.
Removing more dead attributes from Shell. Making Shell::$name the name used to invoke the shell, not the classname. This makes it similar to other objects with names.
This commit is contained in:
parent
2a2428a694
commit
41b8affa82
3 changed files with 23 additions and 34 deletions
|
@ -65,7 +65,7 @@ class I18nShell extends Shell {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function main() {
|
public function main() {
|
||||||
$this->out(__('I18n Shell'));
|
$this->out(__('<info>I18n Shell</info>'));
|
||||||
$this->hr();
|
$this->hr();
|
||||||
$this->out(__('[E]xtract POT file from sources'));
|
$this->out(__('[E]xtract POT file from sources'));
|
||||||
$this->out(__('[I]nitialize i18n database table'));
|
$this->out(__('[I]nitialize i18n database table'));
|
||||||
|
@ -81,7 +81,7 @@ class I18nShell extends Shell {
|
||||||
$this->initdb();
|
$this->initdb();
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
$this->help();
|
$this->out($this->OptionParser->help());
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -102,6 +102,16 @@ class I18nShell extends Shell {
|
||||||
$this->Dispatch->dispatch();
|
$this->Dispatch->dispatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get and configure the Option parser
|
||||||
|
*
|
||||||
|
* @return ConsoleOptionParser
|
||||||
|
*/
|
||||||
|
protected function _getOptionParser() {
|
||||||
|
$parser = parent::_getOptionParser();
|
||||||
|
return $parser->description(__('I18n Shell initializes i18n database table for your application and generates .pot files(s) with translations.'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show help screen.
|
* Show help screen.
|
||||||
*
|
*
|
||||||
|
|
|
@ -83,14 +83,6 @@ class Shell extends Object {
|
||||||
*/
|
*/
|
||||||
public $shell = null;
|
public $shell = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* The class name of the shell that was invoked.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
public $className = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The command called if public methods are available.
|
* The command called if public methods are available.
|
||||||
*
|
*
|
||||||
|
@ -107,14 +99,6 @@ class Shell extends Object {
|
||||||
*/
|
*/
|
||||||
public $name = null;
|
public $name = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* An alias for the shell
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
public $alias = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains tasks to load and instantiate
|
* Contains tasks to load and instantiate
|
||||||
*
|
*
|
||||||
|
@ -179,22 +163,18 @@ class Shell extends Object {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function __construct(&$dispatch, $stdout = null, $stderr = null, $stdin = null) {
|
function __construct(&$dispatch, $stdout = null, $stderr = null, $stdin = null) {
|
||||||
$vars = array('params', 'args', 'shell', 'shellCommand' => 'command', 'shellPaths');
|
$vars = array('shell', 'shellCommand' => 'command', 'shellPaths');
|
||||||
|
|
||||||
foreach ($vars as $key => $var) {
|
foreach ($vars as $key => $var) {
|
||||||
if (is_string($key)) {
|
if (is_string($key)) {
|
||||||
$this->{$var} =& $dispatch->{$key};
|
$this->{$var} = $dispatch->{$key};
|
||||||
} else {
|
} else {
|
||||||
$this->{$var} =& $dispatch->{$var};
|
$this->{$var} = $dispatch->{$var};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->name == null) {
|
if ($this->name == null) {
|
||||||
$this->name = get_class($this);
|
$this->name = Inflector::underscore(str_replace('Shell', '', get_class($this)));
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->alias == null) {
|
|
||||||
$this->alias = $this->name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->Dispatch =& $dispatch;
|
$this->Dispatch =& $dispatch;
|
||||||
|
@ -243,8 +223,8 @@ class Shell extends Object {
|
||||||
$this->out();
|
$this->out();
|
||||||
$this->out('<info>Welcome to CakePHP v' . Configure::version() . ' Console</info>');
|
$this->out('<info>Welcome to CakePHP v' . Configure::version() . ' Console</info>');
|
||||||
$this->hr();
|
$this->hr();
|
||||||
$this->out('App : '. $this->params['app']);
|
$this->out('App : '. $this->Dispatch->params['app']);
|
||||||
$this->out('Path: '. $this->params['working']);
|
$this->out('Path: '. $this->Dispatch->params['working']);
|
||||||
$this->hr();
|
$this->hr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,21 +323,20 @@ class Shell extends Object {
|
||||||
if ($isTask || $isMethod) {
|
if ($isTask || $isMethod) {
|
||||||
array_shift($argv);
|
array_shift($argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->OptionParser = $this->_getOptionParser();
|
||||||
|
list($this->params, $this->args) = $this->OptionParser->parse($argv);
|
||||||
|
|
||||||
if ($isTask || $isMethod || $isMain) {
|
if ($isTask || $isMethod || $isMain) {
|
||||||
$this->startup();
|
$this->startup();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($isTask) {
|
if ($isTask) {
|
||||||
$command = Inflector::camelize($command);
|
$command = Inflector::camelize($command);
|
||||||
return $this->{$command}->runCommand('execute', $argv);
|
return $this->{$command}->runCommand('execute', $argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->OptionParser = $this->_getOptionParser();
|
|
||||||
list($this->params, $this->args) = $this->OptionParser->parse($argv);
|
|
||||||
if (isset($this->params['help'])) {
|
if (isset($this->params['help'])) {
|
||||||
return $this->out($this->OptionParser->help());
|
return $this->out($this->OptionParser->help());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($isMethod) {
|
if ($isMethod) {
|
||||||
return $this->{$command}();
|
return $this->{$command}();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue