php yii-helpers-Inflector类(方法)实例源码

下面列出了php yii-helpers-Inflector 类(方法)源码代码实例,从而了解它的用法。

作者:cranky    项目:change-log-behavio   
/**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (!$this->header) {
         $this->header = "<h2>" . Inflector::camel2words($this->model->formName()) . " change log:</h2>";
     }
 }

作者:luyade    项目:luya-cor   
/**
  * 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());
 }

作者:LexxanderDrea    项目:yii2-amq   
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);
     }
 }

作者:omidoni    项目:yii2-sortable-behavio   
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;
 }

作者:ericmaico    项目:yii2-expor   
/**
  * @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;
 }

作者:vstahee    项目:yii2-amq   
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);
     }
 }

作者:rocksolid-t    项目:luy   
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;
     */
 }

作者:vsgut    项目:cr   
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);
 }

作者:cj    项目:yii2-playgroun   
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);
 }

作者:AppItNetwor    项目:yii2-wordpress-theme   
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);
}

作者:nathanpha    项目:yii2-gii   
/**
  * 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;
     }
 }

作者:sangki    项目:applicatio   
/**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->action === null) {
         $this->action = Inflector::id2camel($this->id);
     }
 }

作者:mdmsof    项目:yii2-widget   
/**
  * @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'];
     }
 }

作者:portalsway    项目:APEDevice   
/**
  * 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;
 }

作者:hiqde    项目:hipanel-cor   
public function getView()
 {
     if ($this->_view === null) {
         $this->_view = lcfirst(Inflector::id2camel($this->id));
     }
     return $this->_view;
 }

作者:iisn    项目:yii2-simplemde-markdow   
/**
  * 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);
 }

作者:vykhrystiu    项目:yii2-filter-ta   
/**
  * @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;
 }

作者:just-le    项目:cardgame-seria   
/**
  * @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)) . '}}';
 }

作者:bscheshirwor    项目:yii2-hiar   
/**
  * 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);
 }

作者:yii2tec    项目:csv-gri   
/**
  * @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;
 }


问题


面经


文章

微信
公众号

扫码关注公众号