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; }
public function initVariables() { $this->modelNamePlural = Str::plural($this->modelName); $this->modelNameCamel = Str::camel($this->modelName); $this->modelNamePluralCamel = Str::camel($this->modelNamePlural); $this->initDynamicVariables(); }
/** * @param Relation $relation * @return $this * @throws GeneratorException */ public function addRelation(Relation $relation) { $relationClass = Str::studly($relation->getTableName()); if ($relation instanceof HasOne) { $name = Str::camel($relation->getTableName()); $docBlock = sprintf('@return \\%s', EloquentHasOne::class); $virtualPropertyType = $relationClass; } elseif ($relation instanceof HasMany) { $name = Str::plural(Str::camel($relation->getTableName())); $docBlock = sprintf('@return \\%s', EloquentHasMany::class); $virtualPropertyType = sprintf('%s[]', $relationClass); } elseif ($relation instanceof BelongsTo) { $name = Str::camel($relation->getTableName()); $docBlock = sprintf('@return \\%s', EloquentBelongsTo::class); $virtualPropertyType = $relationClass; } elseif ($relation instanceof BelongsToMany) { $name = Str::plural(Str::camel($relation->getTableName())); $docBlock = sprintf('@return \\%s', EloquentBelongsToMany::class); $virtualPropertyType = sprintf('%s[]', $relationClass); } else { throw new GeneratorException('Relation not supported'); } $method = new MethodModel($name); $method->setBody($this->createMethodBody($relation)); $method->setDocBlock(new DocBlockModel($docBlock)); $this->addMethod($method); $this->addProperty(new VirtualPropertyModel($name, $virtualPropertyType)); return $this; }
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; }
/** * Get Model's table as a String * @return String */ private function getTable() { if (isset($this->table)) { return $this->table; } return str_replace('\\', '', Str::snake(Str::plural(class_basename($this)))); }
/** * 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); }
/** * 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]); } }
/** * 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)))); }
/** * @param $resource * @param $namespace * @param $template * @return mixed */ protected function createResourceTemplate($resource, $namespace, $template) { $template = str_replace('{namespace}', $namespace ? "namespace {$namespace};" : '', $template); $template = str_replace('{Resource}', ucfirst($resource), $template); $template = str_replace('{resource}', $resource, $template); $template = str_replace('{resources}', Str::plural($resource), $template); return $template; }
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']); }
/** * @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; }
/** * 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]); } } }
/** * 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); }
public static function piklistRegisterTaxonomy($taxonomies) { $settings = array('post_type' => static::getPostTypeSlugs(), 'name' => static::getTaxonomy(), 'show_admin_column' => true, 'configuration' => array('hierarchical' => true, 'labels' => static::getLabels(), 'hide_meta_box' => false, 'show_ui' => true, 'public' => true, 'query_var' => true, 'has_archive' => true, 'rewrite' => array('slug' => Str::plural(static::getSlug()), 'ep_mask' => EP_PERMALINK))); if (static::hasSettings()) { $settings = array_merge_recursive($settings, static::getSettings()); } $taxonomies[] = $settings; return $taxonomies; }
/** * {@inheritdoc} */ protected function replaceNamespace(&$stub, $name) { $parent = parent::replaceNamespace($stub, $name); $stub = str_replace('DummyModelClass', $this->getModelName($name), $stub); $resourceName = $this->getResourceName(); $stub = str_replace('DummyResourceClass', ucfirst($resourceName), $stub); $stub = str_replace('DummyResourceNamePlural', Str::plural($resourceName), $stub); $stub = str_replace('DummyResourceName', $resourceName, $stub); return $parent; }
/** * Generate content for language file. * * @param string $resource * * @return string */ protected function createFile($resource) { $stub = $this->files->get($this->stubPath('crud/lang.stub')); $resources = Str::plural($resource); $stub = str_replace('DummyResourceNamePlural', $resources, $stub); $stub = str_replace('DummyResourceName', $resource, $stub); $stub = str_replace('DummyResourceStudlyPlural', Str::studly($resources), $stub); $stub = str_replace('DummyResourceStudly', Str::studly($resource), $stub); return $stub; }
public function fillStub($stub) { $className = $this->argument('className'); $namespace = str_replace('\\', '', $this->getAppNamespace()); $prefix = Str::plural($className); $stub = str_replace('{{namespace}}', $namespace, $stub); $stub = str_replace('{{class}}', $className, $stub); $stub = str_replace('{{prefix}}', '\'' . $prefix . '\'', $stub); return $stub; }
/** * Function to get the minimum template variables * * @return array */ public function getTemplateVars() { $entity = $this->getEntityName(); $fieldData = $this->getFieldData(); $instance = Str::singular(Str::snake($entity)); $cols = array_keys($fieldData); $cells = array_map(function ($x) use($instance) { return "\${$instance}->{$x}"; }, $cols); return ['Entity' => Str::studly($entity), 'Entities' => Str::plural(Str::studly($entity)), 'collection' => Str::plural(Str::snake($entity)), 'instance' => $instance, 'fields' => $fieldData, 'headings' => $cols, 'cells' => $cells]; }
protected function getViewPath() { if (isset($this->viewPath)) { return $this->viewPath; } $classNameParts = explode('\\', get_class($this)); array_pop($classNameParts); //leave only the namespace array_push($classNameParts, Str::plural($this->getModelName())); $basePath = implode('.', $classNameParts); return Str::lower($basePath); }
/** * Format an Eloquent collection. * * @param \Illuminate\Database\Eloquent\Collection $collection * * @return string */ public function formatEloquentCollection($collection) { if ($collection->isEmpty()) { return $this->encode([]); } $model = $collection->first(); $key = Str::plural($model->getTable()); if (!$model::$snakeAttributes) { $key = Str::camel($key); } return $this->encode([$key => $collection->toArray()]); }
/** * Get the Collection name of the model * * @return string */ public static function getCollectionName() { if (!is_array(static::$collectionName)) { return static::$collectionName; } $class = get_called_class(); if (!isset(static::$collectionName[$class])) { $collectionName = Str::plural($class); $collectionName = lcfirst($collectionName); static::$collectionName[$class] = $collectionName; } return static::$collectionName[$class]; }
/** * Execute the console command. * * @return void */ public function fire() { if (parent::fire() !== false) { if ($this->option('model')) { $this->call('make:model', ['name' => $this->argument('name')]); $table = str_replace('._', '_', Str::plural(Str::snake(class_basename($this->argument('name'))))); $this->call('make:migration', ['name' => "create_{$table}_table", '--create' => $table]); } if ($this->option('testcase')) { $this->call('make:test', ['name' => $this->argument('name')]); } } }
/** * @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]); } if ($this->option('controller')) { $controller = Str::camel(class_basename($this->argument('name'))); $this->call('make:controller', ['name' => "{$controller}Controller", '--resource' => true]); } } }
/** * Replace the model for the given stub. * * @param string $stub * @param string $model * @return string */ protected function replaceModel($stub, $model) { $model = str_replace('/', '\\', $model); if (Str::startsWith($model, '\\')) { $stub = str_replace('NamespacedDummyModel', trim($model, '\\'), $stub); } else { $stub = str_replace('NamespacedDummyModel', $this->laravel->getNamespace() . $model, $stub); } $model = class_basename(trim($model, '\\')); $stub = str_replace('DummyModel', $model, $stub); $stub = str_replace('dummyModelName', Str::lower($model), $stub); return str_replace('dummyPluralModelName', Str::plural(Str::lower($model)), $stub); }
/** * Get the collection and database name from a model class name without caching * * @param $class * * @return array */ public function resolveClass($class) { $data = []; $database = $class::getDatabase(); $collection = $class::getCollection(); $data['database'] = $database ?: $this->defaultDatabase; if ($collection) { $data['collection'] = $collection; } else { $data['collection'] = str_replace('\\', '', Str::snake(Str::plural(class_basename($class)))); } return $data; }
/** * Function to get the minimum template variables * * @return array */ public function getTemplateVars() { $entity = $this->getEntityName(); $fieldData = $this->getFieldData(); $form_rows = []; foreach ($fieldData as $property => $meta) { $display = Str::title(str_replace('_', ' ', $property)); $result['label'] = "{{ Form::label('{$property}', '{$display}:') }}"; $elementType = $this->getElementType($meta['type']); $result['element'] = "{{ Form::{$elementType}('{$property}') }}"; $form_rows[] = $result; } return ['Entity' => Str::studly($entity), 'Entities' => Str::plural(Str::studly($entity)), 'collection' => Str::plural(Str::snake($entity)), 'instance' => Str::singular(Str::snake($entity)), 'fields' => $fieldData, 'form_rows' => $form_rows]; }
/** * Constructor */ public function __construct($elementName = 'item', $collectionName = '') { // Set the element name (singular) first $this->elementName = $elementName; // Pluralise the element name if a collection name is not given if (empty($collectionName)) { $collectionName = Str::plural($this->elementName); } // Set the collection name (plural) $this->collectionName = $collectionName; $this->data['success'] = false; $this->data['json'] = []; $this->data['errors'] = []; }
/** * Run the Task * * @return void */ public function execute() { // If no releases to prune if (!($trash = $this->getReleasesToCleanup())) { return $this->command->comment('No releases to prune from the server'); } // Prune releases foreach ($trash as $release) { $this->removeFolder($this->releasesManager->getPathToRelease($release)); } // Create final message $trash = sizeof($trash); $message = sprintf('Removing <info>%d %s</info> from the server', $trash, Str::plural('release', $trash)); return $this->command->line($message); }
/** * @param InputInterface $input * @param OutputInterface $output * @return mixed */ protected function execute(InputInterface $input, OutputInterface $output) { if (parent::execute($input, $output)) { $name = $input->getArgument('name'); $migration = $input->getOption('migration'); $modelFile = $this->builder->create($name); $output->writeln("<info>Created Model:</info> {$modelFile}"); if ($migration) { list($namespace, $class) = $this->migration->extractClassFromNamespace($name); $table = Str::plural(Str::snake($class)); $migrationFile = pathinfo($this->migration->create("create_{$table}_table", 'migrations', $table, true), PATHINFO_FILENAME); $output->writeln("<info>Created Migration:</info> {$migrationFile}"); } } }
/** * {@inheritdoc} */ protected function replaceNamespace(&$stub, $name) { $parent = parent::replaceNamespace($stub, $name); $stub = str_replace('DummyModelClass', str_replace('/', '\\', $this->guessModelName()), $stub); $resourceName = $this->getResourceName(); $stub = str_replace('DummyResourceClass', ucfirst($resourceName), $stub); $stub = str_replace('DummyResourceNamePlural', Str::plural($resourceName), $stub); $stub = str_replace('DummyResourceName', $resourceName, $stub); // $authorize = is_null($this->option('guard')) // ? "auth()->check()" // : "auth('{$this->option('guard')}')->check()"; // $stub = str_replace( // 'AuthorizeRequest', $authorize, $stub // ); return $parent; }