本文整理汇总了PHP中Illuminate\Support\Pluralizer::singular方法的典型用法代码示例。如果您正苦于以下问题:PHP Pluralizer::singular方法的具体用法?PHP Pluralizer::singular怎么用?PHP Pluralizer::singular使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Pluralizer
的用法示例。
在下文中一共展示了Pluralizer::singular方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getScaffoldedTemplate
/**
* Get the scaffolded template for a view
*
* @param string $name
* @return string Compiled template
*/
protected function getScaffoldedTemplate($name)
{
$model = $this->cache->getModelName();
// post
$models = Pluralizer::plural($model);
// posts
$Models = ucwords($models);
// Posts
$Model = Pluralizer::singular($Models);
// Post
// Create and Edit views require form elements
if ($name === 'create.blade' or $name === 'edit.blade') {
$formElements = $this->makeFormElements();
$this->template = str_replace('{{formElements}}', $formElements, $this->template);
}
// Replace template vars in view
foreach (array('model', 'models', 'Models', 'Model') as $var) {
$this->template = str_replace('{{' . $var . '}}', ${$var}, $this->template);
}
// And finally create the table rows
list($headings, $fields, $editAndDeleteLinks) = $this->makeTableRows($model);
$this->template = str_replace('{{headings}}', implode(PHP_EOL . "\t\t\t\t", $headings), $this->template);
$this->template = str_replace('{{fields}}', implode(PHP_EOL . "\t\t\t\t\t", $fields) . PHP_EOL . $editAndDeleteLinks, $this->template);
return $this->template;
}
示例2: getScaffoldedTemplate
/**
* Get the scaffolded template for a view
*
* @param string $name
* @return string Compiled template
*/
protected function getScaffoldedTemplate($name)
{
$model = $this->cache->getModelName();
// post
$models = Pluralizer::plural($model);
// posts
$Models = ucwords($models);
// Posts
$Model = Pluralizer::singular($Models);
// Post
$layouts_key = 'layouts.' . $this->cache->getValue('layout');
$locales_key = empty($this->cache->getValue('namespace')) ? $models : $this->cache->getValue('namespace') . "/{$models}";
$multi_key = empty($this->cache->getValue('namespace')) ? $models : str_replace('/', '.', $this->cache->getValue('namespace')) . ".{$models}";
// Create and Edit views require form elements
if ($name === 'create.blade' or $name === 'edit.blade' or $name === 'fields.blade') {
$formElements = $this->makeFormElements($locales_key);
$this->template = str_replace('{{formElements}}', $formElements, $this->template);
}
// Replace template vars in view
foreach (array('model', 'models', 'Models', 'Model', 'layouts_key', 'locales_key', 'multi_key') as $var) {
$this->template = str_replace('{{' . $var . '}}', ${$var}, $this->template);
}
// And finally create the table rows
if ($name === 'index.blade') {
list($headings, $fields, $editAndDeleteLinks) = $this->makeTableRows($model, $locales_key, $multi_key);
$this->template = str_replace('{{headings}}', implode(PHP_EOL . "\t\t\t\t", $headings), $this->template);
$this->template = str_replace('{{fields}}', implode(PHP_EOL . "\t\t\t\t\t", $fields) . PHP_EOL . $editAndDeleteLinks, $this->template);
}
if ($name === 'show.blade') {
list($content, $editAndDeleteLinks) = $this->makeShowInfo($model, $locales_key, $multi_key);
$this->template = str_replace('{{content}}', implode(PHP_EOL . "\t\t\t\t\t", $content) . PHP_EOL . $editAndDeleteLinks, $this->template);
}
return $this->template;
}
示例3: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
// Scaffolding should always begin with the singular
// form of the now.
$this->model = Pluralizer::singular($this->argument('name'));
$this->fields = $this->option('fields');
if (is_null($this->fields)) {
throw new MissingFieldsException('You must specify the fields option.');
}
// We're going to need access to these values
// within future commands. I'll save them
// to temporary files to allow for that.
$this->cache->fields($this->fields);
$this->cache->modelName($this->model);
$this->generateModel();
$this->generateController();
$this->generateViews();
$this->generateMigration();
$this->generateSeed();
if (get_called_class() === 'Way\\Generators\\Commands\\ScaffoldGeneratorCommand') {
$this->generateTest();
}
$this->generator->updateRoutesFile($this->model);
$this->info('Updated ' . app_path() . '/routes.php');
// We're all finished, so we
// can delete the cache.
$this->cache->destroyAll();
}
示例4: generate
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);
}
示例5: getTemplate
/**
* 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);
}
示例6: setApiName
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;
}
示例7: formatTree
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);
}
}
}
}
示例8: getScaffoldedController
/**
* 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: getTemplate
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;
}
示例10: getScaffoldedController
/**
* 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;
}
示例11: parseResourceName
/**
* 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: createTableMigration
/**
* 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);
}
}
示例13: getScaffoldedController
/**
* 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;
}
示例14: fire
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('|***************************************************|');
}
示例15: singular
public function singular($word)
{
return Pluralizer::singular($word);
}