当前位置: 首页>>代码示例>>PHP>>正文


PHP snake_case函数代码示例

本文整理汇总了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;
 }
开发者ID:CFLOVEYR,项目名称:hook,代码行数:60,代码来源:Router.php

示例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);
     }
 }
开发者ID:ericbarnes,项目名称:framework,代码行数:26,代码来源:PostTypeManager.php

示例3: getTitle

 public function getTitle($name)
 {
     $name = snake_case($name);
     $name = str_replace("_", " ", $name);
     $name = ucwords($name);
     return $name;
 }
开发者ID:howlowck,项目名称:settings-l4,代码行数:7,代码来源:Form.php

示例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);
 }
开发者ID:barooney,项目名称:laravel-slack-api,代码行数:7,代码来源:SlackApiServiceProvider.php

示例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}] 不存在!.");
 }
开发者ID:fifths,项目名称:lit,代码行数:7,代码来源:View.php

示例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);
 }
开发者ID:visualturk,项目名称:lexicon,代码行数:15,代码来源:View.php

示例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)]);
     }
 }
开发者ID:PovilasLT,项目名称:maze,代码行数:12,代码来源:2016_01_13_020302_change_notifiable_types.php

示例8: setNameAttribute

 public function setNameAttribute($value)
 {
     $this->attributes['name'] = $value;
     if (empty($this->username)) {
         $this->attributes['username'] = snake_case($value);
     }
 }
开发者ID:samwilson,项目名称:asset-manager,代码行数:7,代码来源:User.php

示例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))));
 }
开发者ID:adrian-fjellberg,项目名称:SimpleApi,代码行数:12,代码来源:ResourceModelTrait.php

示例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);
 }
开发者ID:zsping1989,项目名称:commands,代码行数:38,代码来源:CreateModels.php

示例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)));
 }
开发者ID:orangehill,项目名称:photon,代码行数:40,代码来源:MigrationGenerator.php

示例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);
 }
开发者ID:Qiang1234,项目名称:core,代码行数:30,代码来源:UserSearcher.php

示例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();
             }
         });
     });
 }
开发者ID:Smony,项目名称:njphoto,代码行数:25,代码来源:Plugin.php

示例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!');
 }
开发者ID:administrcms,项目名称:administr,代码行数:25,代码来源:MakeAdmin.php

示例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);
 }
开发者ID:lfalmeida,项目名称:lbase,代码行数:15,代码来源:BaseModel.php


注:本文中的snake_case函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。