本文整理汇总了PHP中yii\helpers\Inflector::camelize方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::camelize方法的具体用法?PHP Inflector::camelize怎么用?PHP Inflector::camelize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Inflector
的用法示例。
在下文中一共展示了Inflector::camelize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
示例2: 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);
}
}
示例3: 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;
}
}
示例4: getLabel
/**
* @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;
}
示例5: setBlockName
/**
* Setter method for $blockName, ensure the correct block name.
*
* @param string $name The name of the block.
*/
public function setBlockName($name)
{
if (!StringHelper::endsWith($name, 'Block')) {
$name .= 'Block';
}
$this->_blockName = Inflector::camelize($name);
}
示例6: createClassName
/**
* Generates a class name with camelcase style and specific suffix, if not already provided
*
* @param string $string The name of the class, e.g.: hello_word would
* @param string $suffix The suffix to append on the class name if not eixsts, e.g.: MySuffix
* @return string The class name e.g. HelloWorldMySuffix
* @since 1.0.0-beta4
*/
public function createClassName($string, $suffix = false)
{
$name = Inflector::camelize($string);
if ($suffix && StringHelper::endsWith($name, $suffix, false)) {
$name = substr($name, 0, -strlen($suffix));
}
return $name . $suffix;
}
示例7: params
/**
* get link parameters for menu access
*
* @param String $name
* @param Array $options
* @return Array
*/
static function params($name = '', $options = ['url' => '#'])
{
$method = 'params' . Inflector::camelize($name);
if (method_exists(static::className(), $method)) {
return ArrayHelper::merge(static::$method(), $options);
}
return $options;
}
示例8: callbackButton
/**
*
* @param string $value The name/value of the button to display for the user.
* @param string $callback The id of the callback if the callback method s name is `callbackSayHello` the callback id would be `say-hello`.
* @param array $options Define behavior of the button, options are name-value pairs. The following options are available:
*
* - params: array, Add additional parameters which will be sent to the callback. ['foo' => 'bar']
* - closeOnSuccess: boolean, if enabled, the active window will close after successfully sendSuccess() response from callback.
* - reloadListOnSuccess: boolean, if enabled, the active window will reload the ngrest crud list after success response from callback via sendSuccess().
* - reloadWindowOnSuccess: boolena, if enabled the active window will reload itself after success (when successResponse is returnd).
* - class: string, html class fur the button
* @return string
*/
public function callbackButton($value, $callback, array $options = [])
{
// do we have option params for the button
$params = array_key_exists('params', $options) ? $options['params'] : [];
// create the angular controller name
$controller = 'Controller' . Inflector::camelize($value) . Inflector::camelize($callback);
// render and return the view with the specific params
return $this->render('@admin/views/aws/base/_callbackButton', ['angularCrudControllerName' => $controller, 'callbackName' => $this->callbackConvert($callback), 'callbackArgumentsJson' => Json::encode($params), 'buttonNameValue' => $value, 'closeOnSuccess' => isset($options['closeOnSuccess']) ? '$scope.crud.closeActiveWindow();' : null, 'reloadListOnSuccess' => isset($options['reloadListOnSuccess']) ? '$scope.crud.loadList();' : null, 'reloadWindowOnSuccess' => isset($options['reloadWindowOnSuccess']) ? '$scope.$parent.activeWindowReload();' : null, 'buttonClass' => isset($options['class']) ? $options['class'] : 'btn']);
}
示例9: validateAttribute
/**
* @inheritdoc
*/
public function validateAttribute($model, $attribute)
{
$this->model = $this->model ?: $model;
$method = Inflector::camelize(str_replace('_id', '', $attribute) . 'List');
$list = $this->list === null ? array_keys($this->model->{$method}()) : $this->list;
$result = is_array($model->{$attribute}) ? !array_diff($model->{$attribute}, $list) : in_array($model->{$attribute}, $list);
if (!$result) {
$this->addError($model, $attribute, $this->message ?: \Yii::t('app', 'Forbidden value'));
}
}
示例10: validateName
public function validateName($attribute)
{
$name = Inflector::camelize(Inflector::slug($this->{$attribute}));
$label = $this->getAttributeLabel($attribute);
if (empty($name)) {
$this->addError($attribute, "'{$label}' должно состоять только из букв и цифр");
} else {
$this->{$attribute} = $name;
}
}
示例11: webhook
public function webhook($data)
{
if (!empty($data['event'])) {
$method = lcfirst(Inflector::camelize($data['event']));
if (method_exists($this, $method)) {
return $this->{$method}($data);
}
}
return false;
}
示例12: actionExists
/**
* Checks whether action with specified ID exists in owner controller.
* @param string $id action ID.
* @return boolean whether action exists or not.
*/
public function actionExists($id)
{
$inlineActionMethodName = 'action' . Inflector::camelize($id);
if (method_exists($this->controller, $inlineActionMethodName)) {
return true;
}
if (array_key_exists($id, $this->controller->actions())) {
return true;
}
return false;
}
示例13: actionHandleWebhook
/**
* Processing Stripe's callback and making membership updates according to payment data
*
* @return void|Response
*/
public function actionHandleWebhook()
{
$payload = json_decode(Yii::$app->request->getRawBody(), true);
if (!$this->eventExistsOnStripe($payload['id'])) {
return;
}
$method = 'handle' . Inflector::camelize(str_replace('.', '_', $payload['type']));
if (method_exists($this, $method)) {
return $this->{$method}($payload);
} else {
return $this->missingMethod();
}
}
示例14: actionExists
/**
* Verify that the action requested is actually an action on the controller
* @param string $action
* @return bool
*/
protected function actionExists($action)
{
try {
$reflection = new \ReflectionClass($this->controller);
if ($reflection->getMethod('action' . Inflector::camelize($action))) {
return true;
}
} catch (\ReflectionException $e) {
//method does not exist
return false;
}
return false;
}
示例15: callbackButton
/**
*
* @param string $value The name/value of the button to display for the user.
* @param string $callback The id of the callback if the callback method s name is `callbackSayHello` the callback id would be `say-hello`.
* @param array $params Additional json parameters to send to the callback.
* @param array $options Define behavior of the button, optionas are name-value pairs. The following options are available:
*
* - closeOnSuccess: boolean, if enabled, the active window will close after successfully sendSuccess() response from callback.
* - reloadListOnSuccess: boolean, if enabled, the active window will reload the ngrest crud list after success response from callback via sendSuccess().
*
* @return string
*/
public function callbackButton($value, $callback, array $params = [], array $options = [])
{
$json = Json::encode($params);
$controller = 'Controller' . Inflector::camelize($value) . Inflector::camelize($callback);
$callback = $this->callbackConvert($callback);
$closeOnSuccess = null;
if (isset($options['closeOnSuccess'])) {
$closeOnSuccess .= '$scope.crud.closeActiveWindow();';
}
$reloadListOnSuccess = null;
if (isset($options['reloadListOnSuccess'])) {
$reloadListOnSuccess = '$scope.crud.loadList();';
}
$return = '<script>
zaa.bootstrap.register(\'' . $controller . '\', function($scope, $controller) {
$scope.crud = $scope.$parent;
$scope.params = ' . $json . ';
$scope.sendButton = function(callback) {
$scope.crud.sendActiveWindowCallback(callback, $scope.params).then(function(success) {
var data = success.data;
var errorType = null;
var message = false;
if ("error" in data) {
errorType = data.error;
}
if ("message" in data) {
message = data.message;
}
if (errorType !== null) {
if (errorType == true) {
$scope.crud.toast.error(message, 8000);
} else {
$scope.crud.toast.success(message, 8000);
' . $closeOnSuccess . $reloadListOnSuccess . '
}
}
}, function(error) {
$scope.crud.toast.error(error.data.message, 8000);
});
};
});
</script>
<div ng-controller="' . $controller . '">
<button ng-click="sendButton(\'' . $callback . '\')" class="btn" type="button">' . $value . '</button>
</div>';
return $return;
}