Пример #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $originalName = $this->argument('feature');
     $feature = Pluralizer::plural(ucfirst($this->argument('feature')));
     $path = $this->option('path');
     $namespace = ucfirst($this->option('namespace'));
     $controllerPath = $path . '/' . $feature . '/Controllers';
     $modelPath = $path . '/' . $feature . '/Models';
     $providersPath = $path . '/' . $feature . '/Providers';
     $repositoriesPath = $path . '/' . $feature . '/Repositories';
     $this->info('Creating the feature: ' . $feature);
     $this->info('On the path: ' . $path);
     if ($this->confirm('Do you wish to continue? [yes|no]')) {
         $this->info('Creating folders');
         // Creating directories
         $this->createDirectories($path, $feature, $controllerPath, $modelPath, $providersPath, $repositoriesPath);
         $this->file->put($path . '/' . $feature . '/routes.php', '');
         // Create files
         $this->info('Creating controller');
         $controller = new ControllerGenerator($this->file);
         $this->printResult($controller->make($controllerPath . '/' . $feature . 'Controller.php', $namespace), $controllerPath . '/' . $feature . 'Controller.php');
         $this->info('Creating interface');
         $interface = new InterfaceGenerator($this->file);
         $this->printResult($interface->make($repositoriesPath . '/' . ucfirst($originalName) . 'Interface.php', $namespace), $repositoriesPath . '/' . ucfirst($originalName) . 'Interface.php');
         $this->info('Creating repository');
         $repository = new RepositoryGenerator($this->file);
         $this->printResult($repository->make($repositoriesPath . '/' . ucfirst($originalName) . 'Repository.php', $namespace), $repositoriesPath . '/' . ucfirst($originalName) . 'Repository.php');
         $this->info('Creating model');
         $model = new ModelGenerator($this->file);
         $this->printResult($model->make($modelPath . '/' . ucfirst($originalName) . '.php', $namespace), $modelPath . '/' . ucfirst($originalName) . '.php');
         $this->info('Creating service provider');
         $provider = new ProviderGenerator($this->file);
         $this->printResult($provider->make($providersPath . '/' . $feature . 'ServiceProvider.php', $namespace), $providersPath . '/' . $feature . 'ServiceProvider.php');
     }
 }
Пример #2
0
 /**
  * Fetch the compiled template for a seed
  *
  * @param  string $template Path to template
  * @param  string $className
  *
  * @return string Compiled template
  */
 protected function getTemplate($template, $className)
 {
     $this->template = $this->file->get($template);
     $name = Pluralizer::singular(str_replace('TableSeeder', '', $className));
     $modelVars = GeneratorsServiceProvider::getModelVars($name);
     $this->template = str_replace('{{className}}', $className, $this->template);
     $template = GeneratorsServiceProvider::replaceModelVars($this->template, $modelVars);
     return $this->replaceStandardParams($template);
 }
 public function generate($path, $name)
 {
     $singular = Pluralizer::singular($name);
     $plural = Pluralizer::plural($name);
     $segments = explode('/', $path);
     $module_dir = array_pop($segments);
     return new Collection(['model' => new BackboneComponent($path . '/' . $plural . '/models/' . $name . '.js', $module_dir . '/' . $plural . '/models/' . $name, ucfirst($singular)), 'view' => new BackboneComponent($path . '/' . $plural . '/views/' . $singular . '_view.js', $module_dir . '/' . $plural . '/views/' . $singular . '_view', ucfirst($singular) . 'View'), 'collection' => new BackboneComponent($path . '/' . $plural . '/collections/' . $plural . '.js', $module_dir . '/' . $plural . '/collections/' . $plural, ucfirst($singular) . 'Collection'), 'index' => new BackboneComponent($path . '/' . $plural . '/index.js', $module_dir . '/' . $plural . '/index', 'Index')]);
     return new Collection($ret);
 }
Пример #4
0
 public function setApiName($name)
 {
     $this->_api_name = Pluralizer::singular($name);
     $this->_collection_name = Str::studly(Str::singular(Str::slug($this->_api_name, " ")));
     if (!class_exists("AndrewLamers\\Chargify\\" . $this->_collection_name)) {
         eval("namespace Andrewlamers\\Chargify; class " . $this->_collection_name . " extends \\Andrewlamers\\Chargify\\Fluent {}");
     }
     $this->_collection_name = "Andrewlamers\\Chargify\\" . $this->_collection_name;
 }
Пример #5
0
 public function __construct($modelName, $tableName)
 {
     // Set the given table name, or plularize the model name if
     // not given
     if (!$tableName) {
         $this->tableName = strtolower(Pluralizer::plural($modelName));
     } else {
         $this->tableName = $tableName;
     }
 }
Пример #6
0
 private function formatTree(SimpleXMLElement $xml, array $serialized, SimpleXMLElement $rootNode = null, $parentName = null, SimpleXMLElement $parentNode = null)
 {
     foreach ($serialized as $key => $value) {
         if (is_array($value)) {
             // Branch
             if (count($value) === 0) {
                 // Empty array
                 $child = $xml->addChild($key);
                 $child->addAttribute("array", null);
             } else {
                 if (is_numeric($key)) {
                     // Numeric in array, singularize
                     $key = Pluralizer::singular($parentName);
                     if (!isset($parentNode["array"])) {
                         $parentNode->addAttribute("array", $key);
                     }
                 }
                 $child = $xml->addChild($key);
                 $this->formatTree($child, $value, $rootNode, $key, $child);
             }
         } else {
             // Leaf
             if ($key === "_ref") {
                 // Ref
                 $parentNode->addAttribute("ref", $value);
             } elseif ($key === "_id") {
                 // Id
                 if (!is_null($parentNode)) {
                     $parentNode->addAttribute("id", $value);
                 } else {
                     $rootNode->addAttribute("id", $value);
                 }
             } elseif (is_null($value)) {
                 // If value is null, denote it in the attribute
                 $child = $xml->addChild($key);
                 $child->addAttribute("scalar", "null");
             } elseif (is_int($value)) {
                 // If value is int, denote it in the attribute
                 $child = $xml->addChild($key, $value);
                 $child->addAttribute("scalar", "integer");
             } elseif (is_float($value)) {
                 // If value is float, denote it in the attribute
                 $child = $xml->addChild($key, $value);
                 $child->addAttribute("scalar", "float");
             } elseif (is_bool($value)) {
                 // If value is boolean, denote it in the attribute
                 $child = $xml->addChild($key, $value ? 1 : 0);
                 $child->addAttribute("scalar", "boolean");
             } else {
                 // Value
                 $xml->addChild($key, $value);
             }
         }
     }
 }
Пример #7
0
 /**
  * @inheritdoc
  */
 public function resolve($what)
 {
     if (class_exists($what)) {
         return $what;
     }
     $resolvable = method_exists($this, 'resolvable') ? $this->resolvable() : $this;
     $reflection = new ReflectionClass($resolvable);
     $suffix = ucfirst($what);
     $namespace = Pluralizer::plural($suffix);
     $fqcn = join('\\', [preg_replace('#Models?\\\\#', '', $reflection->getNamespaceName()), $namespace, $reflection->getShortName() . $suffix]);
     return $fqcn;
 }
 /**
  * Get template for a scaffold
  *
  * @param  string $template Path to template
  * @param  string $name
  * @return string
  */
 protected function getScaffoldedController($template, $name)
 {
     $collection = strtolower(str_replace('Controller', '', $name));
     // dogs
     $modelInstance = Pluralizer::singular($collection);
     // dog
     $modelClass = ucwords($modelInstance);
     // Dog
     foreach (array('modelInstance', 'modelClass', 'collection') as $var) {
         $this->template = str_replace('{{' . $var . '}}', ${$var}, $this->template);
     }
     return $this->template;
 }
Пример #9
0
 /**
  * Get template for a scaffold
  *
  * @param  string $template Path to template
  * @param  string $name
  * @return string
  */
 protected function getScaffoldedController($template, $className)
 {
     $model = $this->cache->getModelName();
     // post
     $models = Pluralizer::plural($model);
     // posts
     $Models = ucwords($models);
     // Posts
     $Model = Pluralizer::singular($Models);
     // Post
     foreach (array('model', 'models', 'Models', 'Model', 'className') as $var) {
         $this->template = str_replace('{{' . $var . '}}', ${$var}, $this->template);
     }
     return $this->template;
 }
Пример #10
0
 public function getTemplate($name, $namespace)
 {
     $path = __DIR__ . '/templates/model.txt';
     $this->template = $this->file->get($path);
     // Prepare strings to be placed on the template
     $singular = Pluralizer::singular(ucfirst($name));
     $singularLower = strtolower($singular);
     $plural = Pluralizer::plural(ucfirst($name));
     // Replace
     $this->template = str_replace('{{namespace}}', $namespace, $this->template);
     $this->template = str_replace('{{singular}}', $singular, $this->template);
     $this->template = str_replace('{{plural}}', $plural, $this->template);
     $this->template = str_replace('{{singularLower}}', $singularLower, $this->template);
     return $this->template;
 }
 /**
  * Parse the resource name from the called method.
  *
  * @param  string  $method
  * @return string
  */
 protected function parseResourceName($method)
 {
     // Here we check if the method is returned with
     // a different resource name.
     if (array_key_exists($method, $this->resourceResponseNames)) {
         return $this->resourceResponseNames[$method];
     }
     $plural = strtolower(str_replace($this->trimable, null, $method));
     // Here we check if the method is returned with
     // a plural resource name.
     if (in_array($plural, $this->pluralResponseNames)) {
         return $plural;
     }
     // Lastly we create a singular resource name.
     return Pluralizer::singular($plural);
 }
Пример #12
0
 /**
  * Fetch the compiled template for a model
  *
  * @param  string $template Path to template
  * @param  string $className
  *
  * @return string Compiled template
  */
 protected function getTemplate($template, $className)
 {
     $this->template = $this->file->get($template);
     $relationModelList = GeneratorsServiceProvider::getRelationsModelVarsList(GeneratorsServiceProvider::splitFields($this->cache->getFields(), true));
     // Replace template vars
     $modelVars = GeneratorsServiceProvider::getModelVars($this->cache->getModelName());
     $this->template = GeneratorsServiceProvider::replaceModelVars($this->template, $modelVars);
     $fields = $this->cache->getFields() ?: [];
     $fields = GeneratorsServiceProvider::splitFields(implode(',', $fields), SCOPED_EXPLODE_WANT_ID_RECORD);
     $this->template = GeneratorsServiceProvider::replaceTemplateLines($this->template, '{{translations:line}}', function ($line, $fieldVar) use($fields, $relationModelList) {
         $fieldTexts = [];
         foreach ($fields + ['id' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'] as $field => $type) {
             if (array_key_exists($field, $relationModelList)) {
                 // add the foreign model translation
                 $foreignName = $relationModelList[$field]['dash-model'];
                 $foreignNameText = $relationModelList[$field]['Space Model'];
                 $fieldTexts[] = str_replace($fieldVar, "'{$foreignName}' => '{$foreignNameText}',", $line);
                 if (trim_suffix($field, "_id") !== $foreignName) {
                     $foreignName = trim_suffix($field, "_id");
                     $foreignNameText = GeneratorsServiceProvider::getModelVars($foreignName)['Space Model'];
                     $fieldTexts[] = str_replace($fieldVar, "'{$foreignName}' => '{$foreignNameText}',", $line);
                 }
             }
             if (is_array($type) && ($bitset = hasIt($type, 'bitset', HASIT_WANT_PREFIX | HASIT_WANT_VALUE))) {
                 $params = preg_match('/bitset\\((.*)\\)/', $bitset, $matches) ? $matches[1] : '';
                 if ($params === '') {
                     $params = $field;
                 }
                 $params = explode(',', $params);
                 foreach ($params as $param) {
                     $bitFieldNameText = GeneratorsServiceProvider::getModelVars($param)['Space Model'];
                     $fieldTexts[] = str_replace($fieldVar, "'{$param}' => '{$bitFieldNameText}',", $line);
                 }
             }
             $modelVars = GeneratorsServiceProvider::getModelVars($field);
             $fieldNameTrans = $field !== Pluralizer::plural($field) ? $modelVars['Space Model'] : $modelVars['Space Models'];
             $fieldTexts[] = str_replace($fieldVar, "'{$field}' => '{$fieldNameTrans}',", $line);
         }
         sort($fieldTexts);
         return implode("\n", $fieldTexts) . "\n";
     });
     $this->template = $this->replaceStandardParams($this->template);
     return $this->template;
 }
Пример #13
0
 /**
  * For a given table, generate the migration object with the appropriate
  * parameters
  * @param  string $tableName The name of the table
  * @param  array  $columns   An array of SchemaExtractor Column objects
  */
 private function createTableMigration($tableName, $columns)
 {
     // Get the parsed columns
     $parsedColumns = $this->schemaExtractor->extract($columns, $this->dbType);
     // Get the model name form the table name
     $modelName = ucwords(Pluralizer::singular($tableName));
     // Create a new migration
     $this->migrationList->create($modelName, $tableName);
     // Now, proceed towards adding columns
     foreach ($parsedColumns as $column) {
         $type = $this->getLaravelColumnType($column);
         // For primary keys, we simply set pK
         if ($type == 'increments') {
             $this->migrationList->setPrimaryKey($modelName, $column->name);
             continue;
         }
         $c = array('name' => $column->name, 'type' => $type, 'parameters' => $this->getLaravelColumnParameters($column->parameters, $type), 'default' => is_null($column->defaultValue) ? '' : $column->defaultValue, 'unsigned' => $column->unsigned, 'nullable' => $column->null, 'primary' => $column->index == 'primary', 'unique' => $column->index == 'unique', 'index' => $column->index == 'multicolumn');
         $this->migrationList->addColumn($modelName, $c);
     }
 }
 /**
  * Get template for a scaffold
  *
  * @param  string $template Path to template
  * @param  string $name
  * @return string
  */
 protected function getScaffoldedController($template, $className)
 {
     $model = $this->cache->getModelName();
     // post
     $models = Pluralizer::plural($model);
     // posts
     $Models = ucwords($models);
     // Posts
     $Model = Pluralizer::singular($Models);
     // Post
     $namespace = $this->cache->getValue('namespace');
     $classNamespace = empty($namespace) ? '' : "namespace " . ucwords(str_replace('/', '\\', $namespace)) . ";";
     $multi_key = empty($namespace) ? $models : str_replace('/', '.', $namespace) . ".{$models}";
     $fields = join(",", array_map(function ($f) {
         return "'{$f}'";
     }, array_keys($this->cache->getFields())));
     foreach (array('model', 'models', 'Models', 'Model', 'className', 'multi_key', 'classNamespace', 'fields') as $var) {
         $this->template = str_replace('{{' . $var . '}}', ${$var}, $this->template);
     }
     return $this->template;
 }
Пример #15
0
 public function fire()
 {
     if (!class_exists('Way\\Generators\\GeneratorsServiceProvider')) {
         $this->error('Way Generators are not installed! Lapigen needs this package to run!');
     }
     $lowerCase = strtolower($this->argument('name'));
     $capitalFirst = ucfirst($lowerCase);
     $this->line('');
     $this->line('|***************************************************|');
     $this->line('|');
     $this->line('| I choose you LAPIGEN!');
     $this->line('|');
     $this->line('| Generating full API resource!');
     $this->line('|');
     $this->line('|***************************************************|');
     $this->line('');
     $this->line('*** Controller ***');
     $controllerName = Pluralizer::singular($capitalFirst) . 'Controller';
     $this->call('generate:controller', array('name' => $controllerName, '--path' => $this->option('controllerpath'), '--template' => __DIR__ . '/stubs/controller.txt'));
     $this->line('');
     $this->line('*** Route ***');
     $routesFilePath = $routesFilePath = app_path() . '/routes.php';
     $this->setLapiRoute($routesFilePath, $lowerCase, $controllerName);
     $this->line("Updated {$routesFilePath}");
     $this->line('');
     $this->line('*** Model ***');
     $this->call('generate:model', array('name' => Pluralizer::singular($capitalFirst), '--path' => $this->option('modelpath'), '--template' => __DIR__ . '/stubs/model.txt'));
     $this->line('');
     $this->line('*** Seeder ***');
     $this->call('generate:seed', array('name' => Pluralizer::plural($lowerCase), '--path' => $this->option('seedpath')));
     $this->line('');
     $this->line('*** Migration and "artisan optimize" ***');
     $this->call('generate:migration', array('name' => 'create_' . Pluralizer::plural($lowerCase) . '_table', '--path' => $this->option('migrationspath'), '--fields' => $this->option('fields')));
     $this->line('');
     $this->line('|***************************************************|');
     $this->line('|');
     $this->line('| Ready to rumble!');
     $this->line('|');
     $this->line('|***************************************************|');
 }
    /**
     * Create the table rows
     *
     * @param  string $model
     * @return Array
     */
    protected function makeTableRows($model)
    {
        $models = Pluralizer::plural($model);
        // posts
        $fields = $this->cache->getFields();
        // First, we build the table headings
        $headings = array_map(function ($field) {
            return '<th>' . ucwords($field) . '</th>';
        }, array_keys($fields));
        // And then the rows, themselves
        $fields = array_map(function ($field) use($model) {
            return "<td>{{{ \${$model}->{$field} }}}</td>";
        }, array_keys($fields));
        // Now, we'll add the edit and delete buttons.
        $editAndDelete = <<<EOT
                    <td>
                        {{ Form::open(array('style' => 'display: inline-block;', 'method' => 'DELETE', 'route' => array('{$models}.destroy', \${$model}->id))) }}
                            {{ Form::submit('Delete', array('class' => 'btn btn-danger')) }}
                        {{ Form::close() }}
                        {{ link_to_route('{$models}.edit', 'Edit', array(\${$model}->id), array('class' => 'btn btn-info')) }}
                    </td>
EOT;
        return array($headings, $fields, $editAndDelete);
    }
Пример #17
0
 public function singular($word)
 {
     return Pluralizer::singular($word);
 }
Пример #18
0
 protected function generateSeed()
 {
     $this->call('generate:seed', array('name' => Pluralizer::plural(strtolower($this->model))));
 }
Пример #19
0
    });
    $messageBag->add('notice', 'Collection displayed.');
    echo '<hr>';
    // More at http://daylerees.com/codebright/eloquent-collections
    // Fluent
    $personRecord = array('first_name' => 'Mohammad', 'last_name' => 'Gufran');
    $record = new Fluent($personRecord);
    $record->address('hometown, street, house');
    echo $record->first_name . "\n";
    echo $record->address . "\n";
    $messageBag->add('notice', 'Fluent displayed.');
    echo '<hr>';
    // Pluralizer
    $item = 'goose';
    echo "One {$item}, two " . Pluralizer::plural($item) . "\n";
    $item = 'moose';
    echo "One {$item}, two " . Pluralizer::plural($item) . "\n";
    echo '<hr>';
    // Str
    if (Str::contains('This is my fourteenth visit', 'first')) {
        echo 'Howdy!';
    } else {
        echo 'Nice to see you again.';
    }
    echo '<hr>';
    echo "MessageBag ({$messageBag->count()})\n";
    foreach ($messageBag->all() as $message) {
        echo " - {$message}\n";
    }
});
$app->run();
Пример #20
0
 /**
  * Get the plural form of the given word.
  *
  * <code>
  *  // Returns the plural form of "child"
  *  $plural = Str::plural('child', 10);
  *
  *  // Returns the singular form of "octocat" since count is one
  *  $plural = Str::plural('octocat', 1);
  * </code>
  *
  * @param string  $value
  * @param int     $count
  * @return string
  */
 public function plural($value, $count = 2)
 {
     return Pluralizer::plural($value, $count);
 }
Пример #21
0
 protected function resourceName($className)
 {
     return snake_case(Pluralizer::plural(class_basename($className)), '-');
 }
 /**
  * Generate a model file from a database table.
  *
  * @param $table
  * @return void
  */
 protected function generateTable($table)
 {
     //prefix is the sub-directory within app
     $prefix = $this->option('dir');
     $ignoreTable = $this->option("ignore");
     if ($this->option("ignoresystem")) {
         $ignoreSystem = "users,permissions,permission_role,roles,role_user,migrations,password_resets";
         if (is_string($ignoreTable)) {
             $ignoreTable .= "," . $ignoreSystem;
         } else {
             $ignoreTable = $ignoreSystem;
         }
     }
     // if we have ignore tables, we need to find all the posibilites
     if (is_string($ignoreTable) && preg_match("/^" . $table . "|^" . $table . ",|," . $table . ",|," . $table . "\$/", $ignoreTable)) {
         $this->info($table . " is ignored");
         return;
     }
     $class = VariableConversion::convertTableNameToClassName($table);
     $name = Pluralizer::singular($this->parseName($prefix . $class));
     if ($this->files->exists($path = $this->getPath($name)) && !$this->option('force')) {
         return $this->error($this->extends . ' for ' . $table . ' already exists!');
     }
     $this->makeDirectory($path);
     $this->files->put($path, $this->replaceTokens($name, $table));
     $this->info($this->extends . ' for ' . $table . ' created successfully.');
 }
Пример #23
0
 /**
  * Returns the fully qualified class
  * of the model associated with this
  * controller.
  *
  * This method assumes that the model
  * class is the singularized form of
  * the controller's name minus the
  * 'Controller' suffix.
  *
  * It will also assume that the model class
  * is namespaced under 'App', unless specified
  * otherwise. A different namespace can
  * be set by overriding getModelNamespace().
  *
  * @return  string
  */
 public function getRelatedModelClass()
 {
     $fqController = explode('\\', static::class);
     $model = Pluralizer::singular(str_replace('Controller', '', end($fqController)));
     $ns = $this->getModelNamespace() ?: 'App';
     return $ns . '\\' . $model;
 }
Пример #24
0
 /**
  * call has many relationship
  *
  **/
 public function PointLogs()
 {
     return $this->hasMany('App\\Models\\PointLog', Pluralizer::singular($this->getTable()) . '_id');
 }
Пример #25
0
 /**
  * @param $table_name
  * @return mixed
  */
 private static function getClassByTable($table_name)
 {
     $class = Config::get('refinement.table_map.' . $table_name);
     return $class ?: ucfirst(Pluralizer::singular($table_name));
 }
 /**
  * Fetch Doctrine table info
  * @param  string $model
  * @return object
  */
 public function getTableInfo($model)
 {
     $table = Pluralizer::plural($model);
     return \DB::getDoctrineSchemaManager()->listTableDetails($table)->getColumns();
 }
Пример #27
0
 /**
  * Get the singular form of an English word.
  *
  * @param  string  $value
  * @return string
  */
 public static function singular($value)
 {
     return Pluralizer::singular($value);
 }
Пример #28
0
 /**
  * Convert a word to it's singular
  * @param $word
  * @return string
  */
 public function singular($word)
 {
     return $this->pluralizer->singular($word);
 }
Пример #29
0
 /**
  * Update app/routes.php
  *
  * @param  string $name
  * @return void
  */
 public function updateRoutesFile($name)
 {
     $name = strtolower(Pluralizer::plural($name));
     $this->file->append(app_path() . '/routes.php', "\n\nRoute::resource('" . $name . "', '" . ucwords($name) . "Controller');");
 }
Пример #30
0
 /**
  * Fetch the compiled template for a controller
  *
  * @param  string $template Path to template
  * @param string  $className
  *
  * @return string Compiled template
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  */
 protected function getTemplate($template, $className)
 {
     $this->template = $this->file->get($template);
     $resource = strtolower(Pluralizer::plural(str_ireplace('Controller', '', $className)));
     if ($this->needsScaffolding($template)) {
         $this->template = $this->getScaffoldedController($template, $className);
     }
     $template = str_replace('{{className}}', $className, $this->template);
     $template = str_replace('{{collection}}', $resource, $template);
     $template = $this->replaceLines($template, []);
     return $this->replaceStandardParams($template);
 }