本文整理汇总了PHP中Illuminate\Support\Str::camel方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::camel方法的具体用法?PHP Str::camel怎么用?PHP Str::camel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Str
的用法示例。
在下文中一共展示了Str::camel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initVariables
public function initVariables()
{
$this->modelNamePlural = Str::plural($this->modelName);
$this->tableName = strtolower(Str::snake($this->modelNamePlural));
$this->modelNameCamel = Str::camel($this->modelName);
$this->modelNamePluralCamel = Str::camel($this->modelNamePlural);
$this->modelNamespace = Config::get('generator.namespace_model', 'App') . "\\" . $this->modelName;
}
示例2: generate
public function generate()
{
$templateData = $this->commandData->templatesHelper->getTemplate('Controller', 'api');
if ($this->commandData->pointerModel) {
$pointerRelationship = [];
foreach ($this->commandData->inputFields as $field) {
if ($field['type'] == 'pointer') {
$arr = explode(',', $field['typeOptions']);
if (count($arr) > 0) {
$modelName = $arr[0];
$pointerRelationship[] = "'" . Str::camel($modelName) . "'";
}
}
}
$templateData = str_replace('$POINTER_MODELS_RELATIONSHIP$', "with([" . implode(", ", $pointerRelationship) . "])->", $templateData);
} else {
$templateData = str_replace('$POINTER_MODELS_RELATIONSHIP$', '', $templateData);
}
$templateData = GeneratorUtils::fillTemplate($this->commandData->dynamicVars, $templateData);
$fileName = $this->commandData->modelName . 'APIController.php';
if (!file_exists($this->path)) {
mkdir($this->path, 0755, true);
}
$path = $this->path . $fileName;
$this->commandData->fileHelper->writeFile($path, $templateData);
$this->commandData->commandObj->comment("\nAPI Controller created: ");
$this->commandData->commandObj->info($fileName);
}
示例3: resolvePolicyCallback
/**
* Resolve the callback for a policy check.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param string $ability
* @param array $arguments
*
* @return callable
*/
protected function resolvePolicyCallback($user, $ability, array $arguments)
{
return function () use($user, $ability, $arguments) {
$instance = $this->getPolicyFor($arguments[0]);
if (method_exists($instance, 'before')) {
// We will prepend the user and ability onto the arguments so that the before
// callback can determine which ability is being called. Then we will call
// into the policy before methods with the arguments and get the result.
$beforeArguments = array_merge([$user, $ability], $this->getPolicyArguments($arguments));
$result = call_user_func_array([$instance, 'before'], $beforeArguments);
// If we received a non-null result from the before method, we will return it
// as the result of a check. This allows developers to override the checks
// in the policy and return a result for all rules defined in the class.
if (!is_null($result)) {
return $result;
}
}
if (strpos($ability, '-') !== false) {
$ability = Str::camel($ability);
}
if (!is_callable([$instance, $ability])) {
return false;
}
return call_user_func_array([$instance, $ability], array_merge([$user], $this->getPolicyArguments($arguments)));
};
}
示例4: createNewPolicies
/**
* Creates the new policies for the rest config.
* @param array $mappedPolicies
* @return array The first element are the new class usages and the second element is the policy mapping.
* @throws Exception
*/
public function createNewPolicies(array $mappedPolicies)
{
$appNamespace = $this->getAppNamespace();
$config = $this->getConfig();
$newUsages = [];
foreach (@$config['tables'] ?: [] as $table => $tableConfig) {
$policyName = Str::ucfirst(Str::camel($table)) . 'Policy';
$className = preg_replace('/(\\w+\\\\)+/', '', $tableConfig['model']);
$classCall = $className . '::class';
if (!class_exists($fullPolicyName = $appNamespace . '\\Policies\\' . $policyName)) {
if (Artisan::call('make:policy', ['name' => $policyName])) {
throw new Exception('Could not write ' . $policyName);
}
// if
app(File::class, [$policyFile = app_path("Policies/{$policyName}.php")])->setContent(str_replace([' }', "\nclass "], [" }\n{$this->getPolicyMethods($table)}", "use {$tableConfig['model']};\n\nclass "], file_get_contents($policyFile)))->save();
}
// if
if (!array_key_exists($classCall, $mappedPolicies)) {
$newUsages = array_merge($newUsages, [$tableConfig['model'], str_replace('\\\\', '\\', $fullPolicyName)]);
$mappedPolicies[$className . '::class'] = $policyName . '::class';
}
// if
}
return array($newUsages, $mappedPolicies);
}
示例5: generateRelations
private function generateRelations()
{
if ($this->commandData->tableName == '') {
return '';
}
$code = '';
//Get what tables it belongs to
$relations = DataBaseHelper::getForeignKeysFromTable($this->commandData->tableName);
foreach ($relations as $r) {
$referencedTableName = preg_replace("/{$this->prefix}/uis", '', $r->REFERENCED_TABLE_NAME);
$referencedTableName = ucfirst(Str::camel(StringUtils::singularize($referencedTableName)));
$code .= " public function " . $referencedTableName . "() {\n";
$code .= " " . 'return $this->belongsTo(' . "'\$NAMESPACE_MODEL\$\\" . $referencedTableName . "', '" . $r->COLUMN_NAME . "'); \n";
$code .= " }\n\n";
}
//Get what tables it is referenced
$relations = DataBaseHelper::getReferencesFromTable($this->commandData->tableName);
foreach ($relations as $r) {
$tableName = preg_replace("/{$this->prefix}/uis", '', $r->TABLE_NAME);
$tableName = ucfirst(Str::camel(StringUtils::singularize($tableName)));
$code .= " public function " . Str::plural($tableName) . "() {\n";
$code .= " " . 'return $this->hasMany(' . "'\$NAMESPACE_MODEL\$\\" . $tableName . "', '" . $r->COLUMN_NAME . "'); \n";
$code .= " }\n\n";
}
return $code;
}
示例6: __construct
/**
* Construct with attributes
*
* @param array $attributes
*/
public function __construct(array $attributes = [])
{
if (isset($attributes['attributes'])) {
$attributes['attributes'] = new Attributes($attributes['attributes']);
}
// normalize relationship names to camel case
if (isset($attributes['relationships'])) {
foreach ($attributes['relationships'] as $name => $relationship) {
$normalizedName = Str::camel($name);
$attributes['relationships'][$normalizedName] = new Relationship($relationship);
if ($normalizedName === $name) {
continue;
}
unset($attributes['relationships'][$name]);
}
}
if (isset($attributes['links'])) {
foreach ($attributes['links'] as $key => $link) {
$attributes['links'][$key] = new Link($link);
}
}
if (isset($attributes['meta'])) {
$attributes['meta'] = new Meta($attributes['meta']);
}
parent::__construct($attributes);
}
示例7: initVariables
public function initVariables()
{
$this->modelNamePlural = Str::plural($this->modelName);
$this->modelNameCamel = Str::camel($this->modelName);
$this->modelNamePluralCamel = Str::camel($this->modelNamePlural);
$this->initDynamicVariables();
}
示例8: initValidator
protected function initValidator()
{
$class = $this->getValidatorClass();
if ($class) {
$validator = new $class();
$this->validator_messages = $validator->messages();
$this->validator_rules = $validator->rules();
foreach ($this->validator_rules as $element_name => $element_rules) {
if (false !== mb_strpos($element_name, '.')) {
$element_name = str_replace('.', '][', $element_name) . ']';
$e = explode(']', $element_name, 2);
$element_name = implode('', $e);
}
foreach ($this->getElementsByName($element_name) as $el) {
$element_rules = explode('|', $element_rules);
foreach ($element_rules as $rule) {
$_rule = explode(':', $rule);
$rule_name = Arr::get($_rule, 0);
$rule_params = Arr::get($_rule, 1);
$rule_params = explode(',', $rule_params);
$method = Str::camel('rule_' . $rule_name);
if (method_exists($el, $method)) {
call_user_func_array([$el, $method], $rule_params);
}
}
}
}
}
return $this;
}
示例9: testDtoApply
/**
* @param $cars
* @depends testArrayApply
*/
public function testDtoApply($cars)
{
$model = Cars::make($cars);
$this->assertEquals(count($this->data), count($model->toArray()));
foreach ($this->data as $key => $value) {
$this->assertEquals($value, $model->toArray()[Str::camel($key)]);
}
}
示例10: getFilters
/**
* {@inheritDoc}
*/
public function getFilters()
{
return array(new \Twig_SimpleFilter('camel_case', array('Illuminate\\Support\\Str', 'camel'), array('is_safe' => array('html'))), new \Twig_SimpleFilter('snake_case', array('Illuminate\\Support\\Str', 'snake'), array('is_safe' => array('html'))), new \Twig_SimpleFilter('studly_case', array('Illuminate\\Support\\Str', 'studly'), array('is_safe' => array('html'))), new \Twig_SimpleFilter('str_*', function ($name) {
$arguments = array_slice(func_get_args(), 1);
$name = Str::camel($name);
return call_user_func_array(array('Illuminate\\Support\\Str', $name), $arguments);
}, array('is_safe' => array('html'))));
}
示例11: getFunctions
/**
* {@inheritDoc}
*/
public function getFunctions()
{
return [new Twig_SimpleFunction('link_to', [$this->html, 'link'], ['is_safe' => ['html']]), new Twig_SimpleFunction('link_to_asset', [$this->html, 'linkAsset'], ['is_safe' => ['html']]), new Twig_SimpleFunction('link_to_route', [$this->html, 'linkRoute'], ['is_safe' => ['html']]), new Twig_SimpleFunction('link_to_action', [$this->html, 'linkAction'], ['is_safe' => ['html']]), new Twig_SimpleFunction('html_*', function ($name) {
$arguments = array_slice(func_get_args(), 1);
$name = Str::camel($name);
return call_user_func_array([$this->html, $name], $arguments);
}, ['is_safe' => ['html']])];
}
示例12: getFunctions
/**
* {@inheritDoc}
*/
public function getFunctions()
{
return [new Twig_SimpleFunction('asset', [$this->url, 'asset'], ['is_safe' => ['html']]), new Twig_SimpleFunction('action', [$this->url, 'action'], ['is_safe' => ['html']]), new Twig_SimpleFunction('url', [$this, 'url'], ['is_safe' => ['html']]), new Twig_SimpleFunction('route', [$this->url, 'route'], ['is_safe' => ['html']]), new Twig_SimpleFunction('route_has', [$this->router, 'has'], ['is_safe' => ['html']]), new Twig_SimpleFunction('secure_url', [$this->url, 'secure'], ['is_safe' => ['html']]), new Twig_SimpleFunction('secure_asset', [$this->url, 'secureAsset'], ['is_safe' => ['html']]), new Twig_SimpleFunction('url_*', function ($name) {
$arguments = array_slice(func_get_args(), 1);
$name = IlluminateStr::camel($name);
return call_user_func_array([$this->url, $name], $arguments);
})];
}
示例13: handle
/**
* @param Event $event
*/
public function handle(Event $event)
{
$cloneModel = $this->clone->find($event->request['clone_id']);
$group = $this->group->find($event->request['group_id']);
$sitePath = Str::camel($event->request['name']);
$event->site->updateStatus('Cloning the repo');
$this->envoy->run('clone --path="' . $group->starting_path . '" --name="' . $sitePath . '" --url=' . $cloneModel->url, true);
}
示例14: getFilters
/**
* {@inheritDoc}
*/
public function getFilters()
{
return [new Twig_SimpleFilter('camel_case', [$this->callback, 'camel']), new Twig_SimpleFilter('snake_case', [$this->callback, 'snake']), new Twig_SimpleFilter('studly_case', [$this->callback, 'studly']), new Twig_SimpleFilter('str_*', function ($name) {
$arguments = array_slice(func_get_args(), 1);
$name = IlluminateStr::camel($name);
return call_user_func_array([$this->callback, $name], $arguments);
})];
}
示例15: handle
/**
* @param Event $event
*/
public function handle(Event $event)
{
$event->site->updateStatus('Running the installer');
$installerType = $event->request['installType'] == 'base' ? null : '"--' . $event->request['installType'] . '"';
$group = $this->group->find($event->request['group_id']);
$sitePath = Str::camel($event->request['name']);
$this->envoy->run('make-site --path="' . $group->starting_path . '" --name="' . $sitePath . '" --type=' . $installerType, true);
}