Do not use BaseInflector. Use Inflector instead.
Since: 2.0
Author: Antonio Ramirez (amigo.cobos@gmail.com)
Author: Alexander Makarov (sam@rmcreative.ru)
Inheritance: extends BaseInflector
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (!$this->header) {
         $this->header = "<h2>" . Inflector::camel2words($this->model->formName()) . " change log:</h2>";
     }
 }
Example #2
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());
 }
 public function callback(AMQPMessage $msg)
 {
     $routingKey = $msg->delivery_info['routing_key'];
     $method = 'read' . Inflector::camelize($routingKey);
     if (!isset($this->interpreters[$this->exchange])) {
         $interpreter = $this;
     } elseif (class_exists($this->interpreters[$this->exchange])) {
         $interpreter = new $this->interpreters[$this->exchange]();
         if (!$interpreter instanceof AmqpInterpreter) {
             throw new Exception(sprintf("Class '%s' is not correct interpreter class.", $this->interpreters[$this->exchange]));
         }
     } else {
         throw new Exception(sprintf("Interpreter class '%s' was not found.", $this->interpreters[$this->exchange]));
     }
     if (method_exists($interpreter, $method)) {
         $info = ['exchange' => $msg->get('exchange'), 'routing_key' => $msg->get('routing_key'), 'reply_to' => $msg->has('reply_to') ? $msg->get('reply_to') : null];
         $interpreter->{$method}(Json::decode($msg->body, true), $info);
     } else {
         if (!isset($this->interpreters[$this->exchange])) {
             $interpreter = new AmqpInterpreter();
         }
         $interpreter->log(sprintf("Unknown routing key '%s' for exchange '%s'.", $routingKey, $this->exchange), $interpreter::MESSAGE_ERROR);
         // debug the message
         $interpreter->log(print_r(Json::decode($msg->body, true), true), $interpreter::MESSAGE_INFO);
     }
 }
 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;
 }
Example #5
1
 /**
  * @see \yii\grid\GridView::getColumnHeader($col)
  * @inheritdoc
  */
 public function getColumnHeader($col)
 {
     if ($col->header !== null || $col->label === null && $col->attribute === null) {
         return trim($col->header) !== '' ? $col->header : $col->grid->emptyCell;
     }
     $provider = $this->dataProvider;
     if ($col->label === null) {
         if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQueryInterface) {
             /**
              * @var \yii\db\ActiveRecord $model
              */
             $model = new $provider->query->modelClass();
             $label = $model->getAttributeLabel($col->attribute);
         } else {
             $models = $provider->getModels();
             if (($model = reset($models)) instanceof Model) {
                 $label = $model->getAttributeLabel($col->attribute);
             } else {
                 $label = Inflector::camel2words($col->attribute);
             }
         }
     } else {
         $label = $col->label;
     }
     return $label;
 }
 public function callback(AMQPMessage $msg)
 {
     $routingKey = $msg->get('routing_key');
     $method = 'read' . Inflector::camelize($routingKey);
     $interpreter = isset($this->interpreters[$this->exchange]) ? $this->interpreters[$this->exchange] : (isset($this->interpreters['*']) ? $this->interpreters['*'] : null);
     if ($interpreter === null) {
         $interpreter = $this;
     } else {
         if (class_exists($interpreter)) {
             $interpreter = new $interpreter();
             if (!$interpreter instanceof AmqpInterpreter) {
                 throw new Exception(sprintf("Class '%s' is not correct interpreter class.", $interpreter));
             }
         } else {
             throw new Exception(sprintf("Interpreter class '%s' was not found.", $interpreter));
         }
     }
     if (method_exists($interpreter, $method) || is_callable([$interpreter, $method])) {
         $info = ['exchange' => $this->exchange, 'routing_key' => $routingKey, 'reply_to' => $msg->has('reply_to') ? $msg->get('reply_to') : null, 'delivery_tag' => $msg->get('delivery_tag')];
         try {
             $body = Json::decode($msg->body, true);
         } catch (\Exception $e) {
             $body = $msg->body;
         }
         $interpreter->{$method}($body, $info, $this->amqp->channel);
     } else {
         if (!$interpreter instanceof AmqpInterpreter) {
             $interpreter = new AmqpInterpreter();
         }
         $interpreter->log(sprintf("Unknown routing key '%s' for exchange '%s'.", $routingKey, $this->exchange), $interpreter::MESSAGE_ERROR);
         // debug the message
         $interpreter->log(print_r(Json::decode($msg->body, true), true), $interpreter::MESSAGE_INFO);
     }
 }
 public function render()
 {
     $activeWindowHash = Yii::$app->request->get('activeWindowHash');
     $activeWindowCallback = Yii::$app->request->get('activeWindowCallback');
     $activeWindows = $this->config->getPointer('aw');
     $obj = $activeWindows[$activeWindowHash]['object'];
     $function = 'callback' . Inflector::id2camel($activeWindowCallback);
     return ObjectHelper::callMethodSanitizeArguments($obj, $function, Yii::$app->request->post());
     /*
     $reflection = new \ReflectionMethod($obj, $function);
     
     $methodArgs = [];
     
     if ($reflection->getNumberOfRequiredParameters() > 0) {
         foreach ($reflection->getParameters() as $param) {
             if (!array_key_exists($param->name, $args)) {
                 throw new \Exception("the provided argument '".$param->name."' does not exists in the provided arguments list.");
             }
             $methodArgs[] = $args[$param->name];
         }
     }
     
     $response = call_user_func_array(array($obj, $function), $methodArgs);
     
     return $response;
     */
 }
Example #8
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);
 }
Example #9
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);
 }
function wp_get_nav_menu_object($menu)
{
    $menu_obj = false;
    if (is_object($menu)) {
        $menu_obj = $menu;
    }
    if ($menu && !$menu_obj) {
        // if (strtolower($menu) == 'primary-menu' || strtolower($menu) == 'primary_menu') {
        $menu_obj = ['term_id' => $menu, 'name' => Inflector::camel2words($menu), 'slug' => $menu, 'term_group' => '0', 'term_taxonomy_id' => $menu, 'taxonomy' => 'nav_menu', 'description' => '', 'parent' => '0', 'count' => '1', 'filter' => 'raw'];
        $menu_obj = json_decode(json_encode($menu_obj, false));
        $menu_obj = new WP_Term($menu_obj);
        // }
        // $menu_obj = get_term( $menu, 'nav_menu' );
        // if ( ! $menu_obj ) {
        // 	$menu_obj = get_term_by( 'slug', $menu, 'nav_menu' );
        // }
        // if ( ! $menu_obj ) {
        // 	$menu_obj = get_term_by( 'name', $menu, 'nav_menu' );
        // }
    }
    if (!$menu_obj || is_wp_error($menu_obj)) {
        $menu_obj = false;
    }
    return apply_filters('wp_get_nav_menu_object', $menu_obj, $menu);
}
Example #11
0
 /**
  * This command echoes what you have entered as the message.
  *
  * @param string $message the message to be echoed.
  */
 public function actionIndex()
 {
     echo "Running batch...\n";
     $config = $this->getYiiConfiguration();
     $config['id'] = 'temp';
     // create models
     foreach ($this->tables as $table) {
         #var_dump($this->tableNameMap, $table);exit;
         $params = ['interactive' => $this->interactive, 'template' => 'default', 'ns' => $this->modelNamespace, 'db' => $this->modelDb, 'tableName' => $table, 'tablePrefix' => $this->tablePrefix, 'generateModelClass' => $this->extendedModels, 'modelClass' => isset($this->tableNameMap[$table]) ? $this->tableNameMap[$table] : Inflector::camelize($table), 'baseClass' => $this->modelBaseClass, 'tableNameMap' => $this->tableNameMap];
         $route = 'gii/giix-model';
         $app = \Yii::$app;
         $temp = new \yii\console\Application($config);
         $temp->runAction(ltrim($route, '/'), $params);
         unset($temp);
         \Yii::$app = $app;
     }
     // create CRUDs
     $providers = ArrayHelper::merge($this->crudProviders, Generator::getCoreProviders());
     foreach ($this->tables as $table) {
         $table = str_replace($this->tablePrefix, '', $table);
         $name = isset($this->tableNameMap[$table]) ? $this->tableNameMap[$table] : Inflector::camelize($table);
         $params = ['interactive' => $this->interactive, 'overwrite' => $this->overwrite, 'template' => 'default', 'modelClass' => $this->modelNamespace . '\\' . $name, 'searchModelClass' => $this->modelNamespace . '\\search\\' . $name . 'Search', 'controllerClass' => $this->crudControllerNamespace . '\\' . $name . 'Controller', 'viewPath' => $this->crudViewPath, 'pathPrefix' => $this->crudPathPrefix, 'actionButtonClass' => 'yii\\grid\\ActionColumn', 'baseControllerClass' => $this->crudBaseControllerClass, 'providerList' => implode(',', $providers)];
         $route = 'gii/giix-crud';
         $app = \Yii::$app;
         $temp = new \yii\console\Application($config);
         $temp->runAction(ltrim($route, '/'), $params);
         unset($temp);
         \Yii::$app = $app;
     }
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->action === null) {
         $this->action = Inflector::id2camel($this->id);
     }
 }
Example #13
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if ($this->attribute) {
         $field = str_replace(['[]', '][', '[', ']', ' ', '.'], ['', '-', '-', '', '-', '-'], $this->attribute);
     } else {
         $field = false;
     }
     if (empty($this->inputOptions['data-field']) && $field) {
         $this->inputOptions['data-field'] = $field;
     }
     if (empty($this->contentOptions['data-column']) && $field) {
         $this->contentOptions['data-column'] = $field;
     }
     if (empty($this->headerOptions['data-column']) && $field) {
         $this->headerOptions['data-column'] = $field;
     }
     if ($this->header === null) {
         if ($this->grid->model instanceof Model && !empty($this->attribute)) {
             $this->header = $this->grid->model->getAttributeLabel($this->attribute);
         } else {
             $this->header = Inflector::camel2words($this->attribute);
         }
     }
     if ($this->value === null) {
         $this->value = [$this, 'renderInputCell'];
     } elseif (is_string($this->value)) {
         $this->attribute = $this->value;
         $this->value = [$this, 'renderTextCell'];
     }
 }
Example #14
0
 /**
  * Returns the currently requested sort information.
  * @param boolean $recalculate whether to recalculate the sort directions
  * @return array sort directions indexed by attribute names.
  * Sort direction can be either `SORT_ASC` for ascending order or
  * `SORT_DESC` for descending order.
  */
 public function getAttributeOrders($recalculate = false)
 {
     if ($this->_attributeOrders === null || $recalculate) {
         $this->_attributeOrders = [];
         if (($params = $this->params) === null) {
             $request = Yii::$app->getRequest();
             $params = $request instanceof Request ? $request->getQueryParams() : [];
         }
         if (isset($params[$this->sortParam]) && is_scalar($params[$this->sortParam])) {
             $attributes = explode($this->separator, $params[$this->sortParam]);
             foreach ($attributes as $attribute) {
                 $descending = false;
                 if (strncmp($attribute, '-', 1) === 0) {
                     $descending = true;
                     $attribute = substr($attribute, 1);
                 }
                 $attribute = Inflector::underscore($attribute);
                 if (isset($this->attributes[$attribute])) {
                     $this->_attributeOrders[$attribute] = $descending ? SORT_DESC : SORT_ASC;
                     if (!$this->enableMultiSort) {
                         return $this->_attributeOrders;
                     }
                 }
             }
         }
         if (empty($this->_attributeOrders) && is_array($this->defaultOrder)) {
             $this->_attributeOrders = $this->defaultOrder;
         }
     }
     return $this->_attributeOrders;
 }
Example #15
0
 public function getView()
 {
     if ($this->_view === null) {
         $this->_view = lcfirst(Inflector::id2camel($this->id));
     }
     return $this->_view;
 }
 /**
  * Registers simplemde markdown assets
  */
 public function registerScripts()
 {
     $jsonOptions = Json::encode($this->mdeOptions);
     $varName = Inflector::classify('editor' . $this->id);
     $script = "var {$varName} = new SimpleMDE(" . $jsonOptions . ");";
     $this->view->registerJs($script);
 }
 /**
  * @return array
  */
 function getLabel()
 {
     $res = [];
     $get = $this->get;
     $attr = $this->attribute;
     $label = $this->label;
     if ($get[$attr] || $get[$attr] == '0') {
         $label = $label ? $label : $this->model->getAttributeLabel($attr) . ':';
         if ($this->getRelationName === true) {
             if (is_array($get[$attr])) {
                 $val = implode(', ', $get[$attr]);
             } else {
                 $strMod = substr(Inflector::camelize($attr), 0, -2);
                 $val = $this->model->{lcfirst($strMod)}->name;
             }
         } elseif ($this->value instanceof Closure) {
             $val = $this->renderDataCell($this->model, $get[$attr]);
         } elseif (!$this->value instanceof Closure && $this->value) {
             $val = $this->value;
         } else {
             if (is_array($get[$attr])) {
                 $val = implode(', ', $get[$attr]);
             } else {
                 $val = $get[$attr];
             }
         }
         $res = ['attr' => $attr, 'label' => $label, 'value' => $val];
     }
     return $res;
 }
Example #18
0
 /**
  * @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 #19
0
 /**
  * Sends a request to the _search API and returns the result.
  * @param array $options
  * @throws ErrorResponseException
  * @return mixed
  */
 public function search($options = [])
 {
     $url = $this->index . Inflector::id2camel(ArrayHelper::remove($options, 'scenario', 'search'));
     $query = $this->queryParts;
     $options = array_merge($query, $options);
     return $this->db->post($url, $options);
 }
Example #20
0
 /**
  * @inheritdoc
  */
 public function renderHeaderCellContent()
 {
     if ($this->header !== null || $this->label === null && $this->attribute === null) {
         return parent::renderHeaderCellContent();
     }
     $provider = $this->grid->dataProvider;
     if ($this->label === null) {
         if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQueryInterface) {
             /* @var $model Model */
             $model = new $provider->query->modelClass();
             $label = $model->getAttributeLabel($this->attribute);
         } else {
             $models = $provider->getModels();
             if (($model = reset($models)) instanceof Model) {
                 /* @var $model Model */
                 $label = $model->getAttributeLabel($this->attribute);
             } else {
                 $label = Inflector::camel2words($this->attribute);
             }
         }
     } else {
         $label = $this->label;
     }
     return $label;
 }
 public function registerScripts()
 {
     $jsonOptions = Json::encode($this->leptureOptions);
     $varName = Inflector::classify('editor' . $this->id);
     $script = "var {$varName} = new Editor(" . $jsonOptions . "); {$varName}.render();";
     $this->view->registerJs($script);
 }
Example #22
0
 /**
  * @return string
  */
 protected function getRoute()
 {
     if (Yii::$app->requestedAction) {
         return \yii\helpers\Inflector::camel2id(Yii::$app->requestedAction->getUniqueId());
     }
     return Yii::$app->requestedRoute;
 }
Example #23
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (!$this->id) {
         $this->id = Inflector::slug($this->label);
     }
 }
 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;
 }
 /**
  * Creates a new Participant model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($meeting_id)
 {
     $mtg = new Meeting();
     $title = $mtg->getMeetingTitle($meeting_id);
     $model = new Participant();
     $model->meeting_id = $meeting_id;
     $model->invited_by = Yii::$app->user->getId();
     // load friends for auto complete field
     $friends = Friend::getFriendList(Yii::$app->user->getId());
     if ($model->load(Yii::$app->request->post())) {
         if (!User::find()->where(['email' => $model->email])->exists()) {
             // if email not already registered
             //  create new user with temporary username & password
             $temp_email_arr[] = $model->email;
             $model->username = Inflector::slug(implode('-', $temp_email_arr));
             $model->password = Yii::$app->security->generateRandomString(12);
             $model->participant_id = $model->addUser();
         } else {
             // add participant from user record
             $usr = User::find()->where(['email' => $model->email])->one();
             $model->participant_id = $usr->id;
         }
         // validate the form against model rules
         if ($model->validate()) {
             // all inputs are valid
             $model->save();
             return $this->redirect(['/meeting/view', 'id' => $meeting_id]);
         } else {
             // validation failed
             return $this->render('create', ['model' => $model, 'title' => $title, 'friends' => $friends]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'title' => $title, 'friends' => $friends]);
     }
 }
Example #26
0
 public function actionIndex($callback, $id)
 {
     $model = NavItemPageBlockItem::findOne($id);
     $block = Block::objectId($model->block_id, $model->id, 'callback');
     $method = 'callback' . Inflector::id2camel($callback);
     return ObjectHelper::callMethodSanitizeArguments($block, $method, Yii::$app->request->get());
 }
Example #27
0
 public function getDetailUrl($contextNavItemId = null)
 {
     if ($contextNavItemId) {
         return \luya\helpers\Url::toModule($contextNavItemId, 'gallery/album/index', ['albumId' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
     }
     return \luya\helpers\Url::to('gallery/album/index', ['albumId' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
 }
 /**
  * Connector action
  */
 public function actionConnector()
 {
     /** @var ElFinderComponent $elFinder */
     $elFinder = Yii::$app->get('elFinder');
     $roots = array_map(function ($root) {
         /** @var Root $root */
         return $root->getOptions();
     }, $elFinder->roots);
     /** @var FilesystemComponent $filesystem */
     $filesystem = Yii::$app->get('filesystem');
     foreach ($elFinder->filesystems as $key => $root) {
         if (is_string($root)) {
             $key = $root;
             $root = [];
         }
         $fs = $filesystem->get($key);
         if ($fs instanceof Filesystem) {
             $defaults = ['driver' => 'Flysystem', 'filesystem' => $fs, 'alias' => Inflector::titleize($key)];
             $roots[] = array_merge($defaults, $root);
         }
     }
     $options = array('locale' => '', 'roots' => $roots);
     $connector = new \elFinderConnector(new \elFinder($options));
     $connector->run();
 }
Example #29
0
 public function getDetailUrl($contextNavItemId = null)
 {
     if ($contextNavItemId) {
         return \cms\helpers\Url::toMenuItem($contextNavItemId, 'news/default/detail', ['id' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
     }
     return \luya\helpers\Url::toManager('news/default/detail', ['id' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
 }
Example #30
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);
 }