lithium\console\command\Help::run PHP Метод

run() публичный Метод

Auto run the help command.
public run ( string $command = null ) : boolean
$command string Name of the command to return help about.
Результат boolean
    public function run($command = null)
    {
        $message = 'Lithium console started in the ' . Environment::get() . ' environment.';
        $message .= ' Use the --env=environment key to alter this.';
        $this->out($message);
        if (!$command) {
            $this->_renderCommands();
            return true;
        }
        if (!preg_match('/\\\\/', $command)) {
            $command = Inflector::camelize($command);
        }
        if (!($class = Libraries::locate('command', $command))) {
            $this->error("Command `{$command}` not found");
            return false;
        }
        if (strpos($command, '\\') !== false) {
            $command = join('', array_slice(explode("\\", $command), -1));
        }
        $command = strtolower(Inflector::slug($command));
        $run = null;
        $methods = $this->_methods($class);
        $properties = $this->_properties($class);
        $info = Inspector::info($class);
        $this->out('USAGE', 'heading');
        if (isset($methods['run'])) {
            $run = $methods['run'];
            unset($methods['run']);
            $this->_renderUsage($command, $run, $properties);
        }
        foreach ($methods as $method) {
            $this->_renderUsage($command, $method);
        }
        if (!empty($info['description'])) {
            $this->nl();
            $this->_renderDescription($info);
            $this->nl();
        }
        if ($properties || $methods) {
            $this->out('OPTIONS', 'heading');
        }
        if ($run) {
            $this->_render($run['args']);
        }
        if ($methods) {
            $this->_render($methods);
        }
        if ($properties) {
            $this->_render($properties);
        }
        return true;
    }

Usage Example

Пример #1
0
 public function testRunWithName()
 {
     $command = new Help(array('request' => $this->request, 'classes' => $this->classes));
     $result = $command->run('Test');
     $this->assertTrue($result);
     $result = $command->run('test');
     $this->assertTrue($result);
     $expected = 'li3 test [--filters=<string>]';
     $expected .= ' [--format=<string>] [--verbose] [--plain] [<path>]';
     $expected = preg_quote($expected);
     $result = $command->response->output;
     $this->assertPattern("/{$expected}/", $result);
     $expected = "OPTIONS\n    <path>\n";
     $expected = preg_quote($expected);
     $result = $command->response->output;
     $this->assertPattern("/{$expected}/", $result);
     $expected = "DESCRIPTION\n";
     $expected = preg_quote($expected);
     $result = $command->response->output;
     $this->assertPattern("/{$expected}/", $result);
     $expected = "Command `TestWithDashes` not found";
     $expected = preg_quote($expected);
     $result = $command->run('test-with-dashes');
     $this->assertFalse($result);
     $result = $command->response->error;
     $this->assertPattern("/{$expected}/", $result);
     $expected = "Command `TestWithUnderscores` not found";
     $expected = preg_quote($expected);
     $result = $command->run('test_with_underscores');
     $this->assertFalse($result);
     $result = $command->response->error;
     $this->assertPattern("/{$expected}/", $result);
 }
All Usage Examples Of lithium\console\command\Help::run