Exemplo n.º 1
1
 /**
  * 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;
 }
Exemplo n.º 2
1
 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);
     }
 }
Exemplo n.º 3
1
 public function getTitle($name)
 {
     $name = snake_case($name);
     $name = str_replace("_", " ", $name);
     $name = ucwords($name);
     return $name;
 }
 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);
 }
Exemplo n.º 5
0
Arquivo: View.php Projeto: fifths/lit
 public function __call($method, $parameters)
 {
     if (starts_with($method, 'with')) {
         return $this->with(snake_case(substr($method, 4)), $parameters[0]);
     }
     throw new BadMethodCallException("方法 [{$method}] 不存在!.");
 }
Exemplo n.º 6
0
 /**
  * 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);
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     $notifications = Notification::all();
     foreach ($notifications as $notification) {
         $notification->update(['object_type' => snake_case($notification->object_type)]);
     }
 }
Exemplo n.º 8
0
 public function setNameAttribute($value)
 {
     $this->attributes['name'] = $value;
     if (empty($this->username)) {
         $this->attributes['username'] = snake_case($value);
     }
 }
 /**
  * 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))));
 }
Exemplo n.º 10
0
 /**
  * 基础数据分配
  */
 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);
 }
Exemplo n.º 11
0
 /**
  * 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)));
 }
Exemplo n.º 12
0
 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);
 }
Exemplo n.º 13
0
 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();
             }
         });
     });
 }
Exemplo n.º 14
0
 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!');
 }
Exemplo n.º 15
0
 /**
  * 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);
 }
Exemplo n.º 16
0
 function get_posted_records()
 {
     $record_set = $this->controller->params['ActiveRecord'];
     if (!$record_set) {
         return;
     }
     foreach ($record_set as $class_name => $object_set) {
         foreach ($object_set as $id => $updated_fields) {
             if (preg_match('/new-.*/', $id)) {
                 $obj = new $class_name();
                 $action = 'new';
             } else {
                 $obj = new $class_name($id);
                 $action = 'updated';
             }
             $obj->mergeData($updated_fields);
             $posted_record_collection = $action . '_' . snake_case(pluralize($class_name));
             if (!isset($this->controller->{$posted_record_collection})) {
                 $this->controller->{$posted_record_collection} = array();
             }
             $this->controller->posted_records[$class_name][$action][] = $obj;
             $this->controller->{$posted_record_collection}[] = $obj;
         }
     }
 }
Exemplo n.º 17
0
 public function fire()
 {
     // check if module exists
     if ($this->files->exists(app_path() . '/Modules/' . $this->getNameInput())) {
         return $this->error($this->type . ' already exists!');
     }
     // Create Controller
     //$this->generate('controller');
     // Create Model
     $this->generate('model');
     // Create Views folder
     $this->generate('view');
     // Create Config folder
     $this->generate('config');
     // Create Database folder
     $this->generate('database');
     // Create Http folder
     $this->generate('http');
     //Flag for no translation
     if (!$this->option('no-translation')) {
         // Create Translations folder
         $this->generate('translation');
     }
     // Create Routes file
     $this->generate('routes');
     if (!$this->option('no-migration')) {
         //$table = str_plural(snake_case(class_basename($this->argument('name'))));
         $table = snake_case(class_basename($this->argument('name')));
         $this->call('make:migration', ['name' => "create_{$table}_table", '--create' => $table, '--path' => '/app/Modules/' . $this->getNameInput() . '/Database/Migrations']);
     }
     $this->info($this->type . ' created successfully.');
 }
 protected function parseTables()
 {
     $this->tables = array_map(function ($arg) {
         return snake_case(str_singular($this->argument($arg)));
     }, ['model1', 'model2']);
     sort($this->tables);
 }
Exemplo n.º 19
0
 protected function getResourceParams($modelName, $i)
 {
     $i['name'] = snake_case($modelName);
     foreach (['hasMany', 'hasOne', 'belongsTo'] as $relation) {
         if (isset($i[$relation])) {
             $i[$relation] = $this->convertArray($i[$relation], ' ', ',');
         } else {
             $i[$relation] = false;
         }
     }
     if ($i['belongsTo']) {
         $relations = $this->getArgumentParser('relations')->parse($i['belongsTo']);
         foreach ($relations as $relation) {
             $foreignName = '';
             if (!$relation['model']) {
                 $foreignName = snake_case($relation['name']) . '_id';
             } else {
                 $names = array_reverse(explode("\\", $relation['model']));
                 $foreignName = snake_case($names[0]) . '_id';
             }
             $i['fields'][$foreignName] = ['schema' => 'integer', 'tags' => 'key'];
         }
     }
     $fields = [];
     foreach ($i['fields'] as $name => $value) {
         $value['name'] = $name;
         $fields[] = $this->serializeField($value);
     }
     $i['fields'] = implode(' ', $fields);
     return $i;
 }
Exemplo n.º 20
0
 public function article($category_slug, $slug)
 {
     $key = snake_case(class_basename($this) . '_' . __FUNCTION__ . '_' . $category_slug . '_' . $slug);
     if ($this->cache->has($key)) {
         $view = $this->cache->get($key);
     } else {
         $category = $this->category->where('slug', $category_slug)->first();
         $filters = [['name' => 'enabled', 'value' => 1], ['name' => 'slug', 'value' => $slug]];
         if (is_object($category)) {
             $category_id = $category->id;
             $filters[] = ['name' => 'category_id', 'value' => $category_id];
         }
         if ($this->cache->has($slug)) {
             $content = $this->cache->get($slug);
         } else {
             $content = $this->content->filterAll($filters);
             if ($content->count()) {
                 $content = $content->first();
             } else {
                 return redirect()->route('404');
             }
             $this->cache->put($slug, $content, 60);
         }
         $content->category = $category;
         $view = view('pages.content_show', compact('content'))->render();
     }
     return $view;
 }
Exemplo n.º 21
0
 /**
  * Set table name
  *
  * @param  string  $table
  *
  * @return self
  */
 private function setTable($table)
 {
     $this->table = strtolower($table);
     $this->migrationName = snake_case($this->table);
     $this->className = studly_case($this->migrationName);
     return $this;
 }
Exemplo n.º 22
0
 public function __call($method, $parameters)
 {
     if (starts_with($method, 'with')) {
         return $this->with(snake_case(substr($method, 4)), $parameters[0]);
     }
     throw new \BadMethodCallException("Function [{$method}] does not exist!");
 }
Exemplo n.º 23
0
function train_case($text)
{
    if (strpos($text, '_') === false) {
        $text = snake_case($text);
    }
    return str_replace(' ', '_', ucwords(str_replace('_', ' ', $text)));
}
Exemplo n.º 24
0
 private function formatTableName($model)
 {
     $model = $this->formatModelName($model);
     $model = snake_case($model);
     $model = strtolower($model);
     return $model = str_plural($model);
 }
Exemplo n.º 25
0
 protected function makeData(array $keys, array $data)
 {
     $result = [];
     foreach ($keys as $index => $value) {
         switch ($value) {
             case 'EstablishmentDate':
             case 'EstablishmentApprovalDate':
             case 'RegistrationApplicationDate':
             case 'RegistrationApprovalDate':
                 $result[snake_case($value)] = new \MongoDate(strtotime($data[$index]));
                 break;
             case 'Chairman':
             case 'Leadership':
                 $result[snake_case($value)] = $this->makeName($data[$index]);
                 break;
             case 'Contact':
                 $result[snake_case($value)] = $this->makePhone($data[$index]);
                 break;
             case 'ST_PCODE':
                 $result[$value] = $data[$index];
                 break;
             case 'DT_PCODE':
                 $result[$value] = $data[$index];
                 break;
             default:
                 $result[snake_case($value)] = $data[$index];
                 break;
         }
     }
     return $result;
 }
Exemplo n.º 26
0
 /**
  * Get the primary key for the model.
  *
  * @return string
  */
 public function getKeyName()
 {
     if (isset($this->primaryKey)) {
         return $this->primaryKey;
     }
     return 'id_' . str_replace('\\', '', snake_case(class_basename($this)));
 }
Exemplo n.º 27
0
 /**
  * Template URL helper
  * @param string $path
  * @param string $template
  * @return string
  */
 function template_url($path, $template = null)
 {
     $config = app('config');
     $template = $template ?: $config['app']['template'];
     $path = sprintf('templates/%s/assets/%s', snake_case($template), ltrim($path, '/'));
     return url($path);
 }
Exemplo n.º 28
0
 /**
  * Get the collection name associated with the model.
  *
  * @return string
  */
 public function getCollection()
 {
     if (isset($this->collection)) {
         return $this->collection;
     }
     return str_replace('\\', '', snake_case(str_plural(class_basename($this))));
 }
Exemplo n.º 29
0
 public function formatTokens($content)
 {
     $upperCaseModelName = ucfirst($this->modelName);
     $field_name = snake_case($this->modelName) . '_name';
     $modelId = $this->formatInstanceVariable() . '->id';
     $modelAttribute = $this->formatInstanceVariable() . '->' . $field_name;
     $createdAt = $this->formatInstanceVariable() . '->created_at';
     $modelRoute = '/' . $this->folderName;
     $dtTableName = snake_case($this->modelName) . '_table';
     $masterPage = $this->masterPage;
     $modelName = $this->modelName;
     $modelsUpperCase = ucwords(str_plural($this->modelName));
     $folderName = $this->folderName;
     $gridName = $this->formatVueGridName() . '-grid';
     $endGridName = '/' . $this->formatVueGridName() . '-grid';
     $vueApiRoute = 'api/' . $this->folderName . '-vue';
     $parent = $this->parent;
     $parentInstance = $this->formatParentInstanceVariable($this->parent);
     $parentInstances = $this->formatParents($this->parent);
     $parent_id = strtolower(snake_case($this->parent)) . '_id';
     $parentFieldName = strtolower(snake_case($this->parent)) . '_name';
     $child = $this->child;
     $slug = $this->slug;
     //create token array using compact
     $tokens = compact('upperCaseModelName', 'field_name', 'modelId', 'modelAttribute', 'createdAt', 'modelRoute', 'dtTableName', 'masterPage', 'modelName', 'modelsUpperCase', 'folderName', 'gridName', 'endGridName', 'vueApiRoute', 'parent', 'parentInstance', 'parentInstances', 'parent_id', 'parentFieldName', 'child', 'slug');
     $content = $this->insertTokensInContent($content, $tokens);
     return $content;
 }
 /**
  * Populate the name, options and path variables.
  *
  * @return void
  */
 protected function populateVars()
 {
     $this->placeholder['App'] = str_replace('/', '\\', $this->argument('app'));
     $this->placeholder['AppPath'] = str_replace('\\', '/', $this->placeholder['App']);
     $this->placeholder['Resource'] = $this->argument('resourceName');
     $this->placeholder['resource'] = str_replace('_', '-', strtolower(snake_case($this->placeholder['Resource'])));
     $this->placeholder['Resources'] = $this->option('rn-plural') ? $this->option('rn-plural') : str_plural($this->argument('resourceName'));
     $this->placeholder['resources'] = str_replace('_', '-', strtolower(snake_case($this->placeholder['Resources'])));
     $this->placeholder['NamespacePath'] = $this->option('namespace') ? $this->option('namespace') : $this->placeholder['AppPath'] . '/' . $this->placeholder['Resources'];
     $this->placeholder['Namespace'] = str_replace('/', '\\', $this->placeholder['NamespacePath']);
     $this->placeholder['isViewableResource'] = $this->option('is-viewable-resource') ? true : false;
     $this->placeholder['tests'] = $this->option('no-tests') ? false : true;
     $this->placeholder['views'] = $this->option('no-views') ? false : true;
     if ($this->option('contract-ext')) {
         if (preg_match('/\\\\|\\//', $this->option('contract-ext'))) {
             $this->placeholder['contractExt'] = str_replace('/', '\\', $this->option('contract-ext'));
             $this->placeholder['contract'] = substr($this->placeholder['contractExt'], strrpos($this->placeholder['contractExt'], '\\') + 1);
         } else {
             $this->placeholder['contractExt'] = $this->placeholder['App'] . '\\Contracts\\' . $this->option('contract-ext');
             $this->placeholder['contract'] = $this->option('contract-ext');
         }
     }
     if ($this->option('handler-imp')) {
         if (preg_match('/\\\\|\\//', $this->option('handler-imp'))) {
             $this->placeholder['handlerImp'] = str_replace('/', '\\', $this->option('handler-imp'));
             $this->placeholder['handler'] = substr($this->placeholder['handlerImp'], strrpos($this->placeholder['handlerImp'], '\\') + 1);
         } else {
             $this->placeholder['handlerImp'] = $this->placeholder['App'] . '\\Contracts\\' . $this->option('handler-imp');
             $this->placeholder['handler'] = $this->option('handler-imp');
         }
     }
 }