本文整理汇总了PHP中snake_case函数的典型用法代码示例。如果您正苦于以下问题:PHP snake_case函数的具体用法?PHP snake_case怎么用?PHP snake_case使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snake_case函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mount
/**
* Bind controller methods into a path
*
* @param string $path
* @param string $controller_klass
*
* @example
*
* class MyController {
* // Mount callback
* public static function mounted($path) {
* var_dump("Successfully mounted at " . $path);
* }
*
* // GET /path
* function getIndex() {}
*
* // POST /path/create
* function postCreate() {}
*
* // PUT /path/update
* function putUpdate() {}
*
* // DELETE /path
* function deleteIndex() {}
* }
* Hook\Http\Router::mount('/', 'MyController');
*
*/
public static function mount($path, $controller_klass)
{
$mounted = null;
$methods = get_class_methods($controller_klass);
// skip
if (!$methods) {
debug("'{$controller_klass}' has no methods.");
return;
}
foreach ($methods as $method_name) {
// skip invalid methods
if ($method_name == '__construct') {
continue;
}
// call 'mounted' method
if ($method_name == 'mounted') {
$mounted = call_user_func(array($controller_klass, 'mounted'), $path);
continue;
}
preg_match_all('/^(get|put|post|patch|delete)(.*)/', $method_name, $matches);
$has_matches = count($matches[1]) > 0;
$http_method = $has_matches ? $matches[1][0] : 'any';
$route_name = $has_matches ? $matches[2][0] : $method_name;
$route = str_finish($path, '/');
if ($route_name !== 'index') {
$route .= snake_case($route_name);
}
static::$instance->{$http_method}($route, "{$controller_klass}:{$method_name}");
}
return $mounted;
}
示例2: makeCustomPostType
protected function makeCustomPostType(Post $model)
{
$postTypeSlug = strtolower(snake_case(class_basename($model)));
if ($model instanceof CustomPostType) {
$singular = property_exists($model, 'singular') ? $model->singular : str_replace(['-', '_'], ' ', $postTypeSlug);
$plural = property_exists($model, 'plural') ? $model->plural : str_plural(str_replace(['-', '_'], ' ', $postTypeSlug));
$postTypeData = $model->customPostTypeData();
if (!is_array($postTypeData)) {
$postTypeData = [];
}
$result = register_post_type($postTypeSlug, $this->buildPostTypeData($singular, $plural, $postTypeData));
if (!$result instanceof \WP_Error) {
$this->postTypes[$postTypeSlug] = get_class($model);
if (property_exists($model, 'placeholderText')) {
add_filter('enter_title_here', function ($default) use($postTypeSlug, $model) {
if ($postTypeSlug == get_current_screen()->post_type) {
$default = $model->placeholderText;
}
return $default;
});
}
}
} else {
$this->postTypes[$postTypeSlug] = get_class($model);
}
}
示例3: getTitle
public function getTitle($name)
{
$name = snake_case($name);
$name = str_replace("_", " ", $name);
$name = ucwords($name);
return $name;
}
示例4: registerSlackMethod
public function registerSlackMethod($name)
{
$contract = str_finish($this->contractsNamespace, "\\") . "Slack{$name}";
$shortcut = $this->shortcutPrefix . snake_case($name);
$class = str_finish($this->methodsNamespace, "\\") . $name;
$this->registerSlackSingletons($contract, $class, $shortcut);
}
示例5: __call
public function __call($method, $parameters)
{
if (starts_with($method, 'with')) {
return $this->with(snake_case(substr($method, 4)), $parameters[0]);
}
throw new BadMethodCallException("方法 [{$method}] 不存在!.");
}
示例6: __call
/**
* Dynamically bind parameters to the view.
*
* @param string $method
* @param array $parameters
* @return View
* @throws \BadMethodCallException
*/
public function __call($method, $parameters)
{
if (starts_with($method, 'using')) {
return $this->using(snake_case(substr($method, 5)));
}
return parent::__call($method, $parameters);
}
示例7: down
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$notifications = Notification::all();
foreach ($notifications as $notification) {
$notification->update(['object_type' => snake_case($notification->object_type)]);
}
}
示例8: setNameAttribute
public function setNameAttribute($value)
{
$this->attributes['name'] = $value;
if (empty($this->username)) {
$this->attributes['username'] = snake_case($value);
}
}
示例9: getResourceName
/**
* Get the resource name associated with the model.
*
* @return string
*/
public function getResourceName()
{
if (isset($this->resourceName)) {
return $this->resourceName;
}
return str_replace('\\', '', snake_case(str_plural(class_basename($this))));
}
示例10: initData
/**
* 基础数据分配
*/
protected function initData()
{
//使用数据准备
$data['php'] = '<?php';
$data['name'] = $this->parseName($this->getNameInput());
$data['namespace'] = $this->getNamespace($data['name']);
$data['class'] = str_replace($data['namespace'] . '\\', '', $data['name']);
$data['table'] = $this->argument('table') ?: '';
//数据表名称
//选项
$data['tree'] = $this->option('tree');
//树状结构选项
$data['softDeletes'] = $this->option('softDeletes');
//软删除模式选项
if ($data['fields'] = $this->option('fields')) {
//字段生成
$tableInfo = $this->getTableInfo($data['table'] ?: snake_case($data['class']) . 's');
$this->withData($tableInfo);
$data['dates'] = $tableInfo['table_fields']->filter(function ($item) {
return $item->showType == 'time' || in_array($item->Field, ['deleted_at', 'created_at', 'updated_at']);
})->pluck('Field')->implode("','");
$data['dates'] = $data['dates'] ? "'" . $data['dates'] . "'" : '';
//隐藏输出字段
$data['delete'] = $tableInfo['table_fields']->filter(function ($item) {
return $item->showType == 'delete' || in_array($item->Field, ['deleted_at']);
})->pluck('Field');
//批量赋值字段
$data['fillable'] = $tableInfo['table_fields']->pluck('Field')->diff($data['delete']->merge(['level', 'left_margin', 'right_margin', 'created_at', 'updated_at'])->all())->implode("','");
$data['fillable'] = $data['fillable'] ? "'" . $data['fillable'] . "'" : '';
$data['delete'] = $data['delete']->implode("','");
$data['delete'] = $data['delete'] ? "'" . $data['delete'] . "'" : '';
//dd($tableInfo);
}
$this->withData($data);
}
示例11: createMigrationName
/**
* Creates a migration name based on input parameters
*
* @param string $command
* @param string $table
* @param array $fields
*
* @return string
* @throws MigrationException
* @see Orangehill\Photon\MigrationGenerator\MigrationGeneratorTest::testMigrationNameCreation
* @see Orangehill\Photon\MigrationGenerator\MigrationGeneratorTest::testMigrationNameException
*/
public static function createMigrationName($command, $table, array $fields = array())
{
$key = self::parseFieldsToMigrationKey($fields);
$table = (string) $table;
$command = (string) $command;
$name = '';
switch ($command) {
case 'create':
$name = "create_{$table}_table";
break;
case 'add':
$name = "add_{$key}";
$name .= $table ? "_to_{$table}_table" : '';
break;
case 'remove':
$name = "remove_{$key}";
$name .= $table ? "_from_{$table}_table" : '';
break;
case 'delete':
case 'destroy':
$name = "destroy_{$table}_table";
break;
default:
throw new MigrationException("Migration method `{$command}` does not exist");
break;
}
return str_replace('__', '_', snake_case(str_replace('-', '_', $name)));
}
示例12: search
public function search(UserSearchCriteria $criteria, $limit = null, $offset = 0, $load = [])
{
$this->user = $criteria->user;
$this->query = $this->users->query()->whereCan($criteria->user, 'view');
$this->gambits->apply($criteria->query, $this);
$total = $this->query->count();
$sort = $criteria->sort ?: $this->defaultSort;
foreach ($sort as $field => $order) {
if (is_array($order)) {
foreach ($order as $value) {
$this->query->orderByRaw(snake_case($field) . ' != ?', [$value]);
}
} else {
$this->query->orderBy(snake_case($field), $order);
}
}
if ($offset > 0) {
$this->query->skip($offset);
}
if ($limit > 0) {
$this->query->take($limit + 1);
}
event(new UserSearchWillBePerformed($this, $criteria));
$users = $this->query->get();
if ($limit > 0 && ($areMoreResults = $users->count() > $limit)) {
$users->pop();
}
$users->load($load);
return new UserSearchResults($users, $areMoreResults, $total);
}
示例13: boot
public function boot()
{
FileBase::extend(function ($model) {
$model->hasOne['exif'] = ['Hambern\\Exify\\Models\\Exif', 'delete' => true];
});
FileBase::extend(function ($model) {
$model->bindEvent('model.afterCreate', function () use($model) {
if (strpos($model->content_type, 'image') !== false) {
$reader = Reader::factory(Reader::TYPE_NATIVE);
$path = 'http://' . $_SERVER['SERVER_NAME'] . $model->path;
$data = $reader->read($path)->getData();
foreach ($data as $k => $v) {
$fill[snake_case($k)] = $v;
}
$exif = Exif::make($fill);
$model->exif()->save($exif);
}
});
$model->bindEvent('model.beforeDelete', function () use($model) {
if (strpos($model->content_type, 'image') !== false) {
$model->exif()->delete();
}
});
});
}
示例14: handle
public function handle()
{
$name = trim($this->argument('name'));
$nameSingular = str_singular($name);
$status = 0;
$controllerCmdArgs = ['name' => "{$name}Controller"];
if ($this->option('translated')) {
$controllerCmdArgs['--translated'] = true;
}
$status = $this->call('administr:controller', $controllerCmdArgs);
$status = $this->call('administr:form', ['name' => "{$nameSingular}Form"]);
$modelCmdArgs = ['name' => $nameSingular];
if ($this->option('translated')) {
$modelCmdArgs['--translated'] = true;
}
$status = $this->call('administr:model', $modelCmdArgs);
$status = $this->call('administr:listview', ['name' => "{$name}ListView"]);
$status = $this->call('make:seed', ['name' => "{$name}Seeder"]);
$table = str_plural(snake_case(class_basename($name)));
$status = $this->call('make:migration', ['name' => "create_{$table}_table", '--create' => $table]);
if ($status !== 0) {
$this->error('Some of the commands were not executed successfuly.');
}
$this->info('Admin scaffold generated!');
}
示例15: setAttribute
/**
* Mantém a compatibilidade com snake_case ao definir atributos
*
* @param string $key
* @param mixed $value
*
*
*/
public function setAttribute($key, $value)
{
$key = snake_case($key);
$value = empty($value) ? null : $value;
$value = is_string($value) ? trim($value) : $value;
return parent::setAttribute($key, $value);
}