本文整理汇总了PHP中yii\helpers\Inflector类的典型用法代码示例。如果您正苦于以下问题:PHP Inflector类的具体用法?PHP Inflector怎么用?PHP Inflector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Inflector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (!$this->header) {
$this->header = "<h2>" . Inflector::camel2words($this->model->formName()) . " change log:</h2>";
}
}
示例2: getViewPath
/**
* 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());
}
示例3: callback
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);
}
}
示例4: bOrderAttr
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;
}
示例5: getColumnHeader
/**
* @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;
}
示例6: callback
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);
}
}
示例7: render
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;
*/
}
示例8: renderDataCellContent
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);
}
示例9: actionIndex
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);
}
示例10: wp_get_nav_menu_object
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);
}
示例11: actionIndex
/**
* 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;
}
}
示例12: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if ($this->action === null) {
$this->action = Inflector::id2camel($this->id);
}
}
示例13: init
/**
* @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'];
}
}
示例14: getAttributeOrders
/**
* 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;
}
示例15: getView
public function getView()
{
if ($this->_view === null) {
$this->_view = lcfirst(Inflector::id2camel($this->id));
}
return $this->_view;
}