ManaPHP\Utility\Text::underscore PHP Метод

underscore() публичный статический Метод

public static underscore ( string $str ) : string
$str string
Результат string
    public static function underscore($str)
    {
        return strtolower(preg_replace('/[A-Z]/', '_$0', lcfirst($str)));
    }

Usage Example

Пример #1
0
 /**
  * @param array $args
  *
  * @return int
  * @throws \ManaPHP\Cli\Application\Exception
  */
 public function handle($args = null)
 {
     $this->_args = $args ?: $GLOBALS['argv'];
     $command = count($this->_args) === 1 ? null : $this->_args[1];
     if (!$this->cliRouter->route($command)) {
         $this->console->writeLn('command name is invalid: ' . $command);
         return 1;
     }
     $controllerName = $this->cliRouter->getControllerName();
     $actionName = lcfirst($this->cliRouter->getActionName());
     $this->console->writeLn('executed command is `' . Text::underscore($controllerName) . ':' . Text::underscore($actionName) . '`');
     $controllerClassName = null;
     foreach ([$this->alias->resolve('@ns.app\\Cli\\Controllers\\' . $controllerName . 'Controller'), 'ManaPHP\\Cli\\Controllers\\' . $controllerName . 'Controller'] as $class) {
         if ($this->_dependencyInjector->has($class) || class_exists($class)) {
             $controllerClassName = $class;
         }
     }
     if (!$controllerClassName) {
         $this->console->writeLn('``:command` command is not exists', ['command' => lcfirst($controllerName) . ':' . $actionName]);
         return 1;
     }
     $controllerInstance = $this->_dependencyInjector->getShared($controllerClassName);
     $actionMethod = $actionName . 'Command';
     if (!method_exists($controllerInstance, $actionMethod)) {
         $this->console->writeLn('`:command` sub command is not exists', ['command' => lcfirst($controllerName) . ':' . $actionName]);
         return 1;
     }
     $r = $controllerInstance->{$actionMethod}();
     return is_int($r) ? $r : 0;
 }
All Usage Examples Of ManaPHP\Utility\Text::underscore