本文整理汇总了PHP中str_plural函数的典型用法代码示例。如果您正苦于以下问题:PHP str_plural函数的具体用法?PHP str_plural怎么用?PHP str_plural使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了str_plural函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: makeCustomPostType
protected function makeCustomPostType(Post $model)
{
$postTypeSlug = strtolower(snake_case(class_basename($model)));
if ($model instanceof CustomPostType) {
$singular = property_exists($model, 'singular') ? $model->singular : str_replace(['-', '_'], ' ', $postTypeSlug);
$plural = property_exists($model, 'plural') ? $model->plural : str_plural(str_replace(['-', '_'], ' ', $postTypeSlug));
$postTypeData = $model->customPostTypeData();
if (!is_array($postTypeData)) {
$postTypeData = [];
}
$result = register_post_type($postTypeSlug, $this->buildPostTypeData($singular, $plural, $postTypeData));
if (!$result instanceof \WP_Error) {
$this->postTypes[$postTypeSlug] = get_class($model);
if (property_exists($model, 'placeholderText')) {
add_filter('enter_title_here', function ($default) use($postTypeSlug, $model) {
if ($postTypeSlug == get_current_screen()->post_type) {
$default = $model->placeholderText;
}
return $default;
});
}
}
} else {
$this->postTypes[$postTypeSlug] = get_class($model);
}
}
示例2: handle
/**
* CrudCommand constructor.
*/
public function handle()
{
$this->resource = str_replace(' ', '', $this->argument('resource'));
$this->namespace = rtrim($this->getAppNamespace(), '\\');
$this->table_single = snake_case($this->resource);
$this->table = str_plural($this->table_single);
$this->single = str_replace('_', ' ', $this->table_single);
$this->plural = str_plural($this->single);
$options = $this->input->getOptions();
if (array_has($options, 'route-prefix') and $this->option('route-prefix')) {
$this->route = $this->option('route-prefix') . '.' . $this->table_single;
} else {
$this->route = $this->table_single;
}
if (array_has($options, 'view-path') and $this->option('view-path')) {
$this->view = $this->option('view-path') . '.' . $this->table_single;
} else {
$this->view = $this->table_single;
}
if (array_has($options, 'fields') and $this->option('fields')) {
$this->fields = $this->getFields($this->option('fields'));
} else {
$this->fields = '';
}
$this->variables = ['resource' => $this->resource, 'resource_plural' => str_plural($this->resource), 'namespace' => $this->namespace, 'table' => $this->table, 'table_single' => $this->table_single, 'single' => $this->single, 'single_capital' => ucwords($this->single), 'plural' => $this->plural, 'plural_capital' => ucwords($this->plural), 'route' => $this->route, 'view' => $this->view, 'fields' => $this->fields];
}
示例3: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$name = ucwords(strtolower($this->argument('name')));
if ($this->option('fields')) {
$fields = $this->option('fields');
$fillable_array = explode(',', $fields);
foreach ($fillable_array as $value) {
$data[] = preg_replace("/(.*?):(.*)/", "\$1", trim($value));
}
$comma_separeted_str = implode("', '", $data);
$fillable = "['";
$fillable .= $comma_separeted_str;
$fillable .= "']";
$this->call('crud:controller', ['name' => str_plural($name) . 'Controller', '--crud-name' => $name]);
$this->call('crud:model', ['name' => str_singular($name), '--fillable' => $fillable]);
$this->call('crud:migration', ['name' => str_plural(strtolower($name)), '--schema' => $fields]);
$this->call('crud:view', ['name' => $name, '--fields' => $fields]);
//add CrudName to left menu
$this->call('crud:menu', ['name' => $name]);
//append crudName to custom_routes.php
$this->call('crud:route', ['name' => $name]);
} else {
$this->call('make:controller', ['name' => $name . 'Controller']);
$this->call('make:model', ['name' => $name]);
}
// Commit Database migration
$this->call('migrate');
}
示例4: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
// Models path defined in .env
$model = $this->argument('model');
$modelPath = env('MODELS');
$s = file_get_contents('app/Console/Commands/stubs/Model.stub');
$s = $this->replace($s, $model);
$output = $modelPath . str_singular($model) . '.php';
file_put_contents($output, $s);
// {-c} Controller
if ($this->option('c')) {
$s = file_get_contents('app/Console/Commands/stubs/Controller.stub');
$s = $this->replace($s, $model);
$output = "app/Http/Controllers/" . str_plural($model) . 'Controller.php';
file_put_contents($output, $s);
$this->line($s);
}
// {-m} Migration
if ($this->option('m')) {
$s = file_get_contents('app/Console/Commands/stubs/Schema.stub');
$s = $this->replace($s, $model);
$output = "database/migrations/" . date('Y_m_d_his') . "_create_" . str_plural($model) . 'table.php';
file_put_contents($output, $s);
$this->line($s);
}
// {-s} Seeder
if ($this->option('s')) {
$s = file_get_contents('app/Console/Commands/stubs/Seeder.stub');
$s = $this->replace($s, $model);
$output = "database/seeds/" . str_plural($model) . 'TableSeeder.php';
file_put_contents($output, $s);
}
}
示例5: likeCount
public function likeCount()
{
$count = $this->entity->likes->count();
$plural = str_plural('Like', $count);
$count = $this->entity->likes()->count();
return $count > 0 ? $count . " people like it." : "Nobody cares.";
}
示例6: handle
/**
* Handle the command.
*
* Add a default Module route, language entries etc per Module
*
*/
public function handle()
{
$module = $this->module;
$dest = $module->getPath();
$data = ['config' => _config('builder', $module), 'vendor' => $module->getVendor(), 'module_name' => studly_case($module->getSlug())];
$src = __DIR__ . '/../../resources/stubs/module';
try {
if (_config('builder.landing_page', $module)) {
/* adding routes to the module service provider class
(currently, just for the optional landing (home) page) */
$this->processFile("{$dest}/src/" . $data['module_name'] . 'ModuleServiceProvider.php', ['routes' => $src . '/routes.php'], $data);
/* adding sections to the module class
(currently, just for the optional landing (home) page)*/
$this->processFile("{$dest}/src/" . $data['module_name'] . 'Module.php', ['sections' => $src . '/sections.php'], $data, true);
}
/* generate sitemap for the module main stream */
if ($stream_slug = _config('builder.sitemap.stream_slug', $module)) {
$data['entity_name'] = studly_case(str_singular($stream_slug));
$data['repository_name'] = str_plural($stream_slug);
$this->files->parseDirectory("{$src}/config", "{$dest}/resources/config", $data);
}
/* adding module icon */
$this->processVariable("{$dest}/src/" . $data['module_name'] . 'Module.php', ' "' . _config('builder.icon', $module) . '"', 'protected $icon =', ';');
} catch (\PhpParser\Error $e) {
die($e->getMessage());
}
}
示例7: renderTableBody
/**
* write table body
*/
function renderTableBody()
{
//head
$content = '<thead>' . PHP_EOL;
//tr
$content .= '<tr>' . PHP_EOL;
//you know the rest just creating a table with head and body
foreach ($this->fieldArr as $fieldName => $value) {
$content .= '<th> ' . $fieldName . '</th>' . PHP_EOL;
}
$content .= '</tr>' . PHP_EOL;
$content .= "<thead>" . PHP_EOL;
$content .= "<tbody>" . PHP_EOL;
$content .= '@foreach( ' . str_plural($this->modelVar) . ' as ' . $this->modelVar . ')' . PHP_EOL;
foreach ($this->fieldArr as $fieldName => $value) {
$content .= '<td>{!! ' . $this->modelVar . '->' . $fieldName . ' !!}</td>' . PHP_EOL;
}
$content .= '@endforeach' . PHP_EOL;
$content .= "</tbody>" . PHP_EOL;
$this->tableContent = $content;
//writing the list file
//ToDo Needs to come from template file
$target = $this->viewTarget . '/' . str_slug($this->modelName) . "/list.blade.php";
$template = '/vendor/developernaren/laravel-crud/src/DeveloperNaren/Crud/Templates/ListView.txt';
$contentKeyArr = get_object_vars($this);
$this->write($template, $contentKeyArr, $target);
}
示例8: populateVars
/**
* Populate the name, options and path variables.
*
* @return void
*/
protected function populateVars()
{
$this->placeholder['App'] = str_replace('/', '\\', $this->argument('app'));
$this->placeholder['AppPath'] = str_replace('\\', '/', $this->placeholder['App']);
$this->placeholder['Resource'] = $this->argument('resourceName');
$this->placeholder['resource'] = str_replace('_', '-', strtolower(snake_case($this->placeholder['Resource'])));
$this->placeholder['Resources'] = $this->option('rn-plural') ? $this->option('rn-plural') : str_plural($this->argument('resourceName'));
$this->placeholder['resources'] = str_replace('_', '-', strtolower(snake_case($this->placeholder['Resources'])));
$this->placeholder['NamespacePath'] = $this->option('namespace') ? $this->option('namespace') : $this->placeholder['AppPath'] . '/' . $this->placeholder['Resources'];
$this->placeholder['Namespace'] = str_replace('/', '\\', $this->placeholder['NamespacePath']);
$this->placeholder['isViewableResource'] = $this->option('is-viewable-resource') ? true : false;
$this->placeholder['tests'] = $this->option('no-tests') ? false : true;
$this->placeholder['views'] = $this->option('no-views') ? false : true;
if ($this->option('contract-ext')) {
if (preg_match('/\\\\|\\//', $this->option('contract-ext'))) {
$this->placeholder['contractExt'] = str_replace('/', '\\', $this->option('contract-ext'));
$this->placeholder['contract'] = substr($this->placeholder['contractExt'], strrpos($this->placeholder['contractExt'], '\\') + 1);
} else {
$this->placeholder['contractExt'] = $this->placeholder['App'] . '\\Contracts\\' . $this->option('contract-ext');
$this->placeholder['contract'] = $this->option('contract-ext');
}
}
if ($this->option('handler-imp')) {
if (preg_match('/\\\\|\\//', $this->option('handler-imp'))) {
$this->placeholder['handlerImp'] = str_replace('/', '\\', $this->option('handler-imp'));
$this->placeholder['handler'] = substr($this->placeholder['handlerImp'], strrpos($this->placeholder['handlerImp'], '\\') + 1);
} else {
$this->placeholder['handlerImp'] = $this->placeholder['App'] . '\\Contracts\\' . $this->option('handler-imp');
$this->placeholder['handler'] = $this->option('handler-imp');
}
}
}
示例9: show
public function show($id)
{
$item = $this->driver->get($id);
$entity = $this->entity;
$this->layout->title = str_plural($entity->name);
$this->layout->content = \View::make('admin.entities.show', compact('item', 'entity'));
}
示例10: relates
/**
* Add relation field type.
*
* @param Entity $entity
* @param Collection $collection
* @param string $id
* @param string $ref
* @param bool $inline
*
* @return BasicRelation
*/
public function relates($entity, $collection, $id, $ref = null, $inline = false)
{
if ($ref === null) {
$ref = str_plural($id);
}
$ref = $entity->getEntitiesRepository()->resolve($ref);
$model = $entity->newModel();
if (!method_exists($model, $id)) {
$className = get_class($model);
throw new \RuntimeException("The target model [{$className}] doesn't have relation [{$id}] defined.");
}
$relation = $model->{$id}();
if (!$relation instanceof Relation) {
$className = get_class($model);
throw new \RuntimeException("The method [{$id}] of model [{$className}] did not return valid relation.");
}
$relationClassName = class_basename($relation);
$className = __NAMESPACE__ . '\\' . ($inline ? 'InlineTypes' : 'Types') . '\\' . $relationClassName;
if (!class_exists($className)) {
throw new \RuntimeException("Cruddy does not know how to handle [{$relationClassName}] relation.");
}
$instance = new $className($entity, $id, $ref, $relation);
$collection->add($instance);
return $instance;
}
示例11: getRoot
/**
* Get the root of model for the payload
*
* @return string
*/
public function getRoot()
{
if ($this->root) {
return $this->root;
}
return str_plural(strtolower(class_basename(get_class($this))));
}
示例12: rollback
public function rollback($entity, $id)
{
$modelString = 'Yab\\Quarx\\Models\\' . ucfirst($entity);
if (!class_exists($modelString)) {
$modelString = 'Yab\\Quarx\\Models\\' . ucfirst($entity) . 's';
}
if (!class_exists($modelString)) {
$modelString = 'Quarx\\Modules\\' . ucfirst(str_plural($entity)) . '.\\Models\\' . ucfirst(str_plural($entity));
}
if (!class_exists($modelString)) {
$modelString = 'Quarx\\Modules\\' . ucfirst(str_plural($entity)) . '\\Models\\' . ucfirst(str_singular($entity));
}
if (!class_exists($modelString)) {
$modelString = 'Quarx\\Modules\\' . ucfirst(str_singular($entity)) . '\\Models\\' . ucfirst(str_singular($entity));
}
if (!class_exists($modelString)) {
Quarx::notification('Could not rollback Model not found', 'warning');
return redirect(URL::previous());
}
$model = new $modelString();
$modelInstance = $model->find($id);
$archive = Archive::where('entity_id', $id)->where('entity_type', $modelString)->limit(1)->offset(1)->orderBy('id', 'desc')->first();
if (!$archive) {
Quarx::notification('Could not rollback', 'warning');
return redirect(URL::previous());
}
$archiveData = (array) json_decode($archive->entity_data);
$modelInstance->fill($archiveData);
$modelInstance->save();
Quarx::notification('Rollback was successful', 'success');
return redirect(URL::previous());
}
示例13: normalizeObject
private function normalizeObject($object)
{
$normalized_object = [];
$normalized_collections = [];
foreach ($object as $key => $value) {
if (is_array($value)) {
if (array_key_exists('id', $value)) {
#if (is_array($))
if (!array_key_exists(str_plural($key), $normalized_collections)) {
$normalized_collections[str_plural($key)] = [];
}
$result = $this->normalizeObject($value);
array_push($normalized_collections[str_plural($key)], $result['object']);
$normalized_collections = $this->mergeCollections($normalized_collections, $result['collections']);
$normalized_object[$key] = $result['object']['id'];
} else {
if (in_array('id', array_keys($value))) {
$normalized_collections = $this->mergeCollections($normalized_collections, $this->normalizeCollection($key, $value));
$normalized_object[$key] = array_map(function ($object) {
return $object['id'];
}, $value);
} else {
$normalized_object[$key] = $value;
}
}
} else {
$normalized_object[$key] = $value;
}
}
return ['object' => $normalized_object, 'collections' => $normalized_collections];
}
示例14: setRouteData
protected function setRouteData()
{
$name = str_replace('\\', '', $this->stubVariables['model']['fullNameWithoutRoot']);
$name = snake_case($name);
$this->stubVariables['route']['name'] = str_plural($name);
return $this;
}
示例15: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$camelCasedSingularName = $this->ask('Nom de la resource en camelCase [maNouvelleResourceEnCamelCase]');
$ucFirstSingularName = ucfirst($camelCasedSingularName);
$camelCasedPluralName = str_plural($camelCasedSingularName);
$ucFirstPluralName = str_plural($ucFirstSingularName);
//Todo : proposer plusieurs choix en fonction des modules/packages au lieu que le seul namespace app
$namespace = $this->ask('Namespace du domaine de la resource', 'App\\Domain\\' . $ucFirstSingularName);
//Todo : proposer plusieurs choix en fonction des modules/packages au lieu que le seul dossier app
$directory = $this->ask('Répertoire de la resource', 'app/Domain/' . $ucFirstSingularName);
//Todo : proposer plusieurs choix en fonction des modules/packages au lieu que le seul namespace app
$namespaceController = $this->ask('Namespace du controller de la resource', 'App\\Http\\Controllers\\Api\\v1');
//Todo : proposer plusieurs choix en fonction des modules/packages au lieu que le seul dossier app
$directoryController = $this->ask('Répertoire du controlleur', 'app/Http/Controllers/Api/v1');
$this->generateModel($namespace, $directory, $ucFirstSingularName);
$this->info('Model généré !');
$this->generateValidator($namespace, $directory, $ucFirstSingularName);
$this->info('Validator généré !');
$this->generateService($namespace, $directory, $ucFirstSingularName);
$this->info('Service généré !');
$this->generateTransformer($namespace, $directory, $ucFirstSingularName, $camelCasedSingularName, $camelCasedPluralName);
$this->info('Transformer généré !');
$this->generateController($namespaceController, $directoryController, $ucFirstPluralName, $namespace, $ucFirstSingularName, $camelCasedPluralName);
$this->info('Controller généré !');
//$this->comment(PHP_EOL.Inspiring::quote().PHP_EOL);
}