本文整理汇总了PHP中str_singular函数的典型用法代码示例。如果您正苦于以下问题:PHP str_singular函数的具体用法?PHP str_singular怎么用?PHP str_singular使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了str_singular函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: replaceClass
protected function replaceClass($stub, $name)
{
$stub = parent::replaceClass($stub, $name);
$noControllerName = str_replace('Controller', '', $this->getNameInput());
$dummyRoute = config('administr.prefix') . '.' . str_plural(strtolower(snake_case($noControllerName, '-')));
$stub = str_replace('dummyroute', $dummyRoute, $stub);
$appNamespace = $this->getLaravel()->getNamespace();
$dummyModel = str_singular($noControllerName);
$dummyModelNamespaced = $appNamespace . 'Models\\' . $dummyModel;
$stub = str_replace('DummyModelNamespaced', $dummyModelNamespaced, $stub);
$stub = str_replace('DummyModel', $dummyModel, $stub);
$dummyForm = str_singular($noControllerName) . 'Form';
$dummyFormNamespaced = $appNamespace . 'Http\\Forms\\' . $dummyForm;
$stub = str_replace('DummyFormNamespaced', $dummyFormNamespaced, $stub);
$stub = str_replace('DummyForm', $dummyForm, $stub);
$dummyListView = str_plural($noControllerName) . 'ListView';
$dummyListViewNamespaced = $appNamespace . 'Http\\ListViews\\' . $dummyListView;
$stub = str_replace('DummyListViewNamespaced', $dummyListViewNamespaced, $stub);
$stub = str_replace('DummyListView', $dummyListView, $stub);
$viewPath = config('administr.viewPath');
if (strlen($viewPath) > 0) {
$viewPath .= '.';
}
$dummyView = $viewPath . str_plural(snake_case(class_basename($noControllerName), '-'));
$stub = str_replace('dummyview', $dummyView, $stub);
return $stub;
}
示例2: __construct
/**
* Constructor function
*
* @param string $type
* @param array $items
*/
public function __construct($type, $singular = '', $items = array(), $modelClassName)
{
$this->entity = $type;
$this->entity_singular = $singular ?: str_singular($type);
$this->setItems($items);
$this->modelClassName = $modelClassName;
}
示例3: buildClassContents
/**
* Get contents for base.stub
*
* @author Verron Knowles <Verron.Knowles@develme.com>
* @return string
*/
protected function buildClassContents($name, $stub_data)
{
$table_name = $this->getTableName($name);
$simple_name = str_singular($table_name);
$proper_name = $this->getProperName($simple_name);
$model_name = $this->input->getOption('model');
// Setup fillable namespace
$fillable = array();
foreach ($stub_data as $stubname => $column) {
if (empty(strpos($stubname, '&'))) {
if (!in_array($column['name'], $this->ignore_items, $column['name'])) {
$column_name = $column['name'];
$fillable[] = "\"{$column_name}\"";
}
}
}
$fillable = implode(",", $fillable);
$stub_contents = "";
foreach ($this->stub_names as $view) {
$stub_location = $this->getStubDirectory() . "{$view}.stub";
if ($this->files->isFile($stub_location)) {
$stub_contents .= file_get_contents($stub_location) . "\n";
}
}
// Build replacement tags
$replacements = compact('proper_name', 'simple_name', 'model_name', 'table_name', 'fillable');
$this->replaceTag($stub_contents, $replacements);
return $stub_contents;
}
示例4: singular
/**
* Create a singular version of this name. Allows us to override
* any names that str_singular doesn't do correctly.
*
* @param string $name
* @return string
*/
protected function singular($name)
{
if ($name == "menus") {
return "menu";
}
return str_singular($name);
}
示例5: goToView
public function goToView($route, $parentAssociation, $additionalAssigns, $content)
{
$route_array = explode('.', $route);
if (count($route_array) == 2) {
$parent = $route_array[0];
$action = $route_array[1];
$controller = $parent;
} elseif (count($route_array) == 3) {
$parent = $route_array[0];
$child = $route_array[1];
$action = $route_array[2];
$controller = $child;
} else {
throw new InvalidArgumentException("{$route} is not in correct format");
}
$assignStr = str_singular($controller);
$assigns = array($assignStr => $content);
if (!null_or_empty($parentAssociation)) {
$assigns = array_merge($assigns, $parentAssociation);
}
if (!null_or_empty($additionalAssigns)) {
$assigns = array_merge($assigns, $additionalAssigns);
}
return $this->view->make($controller . "." . $action, $assigns);
}
示例6: create
/**
* Show the form for creating a new resource.
* GET /model/create
*
* @return Response
*/
public function create()
{
$model_class = $this->config->get('entrust.' . str_singular($this->resource));
$model = new $model_class();
$relations = $this->relation->lists('name', 'id');
return view('entrust-gui::' . $this->resource . '.create', compact('model', 'relations'));
}
示例7: addInclude
/**
* Add include to the construct method
*
* @param $stub
* @param $include
* @return $this
*/
private function addInclude(&$stub, $include)
{
$stub = str_replace('DummyIncludeCamel', camel_case($include), $stub);
$stub = str_replace('DummyIncludeStudly', studly_case($include), $stub);
$stub = str_replace('DummyIncludeSingleStudly', studly_case(str_singular($include)), $stub);
return $this;
}
示例8: testStrings
public function testStrings()
{
$this->assertTrue(str_singular('match') == 'match');
$this->assertTrue(str_singular('matches') == 'match');
$this->assertTrue(str_plural('matches') == 'matches');
$this->assertTrue(str_plural('match') == 'matches');
}
示例9: handle
/**
* Handle the command.
*
*/
public function handle()
{
$module = $this->module;
$stream = $this->stream;
$assignment = $this->assignment;
$destination = $module->getPath();
$entity = __DIR__ . '/../../resources/stubs/entity';
$source = $entity . '/code/{{namespace|studly_case}}/';
/* get the field config params from build.php */
$fieldConfig = _getFieldConfig($module, $stream->getNamespace(), $assignment->getFieldSlug());
/* protect module classes from being overwriten */
$this->files->setAvoidOverwrite(_config('builder.avoid_overwrite', $module));
/* get the template data */
$data = ['config' => _config('builder', $module), 'field_slug' => $assignment->getFieldSlug(), 'vendor' => $module->getVendor(), 'module_slug' => $module->getSlug(), 'namespace' => $stream->getNamespace(), 'stream_slug' => $stream->getSlug(), 'entity_name' => studly_case(str_singular($stream->getSlug())), 'column_template' => $fieldConfig['column_template']];
$entityDest = $destination . '/src/' . (_config('builder.group', $module) ? $data['namespace'] . '/' : '') . $data['entity_name'];
/* get the assigned class name, i.e. TextFieldType */
$fieldTypeClassName = _getFieldTypeClassName($assignment);
/* (1) process the form builder class */
if (!$fieldConfig['hide_field']) {
$this->processFormBuilder($entityDest . '/Form/' . $data['entity_name'] . 'FormBuilder.php', $entity . '/templates/field/form/', $fieldTypeClassName, $data);
}
/* (2) process the table column class */
if (!$fieldConfig['hide_column']) {
$this->processTableColumns($entityDest . '/Table/' . $data['entity_name'] . 'TableColumns.php', $entity . '/templates/field/table/' . ($data['column_template'] ? 'template/' : ''), $fieldTypeClassName, $data);
}
/* (3) process the field language file */
$this->processFile($destination . '/resources/lang/en/field.php', [$data['field_slug'] => $entity . '/templates/module/field.php'], $data);
}
示例10: handle
public function handle()
{
$name = trim($this->argument('name'));
$nameSingular = str_singular($name);
$status = 0;
$controllerCmdArgs = ['name' => "{$name}Controller"];
if ($this->option('translated')) {
$controllerCmdArgs['--translated'] = true;
}
$status = $this->call('administr:controller', $controllerCmdArgs);
$status = $this->call('administr:form', ['name' => "{$nameSingular}Form"]);
$modelCmdArgs = ['name' => $nameSingular];
if ($this->option('translated')) {
$modelCmdArgs['--translated'] = true;
}
$status = $this->call('administr:model', $modelCmdArgs);
$status = $this->call('administr:listview', ['name' => "{$name}ListView"]);
$status = $this->call('make:seed', ['name' => "{$name}Seeder"]);
$table = str_plural(snake_case(class_basename($name)));
$status = $this->call('make:migration', ['name' => "create_{$table}_table", '--create' => $table]);
if ($status !== 0) {
$this->error('Some of the commands were not executed successfuly.');
}
$this->info('Admin scaffold generated!');
}
示例11: 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());
}
示例12: getMainArea
/**
* Gets model names for the main navigation
*
* @return array
*/
public function getMainArea($currentArea)
{
$mainArea = '';
$currentArea = str_singular($currentArea);
foreach (config('admin.navigation_tree') as $parent) {
if (!$parent['children']) {
if ($currentArea == $parent['name']) {
$mainArea = $parent['name'];
}
} else {
foreach ($parent['children'] as $child) {
if (!$child['children']) {
if ($currentArea == $child['name']) {
$mainArea = $parent['name'];
}
} else {
foreach ($child['children'] as $grandchild) {
if ($currentArea == $grandchild['name']) {
$mainArea = $parent['name'];
}
}
}
}
}
}
return $mainArea;
}
示例13: getModelName
/**
* Get the class name for the Eloquent model generator.
*
* @return string
*/
protected function getModelName()
{
if ($this->option('model')) {
return trim($this->option('model'));
}
return ucwords(str_singular(camel_case($this->meta['table'])));
}
示例14: handle
/**
* Handle the command.
*
*/
public function handle()
{
$stream = $this->stream;
$module = $this->module;
$entityPath = __DIR__ . '/../../resources/stubs/entity';
$modulePath = __DIR__ . '/../../resources/stubs/module';
$dest = $module->getPath();
/* seed file path for this entity */
$seedFile = "{$dest}/resources/seeders/" . strtolower(str_singular($stream->getSlug())) . ".php";
$data = ['config' => _config('builder', $module), 'vendor' => $module->getVendor(), 'namespace' => $stream->getNamespace(), 'module_slug' => $module->getSlug(), 'stream_slug' => $stream->getSlug(), 'entity_name' => studly_case(str_singular($stream->getSlug())), 'seeder_data' => file_exists($seedFile) ? file_get_contents($seedFile) : ''];
$moduleName = studly_case($data['module_slug']);
/* protect module classes from being overwriten */
$this->files->setAvoidOverwrite(_config('builder.avoid_overwrite', $module));
/* initially, copy the entity template files to the module src folder */
if (_config('builder.group', $module)) {
$this->files->parseDirectory($entityPath . "/code/", "{$dest}/src", $data);
} else {
$this->files->parseDirectory($entityPath . "/code/{{namespace|studly_case}}/", "{$dest}/src", $data);
$this->files->parseDirectory($entityPath . "/code/Http", "{$dest}/src/Http", $data);
}
/* create an empty seeder if it does not exist */
$this->put("{$dest}/resources/seeders/" . strtolower($data['entity_name']) . '.php', '', true);
try {
/* stitch the entity with the module classes */
$this->processFile("{$dest}/src/{$moduleName}" . 'ModuleServiceProvider.php', ['routes' => $entityPath . '/templates/module/routes.php', 'bindings' => $entityPath . '/templates/module/bindings.php', 'singletons' => $entityPath . '/templates/module/singletons.php'], $data);
$this->processFile("{$dest}/src/{$moduleName}" . 'Module.php', ['sections' => $entityPath . '/templates/module/sections.php'], $data);
$this->processFile("{$dest}/src/{$moduleName}" . 'ModuleSeeder.php', ['seeders' => $entityPath . '/templates/module/seeding.php'], $data);
$this->processFile("{$dest}/resources/lang/en/section.php", [strtolower(str_plural($data['entity_name'])) => $entityPath . '/templates/module/section.php'], $data);
$this->processFile("{$dest}/resources/config/permissions.php", [$data['stream_slug'] => $entityPath . '/templates/module/permissions.php'], $data);
$this->processFile("{$dest}/resources/lang/en/stream.php", [$data['stream_slug'] => $entityPath . '/templates/module/stream.php'], $data);
$this->processFile("{$dest}/resources/lang/en/permission.php", [$data['stream_slug'] => $entityPath . '/templates/module/permission.php'], $data);
} catch (\PhpParser\Error $e) {
die($e->getMessage());
}
}
示例15: __construct
public function __construct()
{
//$this->beforeFilter(function(){ });
$this->uriSegment = null;
$this->modelName = null;
$this->viewsPath = null;
$this->resourceId = null;
if (Route::input('alias') !== null) {
$this->uriSegment = Route::input('alias');
$this->viewsPath = File::exists(app_path('views/' . Config::get('reactiveadmin::uri') . '/' . $this->uriSegment)) ? Config::get('reactiveadmin::uri') . '.' . $this->uriSegment : 'reactiveadmin::default';
$this->modelName = studly_case(str_singular(Route::input('alias')));
$this->modelWrapper = App::make('model_wrapper');
$this->modelWrapper->model($this->modelName);
if (Route::input('id') !== null) {
$this->resourceId = Route::input('id');
}
View::share('config', $this->modelWrapper->getConfig());
// TODO: refactor this!
// custom behavior
switch ($this->uriSegment) {
case 'settings':
View::composer(array('admin.' . $this->viewsPath . '.index'), function ($view) {
$view->with('settings', Settings::all());
});
break;
default:
# code...
break;
}
}
View::share('view', $this->uriSegment);
View::share('model', $this->modelName);
}