plural() public static method

Get the plural form of an English word.
public static plural ( string $value, integer $count = 2 ) : string
$value string
$count integer
return string
 /**
  * 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');
     }
 }
 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);
 }
 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;
     }
 }
示例#4
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;
 }
 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;
 }
示例#6
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;
 }
示例#7
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;
 }
 /**
  * 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;
 }
示例#9
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);
    }
示例#11
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();
示例#12
0
文件: En.php 项目: codixor/support
 public function plural($word)
 {
     return Pluralizer::plural($word);
 }
 protected function generateSeed()
 {
     $this->call('generate:seed', parent::commonOptions(array('name' => Pluralizer::plural(strtolower(substr($this->model, 0, 1)) . substr($this->model, 1)))));
 }
 protected function generateSeed()
 {
     $this->call('generate:seed', array('name' => Pluralizer::plural(strtolower($this->model))));
 }
 /**
  * Fetch Doctrine table info
  * @param  string $model
  * @return object
  */
 public function getTableInfo($model)
 {
     $table = Pluralizer::plural($model);
     return \DB::getDoctrineSchemaManager()->listTableDetails($table)->getColumns();
 }
示例#16
0
 /**
  * Get the plural of the given word
  * @param $word
  * @param int $count
  * @return string
  */
 public function plural($word, $count = 2)
 {
     return $this->pluralizer->plural($word, $count);
 }
示例#17
0
 public function BuildControllerComments()
 {
     // Add some comments so that new users have a starting point on what to add to the routes.php file
     $string = " * --- begin route block --- \n\n";
     $string .= "  Route::group([ 'prefix' => '" . $this->subFolder . "', 'namespace' => '" . UCFirst($this->subFolder) . "'], function(){\n";
     $string .= "    Route::get('/', 'MasterIndexController@index');\n";
     foreach ($this->tables as $table) {
         $string .= "    Route::resource('" . Pluralizer::plural($table) . "', '" . UCFirst(Pluralizer::plural($table)) . "Controller');\n";
     }
     $string .= "  });\n\n";
     $string .= " * --- end route block   --- \n";
     $this->controllercomments = $string;
 }
示例#18
0
 /**
  * Get the function name of a relation in the model based on the type of relation
  * it is
  * @param  string $toModel      The related model
  * @param  string $relationType The relation type
  * @return string               The function name to be used in the relation
  */
 private function getRelationalFunctionName($toModel, $relationType)
 {
     // If the relation type is hasMany, hasOne, hasManyAndBelongsToMany,
     // then the function name should be the pluralized version of the related model
     if (in_array($relationType, array('hm', 'ho', 'btm', 'btmc', 'mm'))) {
         return Pluralizer::plural(strtolower($toModel));
     } else {
         if (in_array($relationType, array('bt', 'mo'))) {
             return strtolower($toModel);
         } else {
             return '';
         }
     }
 }
示例#19
0
 protected function resourceName($className)
 {
     return snake_case(Pluralizer::plural(class_basename($className)), '-');
 }
示例#20
0
 /**
  * Retrieves the plural name of the table
  * 
  * @param  boolean $format
  * @return string
  */
 public function getPlural($format = false)
 {
     if (!isset($this->plural)) {
         $this->plural = Pluralizer::plural($this->table);
     }
     return $format ? $this->formatTableName($this->plural) : $this->plural;
 }
 public static function getModelVars($originalModelName)
 {
     // figure out the format of the modelName: has _ then snake, has - then dash, has space then space, else assume CamelCase
     $modelName = $originalModelName;
     if (str_contains($modelName, '_')) {
         $modelName = Pluralizer::singular(str_replace(' ', '', ucwords(str_replace('_', ' ', $modelName))));
     } else {
         if (str_contains($modelName, '-')) {
             $modelName = Pluralizer::singular(str_replace(' ', '', ucwords(str_replace('-', ' ', $modelName))));
         } else {
             if (str_contains($modelName, ' ')) {
                 $modelName = Pluralizer::singular(str_replace(' ', '', ucwords($modelName)));
             } else {
                 $modelName = Pluralizer::singular($modelName);
             }
         }
     }
     $camelModel = strtolower(substr($modelName, 0, 1)) . substr($modelName, 1);
     // blockedEmail
     $camelModels = Pluralizer::plural($camelModel);
     // blockedEmails
     $CamelModel = strtoupper(substr($camelModel, 0, 1)) . substr($camelModel, 1);
     // BlockedEmail
     $CamelModels = strtoupper(substr($camelModels, 0, 1)) . substr($camelModels, 1);
     // BlockedEmails
     $model = strtolower($camelModel);
     // blockedemail
     $models = strtolower($camelModels);
     // blockedemails
     $Model = $CamelModel;
     // BlockedEmail
     $Models = $CamelModels;
     // BlockedEmails
     $MODEL = strtoupper($camelModel);
     // BLOCKEDEMAIL
     $MODELS = strtoupper($camelModels);
     // BLOCKEDEMAILS
     $snake_model = snake_case($camelModel);
     $snake_models = snake_case($camelModels);
     $Snake_Model = str_replace(' ', '_', ucwords(snake_case($camelModel, ' ')));
     $Snake_Models = str_replace(' ', '_', ucwords(snake_case($camelModels, ' ')));
     $SNAKE_MODEL = strtoupper($snake_model);
     $SNAKE_MODELS = strtoupper($snake_models);
     $dash_model = str_replace('_', '-', $snake_model);
     $dash_models = str_replace('_', '-', $snake_models);
     $Dash_Model = str_replace('_', '-', $Snake_Model);
     $Dash_Models = str_replace('_', '-', $Snake_Models);
     $DASH_MODEL = str_replace('_', '-', $SNAKE_MODEL);
     $DASH_MODELS = str_replace('_', '-', $SNAKE_MODELS);
     $space_model = str_replace('-', ' ', $dash_model);
     $space_models = str_replace('-', ' ', $dash_models);
     $Space_Model = str_replace('-', ' ', $Dash_Model);
     $Space_Models = str_replace('-', ' ', $Dash_Models);
     $SPACE_MODEL = str_replace('-', ' ', $DASH_MODEL);
     $SPACE_MODELS = str_replace('-', ' ', $DASH_MODELS);
     $modelVars = ['camelModel' => $camelModel, 'camelModels' => $camelModels, 'CamelModel' => $CamelModel, 'CamelModels' => $CamelModels, 'model' => $model, 'models' => $models, 'MODEL' => $MODEL, 'MODELS' => $MODELS, 'Model' => $Model, 'Models' => $Models, 'snake_model' => $snake_model, 'snake_models' => $snake_models, 'Snake_Model' => $Snake_Model, 'Snake_Models' => $Snake_Models, 'SNAKE_MODEL' => $SNAKE_MODEL, 'SNAKE_MODELS' => $SNAKE_MODELS, 'dash-model' => $dash_model, 'dash-models' => $dash_models, 'Dash-Model' => $Dash_Model, 'Dash-Models' => $Dash_Models, 'DASH-MODEL' => $DASH_MODEL, 'DASH-MODELS' => $DASH_MODELS, 'space model' => $space_model, 'space models' => $space_models, 'Space Model' => $Space_Model, 'Space Models' => $Space_Models, 'SPACE MODEL' => $SPACE_MODEL, 'SPACE MODELS' => $SPACE_MODELS];
     return $modelVars;
 }
示例#22
0
 /**
  * This is the reverse relation of belongsToMany. Children are expected to
  * store the parents' keys in an array. By default, the $foreignKey is
  * expected to be the plural of the parent object's name.
  *
  * @param  string  $otherClass
  * @param  string  $foreignKey
  * @return HasManyArray
  */
 protected function hasManyArray($otherClass, $foreignKey = null)
 {
     if (!$foreignKey) {
         $foreignKey = Pluralizer::plural(lcfirst(static::parseClassName()));
     }
     return new HasManyArray($otherClass::query(), $this, $foreignKey);
 }
 /**
  * Function to handle updating the routes file
  * for us
  * 
  * @param  string $name
  * @param  string $dir
  * @return void
  */
 public function updateRoutesFile($name, $dir)
 {
     $name = strtolower(Pluralizer::plural($name));
     $routes = implode(DIRECTORY_SEPARATOR, [$dir, 'app', 'routes.php']);
     if ($this->filesystem->exists($routes)) {
         $route = "Route::resource('" . $name . "', '" . ucwords($name) . "Controller');";
         $contents = $this->filesystem->get($routes);
         if (str_contains($contents, $route)) {
             return;
         }
         $this->filesystem->append($routes, "\n\n" . $route);
     }
 }
示例#24
0
文件: Str.php 项目: nahid/framework
 /**
  * Get the plural form of an English word.
  *
  * @param  string  $value
  * @param  int     $count
  * @return string
  */
 public static function plural($value, $count = 2)
 {
     return Pluralizer::plural($value, $count);
 }
示例#25
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);
 }
示例#26
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');");
 }
示例#27
0
    protected function makeShowInfo($model, $locales_key, $multi_key)
    {
        $models = Pluralizer::plural($model);
        // posts
        $fields = $this->cache->getFields();
        $content = array_map(function ($field, $type) use($model, $locales_key) {
            if ($type === 'boolean') {
                return "<tr>\n      <td>{{ trans('{$locales_key}.{$field}') }}</td><td>{{{ trans('utils.'.\${$model}->{$field}) }}}</td></tr>";
            }
            return "<tr>\n      <td>{{ trans('{$locales_key}.{$field}') }}</td><td>{{{ \${$model}->{$field} }}}</td></tr>";
        }, array_keys($fields), array_values($fields));
        // Now, we'll add the edit and delete buttons.
        $editAndDelete = <<<EOT
            <tr>      
                    <td>
                        {{ Form::open(array('style' => 'display: inline-block;', 'method' => 'DELETE', 'route' => array('{$multi_key}.destroy', \${$model}->id))) }}
                            {{ Form::submit(trans('utils.delete'), array('class' => 'btn btn-danger')) }}
                        {{ Form::close() }}
                        {{ link_to_route('{$multi_key}.edit', trans('utils.edit'), array(\${$model}->id), array('class' => 'btn btn-info')) }}
                    </td>
            </tr>
EOT;
        return array($content, $editAndDelete);
    }