當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Inflector::pluralize方法代碼示例

本文整理匯總了PHP中Doctrine\Common\Inflector\Inflector::pluralize方法的典型用法代碼示例。如果您正苦於以下問題:PHP Inflector::pluralize方法的具體用法?PHP Inflector::pluralize怎麽用?PHP Inflector::pluralize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\Common\Inflector\Inflector的用法示例。


在下文中一共展示了Inflector::pluralize方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: generate

 /**
  * Generate the CRUD controller.
  *
  * @param BundleInterface   $bundle           A bundle object
  * @param string            $entity           The entity relative class name
  * @param ClassMetadataInfo $metadata         The entity class metadata
  * @param string            $format           The configuration format (xml, yaml, annotation)
  * @param string            $routePrefix      The route name prefix
  * @param array             $needWriteActions Wether or not to generate write actions
  *
  * @throws \RuntimeException
  */
 public function generate(BundleInterface $bundle, $entity, ClassMetadataInfo $metadata, $format, $routePrefix, $needWriteActions, $forceOverwrite)
 {
     $this->routePrefix = $routePrefix;
     $this->routeNamePrefix = self::getRouteNamePrefix($routePrefix);
     $this->actions = $needWriteActions ? array('index', 'show', 'new', 'edit', 'delete') : array('index', 'show');
     if (count($metadata->identifier) != 1) {
         throw new \RuntimeException('The CRUD generator does not support entity classes with multiple or no primary keys.');
     }
     $this->entity = $entity;
     $this->entitySingularized = lcfirst(Inflector::singularize($entity));
     $this->entityPluralized = lcfirst(Inflector::pluralize($entity));
     $this->bundle = $bundle;
     $this->metadata = $metadata;
     $this->setFormat($format);
     $this->generateControllerClass($forceOverwrite);
     $dir = sprintf('%s/Resources/views/%s', $this->rootDir, str_replace('\\', '/', strtolower($this->entity)));
     if (!file_exists($dir)) {
         $this->filesystem->mkdir($dir, 0777);
     }
     $this->generateIndexView($dir);
     if (in_array('show', $this->actions)) {
         $this->generateShowView($dir);
     }
     if (in_array('new', $this->actions)) {
         $this->generateNewView($dir);
     }
     if (in_array('edit', $this->actions)) {
         $this->generateEditView($dir);
     }
     $this->generateTestClass();
     $this->generateConfiguration();
 }
開發者ID:spinx,項目名稱:SensioGeneratorBundle,代碼行數:44,代碼來源:DoctrineCrudGenerator.php

示例2: resolve

 /**
  * {@inheritdoc}
  */
 public function resolve(Route $route, RouteCollectionAccessor $routes)
 {
     if (!in_array('OPTIONS', $route->getMethods(), true)) {
         return;
     }
     $entryPath = $this->getEntryPath($route);
     if (!$entryPath) {
         return;
     }
     $nameFromController = $this->getNameFromController($route);
     if (!$nameFromController) {
         return;
     }
     $nameFromPath = str_replace('/', '', $entryPath);
     if ($nameFromPath === $nameFromController) {
         return;
     }
     if (false !== ($pos = strrpos($entryPath, '/'))) {
         $pluralName = substr($entryPath, $pos + 1);
         $singleName = substr($nameFromController, $pos - substr_count($entryPath, '/') + 1);
     } else {
         $pluralName = $entryPath;
         $singleName = $nameFromController;
     }
     if ($pluralName === $singleName || $pluralName !== Inflector::pluralize($singleName)) {
         return;
     }
     $singlePath = str_replace('/' . $pluralName, '/' . $singleName, $route->getPath());
     $singleRoute = $routes->cloneRoute($route);
     $singleRoute->setPath($singlePath);
     $singleRoute->setOption('old_options', true);
     $pluralRouteName = $routes->getName($route);
     $routes->insert($routes->generateRouteName($pluralRouteName), $singleRoute, $pluralRouteName);
 }
開發者ID:Maksold,項目名稱:platform,代碼行數:37,代碼來源:OldOptionsRouteOptionsResolver.php

示例3: pluralize

 /**
  * Return singular or plural parameter, based on the given count
  *
  * @param  integer $count
  * @param  string  $singular
  * @param  string  $plural
  * @return string
  */
 public static function pluralize($count = 1, $singular, $plural = null)
 {
     if ($count == 1) {
         return $singular;
     }
     return is_null($plural) ? Inflector::pluralize($singular) : $plural;
 }
開發者ID:intervention,項目名稱:helper,代碼行數:15,代碼來源:String.php

示例4: process

 /**
  * @param ContainerBuilder $container
  */
 public function process(ContainerBuilder $container)
 {
     $bundles = $container->getParameter('kernel.bundles');
     $reader = $container->get('annotation_reader');
     $registry = $container->getDefinition('lemon_rest.object_registry');
     foreach ($bundles as $name => $bundle) {
         $reflection = new \ReflectionClass($bundle);
         $baseNamespace = $reflection->getNamespaceName() . '\\Entity\\';
         $dir = dirname($reflection->getFileName()) . '/Entity';
         if (is_dir($dir)) {
             $finder = new Finder();
             $iterator = $finder->files()->name('*.php')->in($dir);
             /** @var SplFileInfo $file */
             foreach ($iterator as $file) {
                 // Translate the directory path from our starting namespace forward
                 $expandedNamespace = substr($file->getPath(), strlen($dir) + 1);
                 // If we are in a sub namespace add a trailing separation
                 $expandedNamespace = $expandedNamespace === false ? '' : $expandedNamespace . '\\';
                 $className = $baseNamespace . $expandedNamespace . $file->getBasename('.php');
                 if (class_exists($className)) {
                     $reflectionClass = new \ReflectionClass($className);
                     foreach ($reader->getClassAnnotations($reflectionClass) as $annotation) {
                         if ($annotation instanceof Resource) {
                             $name = $annotation->name ?: Inflector::pluralize(lcfirst($reflectionClass->getShortName()));
                             $definition = new Definition('Lemon\\RestBundle\\Object\\Definition', array($name, $className, $annotation->search, $annotation->create, $annotation->update, $annotation->delete, $annotation->partialUpdate));
                             $container->setDefinition('lemon_rest.object_resources.' . $name, $definition);
                             $registry->addMethodCall('add', array($definition));
                         }
                     }
                 }
             }
         }
     }
 }
開發者ID:stanlemon,項目名稱:rest-bundle,代碼行數:37,代碼來源:RegisterResourcePass.php

示例5: execute

 /**
  * Executes the command.
  * 
  * @param  \Symfony\Component\Console\Input\InputInterface   $input
  * @param  \Symfony\Component\Console\Output\OutputInterface $output
  * @return object|\Symfony\Component\Console\Output\OutputInterface
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = Configuration::get();
     $templates = str_replace('Commands', 'Templates', __DIR__);
     $contents = [];
     $generator = new ViewGenerator($this->describe);
     $data = ['{name}' => $input->getArgument('name'), '{pluralTitle}' => Inflector::ucwords(str_replace('_', ' ', Inflector::pluralize($input->getArgument('name')))), '{plural}' => Inflector::pluralize($input->getArgument('name')), '{singular}' => Inflector::singularize($input->getArgument('name'))];
     $contents['create'] = $generator->generate($data, $templates, 'create');
     $contents['edit'] = $generator->generate($data, $templates, 'edit');
     $contents['index'] = $generator->generate($data, $templates, 'index');
     $contents['show'] = $generator->generate($data, $templates, 'show');
     $fileName = $config->folders->views . '/' . $data['{plural}'] . '/';
     $layout = $config->folders->views . '/layouts/master.twig';
     if (!$this->filesystem->has($layout)) {
         $template = file_get_contents($templates . '/Views/layout.twig');
         $keywords = ['{application}' => $config->application->name];
         $template = str_replace(array_keys($keywords), array_values($keywords), $template);
         $this->filesystem->write($layout, $template);
     }
     foreach ($contents as $type => $content) {
         $view = $fileName . $type . '.twig';
         if ($this->filesystem->has($view)) {
             if (!$input->getOption('overwrite')) {
                 return $output->writeln('<error>View already exists.</error>');
             } else {
                 $this->filesystem->delete($view);
             }
         }
         $this->filesystem->write($view, $content);
     }
     return $output->writeln('<info>View created successfully.</info>');
 }
開發者ID:rougin,項目名稱:weasley,代碼行數:39,代碼來源:CreateViewCommand.php

示例6: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $selectedSections = $input->getArgument('sections');
     $sections = [];
     foreach (static::$availableSections as $section) {
         if (in_array($section, $selectedSections) || in_array(Inflector::pluralize($section), $selectedSections)) {
             $sections[] = $section;
         }
     }
     if (empty($sections)) {
         $sections = static::$defaultSections;
     }
     foreach ($sections as $section) {
         switch ($section) {
             case 'locale':
                 $this->displayLocale($input, $output);
                 break;
             case 'format':
                 $this->displayFormat($input, $output);
                 break;
             case 'converter':
                 $this->displayConverter($input, $output);
                 break;
             case 'provider':
                 $this->displayProvider($input, $output);
                 break;
             case 'method':
                 $this->displayMethod($input, $output);
                 break;
         }
     }
 }
開發者ID:csanquer,項目名稱:fakery-generator,代碼行數:32,代碼來源:InfoCommand.php

示例7: createOperation

 /**
  * Creates operation.
  *
  * @param ResourceInterface $resource
  * @param bool              $collection
  * @param string|array      $methods
  * @param string|null       $path
  * @param string|null       $controller
  * @param string|null       $routeName
  * @param array             $context
  *
  * @return Operation
  */
 private function createOperation(ResourceInterface $resource, $collection, $methods, $path = null, $controller = null, $routeName = null, array $context = [])
 {
     $shortName = $resource->getShortName();
     if (!isset(self::$inflectorCache[$shortName])) {
         self::$inflectorCache[$shortName] = Inflector::pluralize(Inflector::tableize($shortName));
     }
     // Populate path
     if (null === $path) {
         $path = '/' . self::$inflectorCache[$shortName];
         if (!$collection) {
             $path .= '/{id}';
         }
     }
     // Guess default method
     if (is_array($methods)) {
         $defaultMethod = $methods[0];
     } else {
         $defaultMethod = $methods;
     }
     // Populate controller
     if (null === $controller) {
         $actionName = sprintf('%s_%s', strtolower($defaultMethod), $collection ? 'collection' : 'item');
         $controller = self::DEFAULT_ACTION_PATTERN . $actionName;
         // Populate route name
         if (null === $routeName) {
             $routeName = sprintf('%s%s_%s', self::ROUTE_NAME_PREFIX, self::$inflectorCache[$shortName], $actionName);
         }
     }
     return new Operation(new Route($path, ['_controller' => $controller, '_resource' => $shortName], [], [], '', [], $methods), $routeName, $context);
 }
開發者ID:akomm,項目名稱:DunglasApiBundle,代碼行數:43,代碼來源:OperationFactory.php

示例8: createOperation

 /**
  * Creates operation.
  *
  * @param ResourceInterface $resource
  * @param bool              $collection
  * @param string|array      $methods
  * @param string|null       $path
  * @param string|null       $controller
  * @param string|null       $routeName
  * @param array             $context
  *
  * @return Operation
  */
 private function createOperation(ResourceInterface $resource, $collection, $methods, $path = null, $controller = null, $routeName = null, array $context = [])
 {
     $shortName = $resource->getShortName();
     if (!isset(self::$inflectorCache[$shortName])) {
         self::$inflectorCache[$shortName] = Inflector::pluralize(Inflector::tableize($shortName));
     }
     // Populate path
     if (null === $path) {
         $path = '/' . self::$inflectorCache[$shortName];
         if (!$collection) {
             $path .= '/{id}';
         }
     }
     // Guess default method
     if (is_array($methods)) {
         $defaultMethod = $methods[0];
     } else {
         $defaultMethod = $methods;
     }
     // Populate controller
     if (null === $controller) {
         $defaultAction = strtolower($defaultMethod);
         if ($collection) {
             $defaultAction = 'c' . $defaultAction;
         }
         $controller = self::DEFAULT_CONTROLLER . ':' . $defaultAction;
         // Populate route name
         if (null === $routeName) {
             $routeName = self::ROUTE_NAME_PREFIX . self::$inflectorCache[$shortName] . '_' . $defaultAction;
         }
     }
     return new Operation(new Route($path, ['_controller' => $controller, '_resource' => $shortName], [], [], '', [], $methods), $routeName, $context);
 }
開發者ID:GuillaumeDoury,項目名稱:DunglasApiBundle,代碼行數:46,代碼來源:OperationFactory.php

示例9: load

 public function load($resource, $type = null)
 {
     $routes = new RouteCollection();
     list($prefix, $resource) = explode('.', $resource);
     $pluralResource = Inflector::pluralize($resource);
     $rootPath = '/' . $pluralResource . '/';
     $requirements = array();
     // GET collection request.
     $routeName = sprintf('%s_api_%s_index', $prefix, $resource);
     $defaults = array('_controller' => sprintf('%s.controller.%s:indexAction', $prefix, $resource));
     $route = new Route($rootPath, $defaults, $requirements, array(), '', array(), array('GET'));
     $routes->add($routeName, $route);
     // GET request.
     $routeName = sprintf('%s_api_%s_show', $prefix, $resource);
     $defaults = array('_controller' => sprintf('%s.controller.%s:showAction', $prefix, $resource));
     $route = new Route($rootPath . '{id}', $defaults, $requirements, array(), '', array(), array('GET'));
     $routes->add($routeName, $route);
     // POST request.
     $routeName = sprintf('%s_api_%s_create', $prefix, $resource);
     $defaults = array('_controller' => sprintf('%s.controller.%s:createAction', $prefix, $resource));
     $route = new Route($rootPath, $defaults, $requirements, array(), '', array(), array('POST'));
     $routes->add($routeName, $route);
     // PUT request.
     $routeName = sprintf('%s_api_%s_update', $prefix, $resource);
     $defaults = array('_controller' => sprintf('%s.controller.%s:updateAction', $prefix, $resource));
     $route = new Route($rootPath . '{id}', $defaults, $requirements, array(), '', array(), array('PUT', 'PATCH'));
     $routes->add($routeName, $route);
     // DELETE request.
     $routeName = sprintf('%s_api_%s_delete', $prefix, $resource);
     $defaults = array('_controller' => sprintf('%s.controller.%s:deleteAction', $prefix, $resource));
     $route = new Route($rootPath . '{id}', $defaults, $requirements, array(), '', array(), array('DELETE'));
     $routes->add($routeName, $route);
     return $routes;
 }
開發者ID:lingoda,項目名稱:Sylius,代碼行數:34,代碼來源:ApiLoader.php

示例10: mapDirectory

 protected function mapDirectory(ContainerBuilder $container, $dir, $prefix)
 {
     if (!is_dir($dir)) {
         throw new \RuntimeException(sprintf("Invalid directory %s", $dir));
     }
     $reader = $container->get('annotation_reader');
     $registry = $container->getDefinition('lemon_rest.object_registry');
     $finder = new Finder();
     $iterator = $finder->files()->name('*.php')->in($dir);
     if (substr($prefix, -1, 1) !== "\\") {
         $prefix .= "\\";
     }
     /** @var \SplFileInfo $file */
     foreach ($iterator as $file) {
         // Translate the directory path from our starting namespace forward
         $expandedNamespace = substr($file->getPath(), strlen($dir) + 1);
         // If we are in a sub namespace add a trailing separation
         $expandedNamespace = $expandedNamespace === false ? '' : $expandedNamespace . '\\';
         $className = $prefix . $expandedNamespace . $file->getBasename('.php');
         if (class_exists($className)) {
             $reflectionClass = new \ReflectionClass($className);
             foreach ($reader->getClassAnnotations($reflectionClass) as $annotation) {
                 if ($annotation instanceof Resource) {
                     $name = $annotation->name ?: Inflector::pluralize(lcfirst($reflectionClass->getShortName()));
                     $definition = new Definition('Lemon\\RestBundle\\Object\\Definition', array($name, $className, $annotation->search, $annotation->create, $annotation->update, $annotation->delete, $annotation->partialUpdate));
                     $container->setDefinition('lemon_rest.object_resources.' . $name, $definition);
                     $registry->addMethodCall('add', array($definition));
                 }
             }
         }
     }
 }
開發者ID:stanlemon,項目名稱:rest-bundle,代碼行數:32,代碼來源:RegisterMappingsPass.php

示例11: plural

 /**
  * Get the plural form of an English word.
  *
  * @param  string  $value
  * @param  int     $count
  * @return string
  */
 public static function plural($value, $count = 2)
 {
     if ((int) $count === 1 || static::uncountable($value)) {
         return $value;
     }
     $plural = Inflector::pluralize($value);
     return static::matchCase($plural, $value);
 }
開發者ID:bryanashley,項目名稱:framework,代碼行數:15,代碼來源:Pluralizer.php

示例12: getTableName

 /**
  * Resolves a table's name, following the plural naming scheme.
  *
  * @param $class string|object An instance of p810\Model\Model or a string.
  * @return string
  */
 public static function getTableName($class)
 {
     if (is_object($class)) {
         $reflection = new \ReflectionClass($class);
         $class = $reflection->getShortName();
     }
     return lcfirst(Inflector::pluralize($class));
 }
開發者ID:p810,項目名稱:mysql-helper,代碼行數:14,代碼來源:Table.php

示例13: getDefaultConfiguration

 private function getDefaultConfiguration()
 {
     $item = ucwords(str_replace('-', ' ', $this->getTaxonomyName()));
     $plural = Inflector::pluralize($item);
     $labels = ['name' => sprintf('%s', $plural), 'singular_name' => sprintf('%s', $item), 'menu_name' => __(sprintf('%s', $item)), 'all_items' => __(sprintf('All %s', $plural)), 'parent_item' => __(sprintf('Parent %s', $item)), 'parent_item_colon' => __(sprintf('Parent %s:', $item)), 'new_item_name' => __(sprintf('New %s', $item)), 'add_new_item' => __(sprintf('Add %s', $item)), 'edit_item' => __(sprintf('Edit %s', $item)), 'update_item' => __(sprintf('Update %s', $item)), 'view_item' => __(sprintf('View %s', $item)), 'separate_items_with_commas' => __(sprintf('Separate %s with commas', strtolower($plural))), 'add_or_remove_items' => __(sprintf('Add or remove %s', strtolower($plural))), 'choose_from_most_used' => __('Choose from the most used'), 'popular_items' => __(sprintf('Popular %s', $plural)), 'search_items' => __(sprintf('Search %s', $plural)), 'not_found' => __('Not Found')];
     $args = ['labels' => $labels, 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => false];
     return $args;
 }
開發者ID:stoutlogic,項目名稱:understory,代碼行數:8,代碼來源:TaxonomyBuilder.php

示例14: getSkeleton

 protected function getSkeleton($name)
 {
     $skeleton = new Skeleton($this->getSkeletonPath('entity'));
     $name = S::upperCamelize($name);
     $skeleton->entity_name = $name;
     $skeleton->table = Inflector::pluralize(S::replace(S::dasherize($name), '-', '_'));
     return $skeleton;
 }
開發者ID:glynnforrest,項目名稱:neptune,代碼行數:8,代碼來源:CreateEntityCommand.php

示例15: getCollectionRoute

 public function getCollectionRoute($class)
 {
     $route = 'get_' . Inflector::pluralize($this->getRouteResourceName($class));
     if ($this->router->getRouteCollection()->get($route) === null) {
         throw new \InvalidArgumentException('That entity does not have a corresponding collection route');
     }
     return $route;
 }
開發者ID:dstansby,項目名稱:camdram,代碼行數:8,代碼來源:EntityUrlGenerator.php


注:本文中的Doctrine\Common\Inflector\Inflector::pluralize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。