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

public static underscore ( string $str ) : string
$str string
Результат string
Пример #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;
 }
Пример #2
0
 /**
  * Returns the mapped source for a model
  *
  * @param \ManaPHP\Mvc\ModelInterface|string $model
  *
  * @return string
  */
 public function getModelSource($model)
 {
     $modelName = is_string($model) ? $model : get_class($model);
     if (!isset($this->_sources[$modelName])) {
         if ($this->_recallGetModelSource) {
             return Text::underscore(Text::contains($modelName, '\\') ? substr($modelName, strrpos($modelName, '\\') + 1) : $modelName);
         }
         $modelInstance = is_string($model) ? new $model() : $model;
         /** @noinspection NotOptimalIfConditionsInspection */
         if (!isset($this->_sources[$modelName])) {
             $this->_recallGetModelSource = true;
             $this->_sources[$modelName] = $modelInstance->getSource();
             $this->_recallGetModelSource = false;
         }
     }
     return $this->_sources[$modelName];
 }
Пример #3
0
 /**
  * @param string     $method
  * @param int|string $arguments
  *
  * @return array|false|int|\ManaPHP\Mvc\Model|static[]
  * @throws \ManaPHP\Mvc\Model\Exception
  */
 public static function __callStatic($method, $arguments)
 {
     switch (count($arguments)) {
         case 0:
             throw new ModelException('The `:method` requires one argument at least', ['method' => $method]);
             break;
         case 1:
             $arguments[] = null;
             break;
         case 2:
             break;
         default:
             throw new ModelException('The `:method` requires two arguments at most', ['method' => $method]);
     }
     if (!is_scalar($arguments[0])) {
         throw new ModelException('The first argument of `:method`  must be a scalar value', ['method' => $method]);
     }
     if (strpos($method, 'findFirstBy') === 0) {
         return static::findFirst([Text::underscore(substr($method, 11)) => $arguments[0]], $arguments[1]);
     } elseif (strpos($method, 'findBy') === 0) {
         return static::find([Text::underscore(substr($method, 6)) => $arguments[0]], $arguments[1]);
     } elseif (strpos($method, 'countBy') === 0) {
         return static::count([Text::underscore(substr($method, 7)) => $arguments[0]], '*', $arguments[1]);
     } else {
         return null;
     }
 }