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;
 }
 /**
  * {@inheritdoc}
  */
 protected function getSizeMessage($attribute, $rule)
 {
     $lowerRule = Str::snake($rule);
     $type = $this->getAttributeType($attribute);
     $key = "validation.{$lowerRule}.{$type}";
     return $this->translator->get($key);
 }
示例#3
0
 /**
  * Create migration file if not null
  *
  * @param $option
  */
 private function makeMigration($option)
 {
     if ($option) {
         $table = Str::plural(Str::snake(class_basename($this->argument('name'))));
         $this->call('make:migration', ['name' => "create_{$table}_table", '--create' => $table]);
     }
 }
示例#4
0
 /**
  * Get the package namespace.
  *
  * @return string
  */
 public function getNamespace()
 {
     $namespace = str_replace('\\', '/', get_class($this));
     $namespace = Str::snake(basename($namespace));
     $namespace = str_replace('_', '-', $namespace);
     return $namespace;
 }
示例#5
0
 /**
  * 系统的默认表名会将类名变为复数,如 org 将会变为 orgs;
  * 复写该类取消这一功能,声明 Model 时将类名与表名保持一致即可
  */
 public function getTable()
 {
     if (isset($this->table)) {
         return $this->table;
     }
     return str_replace('\\', '', Str::snake(class_basename($this)));
 }
示例#6
0
 /**
  * Get the default foreign key name for the model.
  *
  * @return string
  */
 public function getForeignKey()
 {
     if (empty($this->foreignKey)) {
         return Str::snake(class_basename($this)) . '_id';
     }
     return $this->foreignKey;
 }
示例#7
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $model = ucfirst(strtolower($this->argument('model')));
     $models = Str::plural($model);
     $table = strtolower(Str::snake($models));
     $modelsLower = strtolower($models);
     $fields = $this->getInputFields();
     $modelGen = Generator::get('model')->make(['name' => $model, 'namespace' => 'App\\Models', 'table' => $table, 'fields' => $fields]);
     $this->info("\nModel Created:");
     $this->comment($modelGen);
     $controllerGen = Generator::get('controller')->make(['name' => $model, 'namespace' => 'App\\Http\\Controllers', 'modelsLower' => $modelsLower]);
     $this->info("\nController Created:");
     $this->comment($controllerGen);
     $this->info("\nRoute Added:");
     $this->comment($modelsLower);
     //        $viewGen = Generator::get('view')->make([
     //            'name' => $model,
     //            'modelsLower' => $modelsLower,
     //            'models' => $models,
     //        ]);
     //        $this->info("\nView Created :");
     //        $this->comment($modelsLower);
     $migrationGen = Generator::get('migration')->make(['models' => $models, 'table' => $table, 'fields' => $fields]);
     $this->info("\nMigration Created:");
     $this->comment($migrationGen);
     $formGen = Generator::get('form')->make(['name' => $model, 'models' => $models, 'fields' => $fields, 'namespace' => 'App\\Forms']);
     $this->info("\nForm Created:");
     $this->comment($formGen);
 }
示例#8
0
 /**
  * Send the given notification.
  *
  * @param  mixed  $notifiable
  * @param  \Illuminate\Notifications\Notification  $notification
  * @return void
  */
 public function send($notifiable, Notification $notification)
 {
     if (!$notifiable->routeNotificationFor('mail')) {
         return;
     }
     $message = $notification->toMail($notifiable);
     if ($message instanceof Mailable) {
         return $message->send($this->mailer);
     }
     $this->mailer->send($message->view, $message->data(), function ($m) use($notifiable, $notification, $message) {
         $recipients = empty($message->to) ? $notifiable->routeNotificationFor('mail') : $message->to;
         if (!empty($message->from)) {
             $m->from($message->from[0], isset($message->from[1]) ? $message->from[1] : null);
         }
         if (is_array($recipients)) {
             $m->bcc($recipients);
         } else {
             $m->to($recipients);
         }
         $m->subject($message->subject ?: Str::title(Str::snake(class_basename($notification), ' ')));
         foreach ($message->attachments as $attachment) {
             $m->attach($attachment['file'], $attachment['options']);
         }
         foreach ($message->rawAttachments as $attachment) {
             $m->attachData($attachment['data'], $attachment['name'], $attachment['options']);
         }
     });
 }
示例#9
0
 /**
  * Get the collection associated with the model.
  *
  * @return string
  */
 public function getCollectionName()
 {
     if (static::$collection) {
         return static::$collection;
     }
     return str_replace('\\', '', Str::snake(Str::plural(class_basename($this))));
 }
示例#10
0
 /**
  * Handle the event.
  *
  * @param Event $event
  */
 public function handle(Event $event)
 {
     $event->site->updateStatus('Adding mysql database');
     $sql = 'CREATE DATABASE IF NOT EXISTS ' . Str::snake($event->site->name) . ';';
     $this->envoy->run('mysql --sql="' . $sql . '"', true);
     $this->envoy->run('artisan --path="' . $event->site->rootPath . '" --cmd="migrate"', true);
 }
 /**
  * Get the resource associated with the controller.
  *
  * @return string
  */
 public function resource()
 {
     $resource = str_replace('Controller', null, $this->getName());
     $resource = Str::snake($resource, '-');
     $resource = str_replace('\\', '.', $resource);
     $resource = str_replace('.-', '.', $resource);
     return $resource;
 }
 private function prepareModelNames()
 {
     $this->modelNames['plural'] = Str::plural($this->modelName);
     $this->modelNames['camel'] = Str::camel($this->modelName);
     $this->modelNames['camelPlural'] = Str::camel($this->modelNames['plural']);
     $this->modelNames['snake'] = Str::snake($this->modelName);
     $this->modelNames['snakePlural'] = Str::snake($this->modelNames['plural']);
 }
 public function getAbility($actionName)
 {
     list($controller, $method) = explode('@', $actionName);
     $name = str_plural(strtolower(Str::snake(preg_replace('/Controller$/i', '', class_basename($controller)))));
     $resourceAbilityMap = $this->resourceAbilityMap();
     $method = isset($resourceAbilityMap[$method]) === true ? $resourceAbilityMap[$method] : $method;
     return sprintf('admin.%s.%s', $name, $method);
 }
示例#14
0
 /**
  * Set a constraint.
  *
  * @param string $constraint
  * @param mixed $value
  */
 public function __call($method, $arguments)
 {
     $constraint = Str::snake($method);
     $value = $arguments[0];
     $type = $this->constraintType($constraint);
     $this->setConstraint($constraint, $value, $type);
     return $this;
 }
 private function getPrefix()
 {
     $raw = get_called_class();
     $raw = str_replace($this->removePrefix(), '', $raw);
     $raw = Str::snake($raw, '_');
     $raw = str_replace('\\_', '.', $raw);
     return $this->prefixFixer($raw);
 }
 /**
  * @param string $name
  *
  * @return string
  */
 protected function buildClass($name)
 {
     $stub = parent::buildClass($name);
     $table = Str::plural(Str::snake(class_basename($this->argument('name'))));
     $this->table = str_replace('._', '_', $table);
     $stub = str_replace('DummyTable', $this->table, $stub);
     return $stub;
 }
示例#17
0
 public function toArray()
 {
     $out = [];
     foreach ($this as $key => $value) {
         $out[ucfirst(Str::snake($key))] = $value;
     }
     return $out;
 }
示例#18
0
文件: TraitNode.php 项目: larakit/lk
 protected function laraSet($k, $v)
 {
     if (mb_strpos($k, 'set') !== false) {
         $k = mb_substr($k, 3);
     }
     $k = Str::snake($k);
     $this->larakit[$k] = $v;
     return $this;
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if (parent::fire() !== false) {
         if ($this->option('migration')) {
             $table = Str::plural(Str::snake(class_basename($this->argument('name'))));
             $this->call('make:migration', ['name' => "create_{$table}_table", '--create' => $table]);
         }
     }
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::create($this->meta_table, function (Blueprint $table) {
         $table->increments(Str::snake($this->meta_table) . '_id');
         $table->string($this->meta_key);
         $table->text($this->meta_value);
         $table->timestamps();
     });
 }
示例#21
0
 /**
  * Build the class with the given name.
  *
  * @param  string  $name
  * @return string
  */
 protected function buildClass($name)
 {
     $stub = $this->files->get($this->getStub());
     if ($this->option('migration')) {
         $table = Str::plural(Str::snake(class_basename($this->argument('name'))));
         $this->call('make:migration', ['name' => "create_{$table}_table", '--create' => $table]);
     }
     return $this->replaceNamespace($stub, $name)->replaceAbstractClass($stub, $this->getAbstractModelName())->replaceClass($stub, $name);
 }
示例#22
0
 /**
  * Catches method call and checks for matching view.
  *
  * @param string $method
  * @param array  $parameters
  *
  * @return \Illuminate\View\View|null
  */
 public function __call($method, $parameters = null)
 {
     $name = Str::snake($method, '-');
     $view = 'pages/' . $name;
     if (view()->exists($view)) {
         return view($view);
     }
     return abort(404);
 }
示例#23
0
 /**
  * Get an instance from the Container
  *
  * @param string $key
  *
  * @return object
  */
 public function __get($key)
 {
     if (in_array($key, ['translator', 'url', 'router'])) {
         $key = 'polyglot.' . $key;
     }
     $key = Str::snake($key);
     $key = str_replace('_', '.', $key);
     return $this->app[$key];
 }
示例#24
0
 /**
  * Build the mail message.
  *
  * @param  \Illuminate\Mail\Message  $mailMessage
  * @param  mixed  $notifiable
  * @param  \Illuminate\Notifications\Notification  $notification
  * @param  \Illuminate\Notifications\Messages\MailMessage  $message
  * @return void
  */
 protected function buildMessage($mailMessage, $notifiable, $notification, $message)
 {
     $this->addressMessage($mailMessage, $notifiable, $message);
     $mailMessage->subject($message->subject ?: Str::title(Str::snake(class_basename($notification), ' ')));
     $this->addAttachments($mailMessage, $message);
     if (!is_null($message->priority)) {
         $mailMessage->setPriority($message->priority);
     }
 }
示例#25
0
 /**
  * This is the main function that does the work of finding the method and calling it
  * @param $method
  * @param $arguments
  * @return mixed
  */
 private function makeAndCallMethod($method, $arguments)
 {
     $method_parts = explode('_', Str::snake($method));
     $valid_operators = ['get', 'count', 'first', 'if'];
     if (!$this->isValidCall($method_parts, $valid_operators)) {
         throw new \Exception("Invalid method {$method} called. ");
     }
     list($query_operator, $method) = $this->extractQueryOperatorAndMethod($method_parts);
     return $this->callMethod($method, $arguments, $query_operator);
 }
示例#26
0
 /**
  * @param string $separator
  *
  * @return string|null
  */
 public function getRouterPath($separator = '.')
 {
     if (!is_null($this->getRouter())) {
         $controller = $this->getRouter()->currentRouteAction();
         $namespace = array_get($this->getRouter()->getCurrentRoute()->getAction(), 'namespace');
         $path = trim(str_replace($namespace, '', $controller), '\\');
         return str_replace(['\\', '@', '..', '.controller.'], $separator, Str::snake($path, '.'));
     }
     return;
 }
示例#27
0
文件: Widget.php 项目: larakit/lk
 static function widget_name()
 {
     $function_name = 'widget_';
     $r = new \ReflectionClass(get_called_class());
     $function_name .= Str::snake(str_replace('Widget', '', $r->getShortName()));
     if ('Larakit\\Widget' != $r->getNamespaceName()) {
         $function_name .= '__' . Str::snake(str_replace(['\\', 'Widget'], '', $r->getNamespaceName()));
     }
     return $function_name;
 }
 protected function doReplacements($message, $attribute, $rule, $parameters)
 {
     $value = $attribute;
     $message = str_replace([':ATTRIBUTE', ':Attribute', ':attribute'], [Str::upper($value), Str::ucfirst($value), $value], $message);
     if (isset($this->replacers[Str::snake($rule)])) {
         $message = $this->callReplacer($message, $attribute, Str::snake($rule), $parameters);
     } elseif (method_exists($this, $replacer = "replace{$rule}")) {
         $message = $this->{$replacer}($message, $attribute, $rule, $parameters);
     }
     return $message;
 }
示例#29
0
 public function toArray()
 {
     $arr = [];
     foreach ($this as $key => $value) {
         if ($value instanceof Arrayable) {
             $value = $value->toArray();
         }
         $arr[Str::snake($key)] = $value;
     }
     return $arr;
 }
示例#30
-2
文件: Lara.php 项目: gxela/lararoute
 /**
  * Controller Auto-Router
  *
  * @param string $controller eg. 'Admin\\UserController'
  * @param array $request_methods eg. array('get', 'post', 'put', 'delete')
  * @param string $prefix eg. admin.users
  * @param array $disallowed eg. array('private_method that starts with one of request methods)
  * @return Closure
  */
 public static function autoRoute($controller, $request_methods, $disallowed = array(), $prefix = '')
 {
     return function () use($controller, $prefix, $disallowed, $request_methods) {
         //get all defined functions
         $methods = get_class_methods(App::make($controller));
         //laravel methods to disallow by default
         $disallowed_methods = array('getBeforeFilters', 'getAfterFilters', 'getFilterer');
         //build list of functions to not allow
         if (is_array($disallowed)) {
             $disallowed_methods = array_merge($disallowed_methods, $disallowed);
         }
         //if there is a index method then lets just bind it and fill the gap in route_names
         if (in_array('getIndex', $methods)) {
             Lara::fillRouteGaps($prefix, $controller . '@getIndex');
         }
         //over all request methods, get, post, etc
         foreach ($request_methods as $type) {
             //filter functions that starts with request method and not in disallowed list
             $actions = array_filter($methods, function ($action) use($type, $disallowed_methods) {
                 return Str::startsWith($action, $type) && !in_array($action, $disallowed_methods);
             });
             foreach ($actions as $action) {
                 $controller_route = $controller . '@' . $action;
                 // Admin\\Controller@get_login
                 $url = Str::snake(str_replace($type, '', $action));
                 // login; snake_case
                 //double check and dont bind to already bound gaps filled index
                 if (in_array($action, $methods) && $action !== 'getIndex') {
                     $route = str_replace('..', '.', $prefix . '.' . Str::snake($action));
                     Route::$type($url, array('as' => $route, 'uses' => $controller_route));
                 }
             }
         }
     };
 }