Example #1
1
 /**
  * Find view paths in application folder.
  *
  * {@inheritDoc}
  *
  * @see \yii\base\Widget::getViewPath()
  * @return string
  */
 public function getViewPath()
 {
     // get reflection
     $class = new ReflectionClass($this);
     // get path with alias
     return '@app/views/widgets/' . Inflector::camel2id($class->getShortName());
 }
Example #2
1
 protected function renderDataCellContent($model, $key, $index)
 {
     if ($this->count) {
         $count = call_user_func($this->count, $model, $key, $index, $this);
         // Deprecated: use `self::$count`
     } elseif ($this->countField) {
         $count = $model->{$this->countField};
     } elseif ($this->modelClass) {
         $childModelClass = $this->modelClass;
         $count = $childModelClass::find()->where([$this->modelField => $key])->permission()->count();
     } else {
         throw new Exception("Count is empty");
     }
     if (empty($count) && !$this->showEmpty) {
         return '';
     }
     $content = Html::tag('span', $count, ['class' => 'badge']);
     // Deprecated: Use `DataColumn::$link`
     if ($this->needUrl && $this->modelClass && $this->modelField) {
         // need url
         $childModel = new $childModelClass();
         if (empty($this->urlPath)) {
             $this->urlPath = Inflector::camel2id($childModel->formName()) . '/index';
         }
         if (empty($this->searchFieldName)) {
             $this->searchFieldName = $this->modelField;
             if ($this->dirtyUrl) {
                 $this->searchFieldName = $childModel->formName() . 'Search[' . $this->modelField . ']';
             }
         }
         $url = Url::to([$this->urlPath, $this->searchFieldName => $key]);
         return Html::a($content, $url);
     }
     return $this->dataCellContentWrapper($content, $model);
 }
 public static function bOrderAttr()
 {
     if (is_null(static::$b_order_attr)) {
         static::$b_order_attr = Inflector::camel2id(StringHelper::basename(static::bClass()), '_') . '_ord';
     }
     return static::$b_order_attr;
 }
 /**
  * @inheritdoc
  */
 public static function tableName()
 {
     $name = Inflector::camel2id(StringHelper::basename(get_called_class()), '_');
     $length = mb_strlen($name, \Yii::$app->charset) - 7;
     // - mb_strlen('_record', Yii::$app->charset);
     return '{{%' . trim(mb_substr($name, 0, $length, \Yii::$app->charset)) . '}}';
 }
Example #5
0
 /**
  * @param $class
  * @param $id
  * @param array $options
  * @return string
  */
 public static function getLink($class, $id, $options = [])
 {
     list($app, $module, $moduleName, $model, $modelName) = explode('\\', $class);
     list($modulePath, $modelPath) = [Inflector::camel2id($moduleName), Inflector::camel2id($modelName)];
     $modelName = $modulePath == $modelPath || $modelPath == 'item' ? $moduleName : "{$moduleName} {$modelName}";
     return $id ? Html::a("{$modelName}#{$id}", ["/{$modulePath}/{$modelPath}/view", 'id' => $id], $options) : Html::a("{$modelName}", ["/{$modulePath}/{$modelPath}/index"], $options);
 }
 /**
  * @return string
  */
 protected function getRoute()
 {
     if (Yii::$app->requestedAction) {
         return \yii\helpers\Inflector::camel2id(Yii::$app->requestedAction->getUniqueId());
     }
     return Yii::$app->requestedRoute;
 }
Example #7
0
 public function actionIndex()
 {
     $actions = [];
     $rc = new \ReflectionClass($this);
     $publicMethods = $rc->getMethods(\ReflectionMethod::IS_PUBLIC);
     $availableActions = [];
     foreach ($publicMethods as $publicMethod) {
         $methodName = $publicMethod->name;
         if ($methodName == 'actions') {
             continue;
         }
         if (StringHelper::startsWith($methodName, 'action')) {
             $availableActions[] = $methodName;
         }
     }
     if (count($this->actions()) > 0) {
         $availableActions = $availableActions + array_keys($this->actions());
     }
     $menus = [];
     foreach ($availableActions as $actionName) {
         $routeId = Inflector::camel2id(substr($actionName, strlen('action')));
         $menus[] = Html::a($actionName, [$routeId]);
     }
     echo implode('<br/>', $menus);
 }
Example #8
0
 public function testCamel2id()
 {
     $this->assertEquals('post-tag', Inflector::camel2id('PostTag'));
     $this->assertEquals('post_tag', Inflector::camel2id('PostTag', '_'));
     $this->assertEquals('post-tag', Inflector::camel2id('postTag'));
     $this->assertEquals('post_tag', Inflector::camel2id('postTag', '_'));
 }
 public function actionRoute()
 {
     Yii::$app->response->format = 'json';
     $controllerlist = [];
     $name = Yii::getAlias('@app');
     $pos = strrpos($_GET['title'], '\\');
     $class = substr(substr($_GET['title'], $pos + 0), 0, -10);
     $nameController = Inflector::camel2id($class);
     if ($views = opendir($name . '/views/' . $nameController)) {
         while (false !== ($file = readdir($views))) {
             $viewlist[] = $file;
         }
         closedir($views);
     }
     $fulllist = [];
     $handle = fopen($name . '/controllers/' . $_GET['title'] . ".php", "r");
     if ($handle) {
         while (($line = fgets($handle)) !== false) {
             if (preg_match('/public function action(.*?)\\(/', $line, $display)) {
                 if (strlen($display[1]) > 2) {
                     $actionname = Inflector::camel2id($display[1]);
                     $nameController = Inflector::camel2id($class);
                     $fulllist['url'][strtolower($nameController . '/' . $actionname)][] = strtolower($nameController . '/' . $actionname);
                 }
             }
         }
     }
     fclose($handle);
     return $fulllist;
 }
Example #10
0
 public function run()
 {
     $controllerId = Inflector::camel2id($this->itemClass);
     $translatedWordItems = $this->itemClass == 'Page' ? \Yii::t('back', 'pages') : \Yii::t('back', 'articles');
     $translatedWordItems2 = $this->itemClass == 'Page' ? \Yii::t('back', 'of pages') : \Yii::t('back', 'of articles');
     $contentType = $this->itemClass == 'Page' ? ContentRecord::TYPE_PAGE : ContentRecord::TYPE_ARTICLE;
     return $this->render('recentContent', ['items' => $this->_items, 'controllerId' => $controllerId, 'translatedWordItems' => $translatedWordItems, 'translatedWordItems2' => $translatedWordItems2, 'contentType' => $contentType]);
 }
 protected function idAttr()
 {
     if (is_null($this->pivotIdAttr)) {
         $owner = $this->owner;
         $this->pivotIdAttr = Inflector::camel2id(StringHelper::basename($owner->className()), '_') . '_id';
     }
     return $this->pivotIdAttr;
 }
Example #12
0
 /**
  * @param  ActiveRecord $activeRecord
  * @param               $attribute
  * @param null $extension
  *
  * @return string
  */
 public function getFilenameFor($activeRecord, $attribute, $extension = null)
 {
     $path = Inflector::camel2id((new \ReflectionClass($activeRecord))->getShortName());
     $basename = implode('-', $activeRecord->getPrimaryKey(true)) . '-' . $attribute;
     if ($extension) {
         $basename .= '.' . $extension;
     }
     return $path . DIRECTORY_SEPARATOR . $basename;
 }
Example #13
0
 /**
  * @param Module $module
  *
  * @return array
  */
 public function getControllers($module)
 {
     $files = FileHelper::findFiles($module->controllerPath, ['only' => ['*Controller.php']]);
     return ArrayHelper::getColumn($files, function ($file) use($module) {
         $class = pathinfo($file, PATHINFO_FILENAME);
         $route = Inflector::camel2id($class = substr($class, 0, strlen($class) - strlen('Controller')));
         return new ControllerModel(['route' => $module->uniqueId . '/' . $route, 'label' => Inflector::camel2words($class)]);
     });
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (!isset($this->counterOwner) || !is_array($this->counterOwner) && !is_object($this->counterOwner)) {
         throw new InvalidConfigException('counterOwner must be configured as array or object');
     }
     if (!isset($this->counterParam)) {
         $this->counterParam = Inflector::camel2id(StringHelper::basename(get_class($this->counterOwner))) . '_count';
     }
 }
 /**
  * Initialize attributes
  *
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     if (!$this->model) {
         throw new InvalidConfigException('Model is missing');
     }
     $this->_modelName = $this->model instanceof ActiveRecord ? Inflector::camel2id(StringHelper::basename(get_class($this->model))) : $this->model;
     if (!$this->storageId) {
         $this->storageId = $this->_modelName;
     }
 }
 public function actionIndex()
 {
     foreach (FileHelper::findFiles($this->module->getControllerPath()) as $file) {
         $id = lcfirst(substr(basename($file), 0, -14));
         $name = Inflector::camel2words($id);
         $route = ['/' . $this->module->id . '/' . Inflector::camel2id($name)];
         $controllers[$name] = $route;
     }
     return $this->render('index', ['controllers' => $controllers]);
 }
Example #17
0
 public function filter(ActiveDataProvider &$activeDataProvider, $query)
 {
     $fieldName = Inflector::camel2id(ArrayHelper::getValue($query, 'field'), '_');
     $glue = ArrayHelper::getValue($query, 'glue', 'and');
     if ($glue == 'and') {
         $activeDataProvider->query->andWhere([$fieldName => null]);
     } else {
         $activeDataProvider->query->orWhere([$fieldName => null]);
     }
 }
Example #18
0
 public static function prefixEventName()
 {
     $class = static::className();
     if (!isset(static::$_prefixEventNames[$class])) {
         if (($pos = strrpos($class, '\\')) !== false) {
             $class = substr($class, $pos);
         }
         static::$_prefixEventNames[$class] = 'e_' . Inflector::camel2id($class);
     }
     return static::$_prefixEventNames[$class];
 }
Example #19
0
 public function testCamel2id()
 {
     $this->assertEquals('post-tag', Inflector::camel2id('PostTag'));
     $this->assertEquals('post_tag', Inflector::camel2id('PostTag', '_'));
     $this->assertEquals('post-tag', Inflector::camel2id('postTag'));
     $this->assertEquals('post_tag', Inflector::camel2id('postTag', '_'));
     $this->assertEquals('foo-ybar', Inflector::camel2id('FooYBar', '-', false));
     $this->assertEquals('foo_ybar', Inflector::camel2id('fooYBar', '_', false));
     $this->assertEquals('foo-y-bar', Inflector::camel2id('FooYBar', '-', true));
     $this->assertEquals('foo_y_bar', Inflector::camel2id('fooYBar', '_', true));
 }
Example #20
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if ($this->modelClass === null) {
         throw new InvalidConfigException(get_class($this) . '::$modelClass must be set.');
     }
     if ($this->prefixEventName === null) {
         $pos = strrpos($this->modelClass, '\\');
         $name = $pos !== 0 ? substr($this->modelClass, $pos + 1) : $this->modelClass;
         $this->prefixEventName = 'e_' . Inflector::camel2id($name);
     }
 }
Example #21
0
 /**
  * @hass-todo
  */
 public function actionIndex()
 {
     $namespaces = \HassClassLoader::getHassCoreFile();
     $result = [];
     foreach ($namespaces as $namespace => $dir) {
         $controllerDir = $dir . DIRECTORY_SEPARATOR . "controllers";
         if (!is_dir($controllerDir)) {
             continue;
         }
         $files = FileHelper::findFiles($controllerDir);
         $moduleId = trim(substr($namespace, strrpos(rtrim($namespace, "\\"), "\\")), "\\");
         $result[$moduleId]["module"] = $moduleId;
         $result[$moduleId]["permissions"] = [];
         foreach ($files as $file) {
             $childDir = rtrim(pathinfo(substr($file, strpos($file, "controllers") + 12), PATHINFO_DIRNAME), ".");
             if ($childDir) {
                 $class = $namespace . "controllers\\" . str_replace("/", "\\", $childDir) . "\\" . rtrim(basename($file), ".php");
             } else {
                 $class = $namespace . "controllers\\" . rtrim(basename($file), ".php");
             }
             $controllerId = Inflector::camel2id(str_replace("Controller", "", pathinfo($file, PATHINFO_FILENAME)));
             $reflect = new \ReflectionClass($class);
             $methods = $reflect->getMethods(\ReflectionMethod::IS_PUBLIC);
             /** @var \ReflectionMethod $method */
             foreach ($methods as $method) {
                 if (!StringHelper::startsWith($method->name, "action")) {
                     continue;
                 }
                 if ($method->name == "actions") {
                     $object = \Yii::createObject(["class" => $class], [$controllerId, $moduleId]);
                     $actions = $method->invoke($object);
                     foreach ($actions as $actionId => $config) {
                         $route = $moduleId . "/" . $controllerId . "/" . $actionId;
                         if ($childDir) {
                             $route = $moduleId . "/" . $childDir . "/" . $controllerId . "/" . $actionId;
                         }
                         $result[$moduleId]["permissions"][$route] = ["type" => Item::TYPE_PERMISSION, "description" => $controllerId . "-" . Inflector::camel2words($actionId)];
                     }
                     continue;
                 }
                 $actionId = Inflector::camel2id(substr($method->name, 6));
                 $route = $moduleId . "/" . $controllerId . "/" . $actionId;
                 if ($childDir) {
                     $route = $moduleId . "/" . $childDir . "/" . $controllerId . "/" . $actionId;
                 }
                 $result[$moduleId]["permissions"][$route] = ["type" => Item::TYPE_PERMISSION, "description" => $controllerId . "-" . Inflector::camel2words(substr($method->name, 6))];
             }
         }
     }
     $result["super"] = ['module' => 'SUPER_PERMISSION', 'permissions' => array(\hass\rbac\Module::SUPER_PERMISSION => array('type' => Item::TYPE_PERMISSION, 'description' => 'SUPER_PERMISSION'))];
     $result = "<?php \n return " . var_export($result, true) . ";";
     file_put_contents(dirname(__DIR__) . "/permissions.php", $result);
     return $this->render("index");
 }
Example #22
0
 /**
  * Calls the named method which is not a class method.
  * Call this method directly from database connections
  */
 public function __call($name, $params)
 {
     $method = explode('-', Inflector::camel2id($name));
     $model = array_shift($method);
     $method = lcfirst(Inflector::id2camel(implode('-', $method)));
     $class = isset($this->models[$model]) ? $this->models[$model] : null;
     if ($class && method_exists($class, $method)) {
         return call_user_func_array([$class, $method], $params);
     }
     $message = 'Calling unknown method: ' . ($class ? $class : get_class($this)) . "::{$name}()";
     throw new UnknownMethodException($message);
 }
Example #23
0
 public function filter(ActiveDataProvider &$activeDataProvider, $query)
 {
     $fieldName = Inflector::camel2id(ArrayHelper::getValue($query, 'field'), '_');
     $from = ArrayHelper::getValue($query, 'from', null);
     $to = ArrayHelper::getValue($query, 'to', null);
     $glue = ArrayHelper::getValue($query, 'glue', 'and');
     if ($glue == 'and') {
         $activeDataProvider->query->andWhere(['between', $fieldName, $from, $to]);
     } else {
         $activeDataProvider->query->orWhere(['between', $fieldName, $from, $to]);
     }
 }
Example #24
0
 public function filter(ActiveDataProvider &$activeDataProvider, $query)
 {
     $fieldName = Inflector::camel2id(ArrayHelper::getValue($query, 'field'), '_');
     $value = ArrayHelper::getValue($query, 'value', array());
     $glue = ArrayHelper::getValue($query, 'glue', 'and');
     $value = explode(',', $value);
     if ($glue == 'and') {
         $activeDataProvider->query->andWhere(['like', $fieldName, $value]);
     } else {
         $activeDataProvider->query->orWhere(['like', $fieldName, $value]);
     }
 }
Example #25
0
 public function getListActions($namespace)
 {
     $reflectionClass = new ReflectionClass($namespace);
     $methods = $reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC);
     $actions = [];
     foreach ($methods as $method) {
         if (substr($method->name, 0, 6) === 'action' and strlen($method->name) > 7) {
             $action_id = str_replace('action', '', $method->name);
             $actions[] = '/' . \yii\helpers\Inflector::camel2id($action_id);
         }
     }
     return $actions;
 }
Example #26
0
 public function getViewPath()
 {
     if (!$this->viewDir || true) {
         $names = explode('\\', $this->className());
         $controllerName = array_pop($names);
         $controllerName = Inflector::camel2id(substr($controllerName, 0, -10));
         for ($i = count($names) - 1; $names[$i] != 'controllers'; $i--) {
             $controllerName = $names[$i] . '/' . $controllerName;
         }
         $this->viewDir = $controllerName;
     }
     return $this->module->getViewPath() . DIRECTORY_SEPARATOR . $this->viewDir;
 }
 /**
  * Инициализация проекта.
  */
 public function actionInit()
 {
     $rawProjectName = pathinfo(Yii::getAlias('@app'), PATHINFO_FILENAME);
     $rawProjectName = Inflector::camelize($rawProjectName);
     $projectId = Inflector::camel2id($rawProjectName);
     $projectId = Console::prompt('Project id', ['default' => $projectId]);
     $projectName = Inflector::titleize($projectId);
     $projectName = Console::prompt('Project name', ['default' => $projectName]);
     $vagrantIp = '192.168.33.' . rand(100, 254);
     $vagrantIp = Console::prompt('Vagrant IP', ['default' => $vagrantIp]);
     $values = ['PROJECT-ID' => $projectId, 'PROJECT-NAME' => $projectName, 'VAGRANT-IP' => $vagrantIp];
     $files = ['@app/build.xml' => ['PROJECT-ID'], '@app/Vagrantfile' => ['VAGRANT-IP', 'PROJECT-ID'], '@app/config/web.php' => ['PROJECT-NAME'], '@app/config/console.php' => ['PROJECT-NAME'], '@app/config/env/vagrant.php' => ['VAGRANT-IP', 'PROJECT-ID']];
     $this->replaceInFiles($files, $values);
 }
Example #28
0
 public function getControllers($module = null)
 {
     if ($module === null) {
         $module = \Yii::$app;
     } else {
         $module = \Yii::$app->getModule($module);
     }
     foreach (scandir($module->getControllerPath()) as $i => $name) {
         if (substr($name, 0, 1) == '.') {
             continue;
         }
         $controllers[] = \yii\helpers\Inflector::camel2id(str_replace('Controller.php', '', $name));
     }
     return $controllers;
 }
Example #29
0
 public function filter(ActiveDataProvider &$activeDataProvider, $query)
 {
     //TODO correct error "x-pagination-total-count"
     $fieldName = Inflector::camel2id(ArrayHelper::getValue($query, 'field'), '_');
     $value = ArrayHelper::getValue($query, 'value', array());
     $glue = ArrayHelper::getValue($query, 'glue', 'and');
     $currentObject = new $activeDataProvider->query->modelClass();
     $object = $currentObject->relatedManyToMany($fieldName);
     $keys = $object->getIds($value, $fieldName);
     if ($glue == 'and') {
         $activeDataProvider->query->andFilterWhere(['in', 'id', $keys]);
     } else {
         $activeDataProvider->query->orFilterWhere(['in', 'id', $keys]);
     }
 }
Example #30
0
 /**
  * @inheritdoc
  */
 public function actions()
 {
     $result = [];
     foreach ($this->contexts as $key => $value) {
         if (is_int($key)) {
             $contextName = $value;
             $params = [];
         } else {
             $contextName = $key;
             $params = is_array($value) ? $value : ['class' => $value];
         }
         $actionName = Inflector::camel2id('upload' . ucfirst($contextName));
         $result[$actionName] = ArrayHelper::merge($this->defaultActionParams, ['class' => $this->defaultActionClass, 'context' => $contextName], $params);
     }
     return $result;
 }