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


PHP Inflector::singularize方法代碼示例

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


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

示例1: convertArrayToXml

 /**
  * Convert an Array to XML
  * @param string $root_node - name of the root node to be converted
  * @param array $data - array to be converted
  * @throws \Exception
  * @return \DOMNode
  */
 protected function convertArrayToXml($root_node, $data = array())
 {
     if (!$this->isValidTagName($root_node)) {
         throw new \Exception('Array to XML Conversion - Illegal character in element name: ' . $root_node);
     }
     $node = $this->xml->createElement($root_node);
     if (is_scalar($data)) {
         $node->appendChild($this->xml->createTextNode($this->bool2str($data)));
     }
     if (is_array($data)) {
         foreach ($data as $key => $value) {
             $this->current_node_name = $root_node;
             $key = is_numeric($key) ? Inflector::singularize($this->current_node_name) : $key;
             $node->appendChild($this->convertArrayToXml($key, $value));
             unset($data[$key]);
         }
     }
     if (is_object($data)) {
         // Catch toString objects, and datetime. Note Closure's will fall into here
         if (method_exists($data, '__toString')) {
             $node->appendChild($this->xml->createTextNode($data->__toString()));
         } elseif ($data instanceof \DateTime) {
             $node->appendChild($this->xml->createTextNode($data->format(\DateTime::ISO8601)));
         } else {
             throw new \Exception('Invalid data type used in Array to XML conversion. Must be object of \\DateTime or implement __toString()');
         }
     }
     return $node;
 }
開發者ID:leedavis81,項目名稱:drest-common,代碼行數:36,代碼來源:Xml.php

示例2: postBuild

 /**
  * Execute after types are built.
  */
 public function postBuild()
 {
     $types_build_path = $this->getBuildPath() ? "{$this->getBuildPath()}/types.php" : null;
     if ($types_build_path) {
         $result = [];
         $result[] = '<?php';
         $result[] = '';
         if ($this->getStructure()->getConfig('header_comment')) {
             $result = array_merge($result, explode("\n", $this->getStructure()->getConfig('header_comment')));
             $result[] = '';
         }
         $namespace = $this->getStructure()->getNamespace();
         if ($namespace) {
             $namespace = ltrim($namespace, '\\');
         }
         if ($this->getStructure()->getNamespace()) {
             $result[] = '/**';
             $result[] = ' * @package ' . $this->getStructure()->getNamespace();
             $result[] = ' */';
         }
         $result[] = 'return [';
         foreach ($this->getStructure()->getTypes() as $current_type) {
             $result[] = '    ' . var_export($namespace . '\\' . Inflector::classify(Inflector::singularize($current_type->getName())), true) . ',';
         }
         $result[] = '];';
         $result[] = '';
         $result = implode("\n", $result);
         if (is_file($types_build_path) && file_get_contents($types_build_path) === $result) {
             return;
         } else {
             file_put_contents($types_build_path, $result);
             $this->triggerEvent('on_types_built', [$types_build_path]);
         }
     }
 }
開發者ID:activecollab,項目名稱:databasestructure,代碼行數:38,代碼來源:TypesBuilder.php

示例3: transform

 public function transform($entities)
 {
     foreach ($entities as &$entity) {
         $entity['icon'] = $this->getIcon(Inflector::singularize($entity['name']));
     }
     return $entities;
 }
開發者ID:rlamarche,項目名稱:NgAdminGeneratorBundle,代碼行數:7,代碼來源:EntityToEntityWithIconTransformer.php

示例4: arrayToXml

 public static function arrayToXml(array $data, \SimpleXMLElement $xml, $parentKey = null, $keyFilterCallback = null)
 {
     foreach ($data as $k => $v) {
         if (!is_numeric($k) && is_callable($keyFilterCallback)) {
             $k = call_user_func($keyFilterCallback, $k);
         }
         if (is_array($v)) {
             if (!is_numeric($k)) {
                 self::arrayToXml($v, $xml->addChild($k), $k, $keyFilterCallback);
             } else {
                 self::arrayToXml($v, $xml->addChild(Inflector::singularize($parentKey)), null, $keyFilterCallback);
             }
         } else {
             if (!is_numeric($k)) {
                 $xml->addChildWithCDATA($k, $v);
             } else {
                 if (!is_null($parentKey)) {
                     $xml->addChildWithCDATA(Inflector::singularize($parentKey), $v);
                 } else {
                     throw new \Exception("Array To xml forma error: invalid element name {$k}");
                 }
             }
         }
     }
     return $xml;
 }
開發者ID:lrusev,項目名稱:bump-common,代碼行數:26,代碼來源:Utils.php

示例5: buildType

 /**
  * @param TypeInterface $type
  */
 public function buildType(TypeInterface $type)
 {
     $class_name = Inflector::classify(Inflector::singularize($type->getName()));
     $base_class_name = 'Base\\' . $class_name;
     $class_build_path = $this->getBuildPath() ? "{$this->getBuildPath()}/{$class_name}.php" : null;
     if ($class_build_path && is_file($class_build_path)) {
         $this->triggerEvent('on_class_build_skipped', [$class_name, $class_build_path]);
         return;
     }
     $result = [];
     $result[] = '<?php';
     $result[] = '';
     if ($this->getStructure()->getConfig('header_comment')) {
         $result = array_merge($result, explode("\n", $this->getStructure()->getConfig('header_comment')));
         $result[] = '';
     }
     if ($this->getStructure()->getNamespace()) {
         $result[] = 'namespace ' . $this->getStructure()->getNamespace() . ';';
         $result[] = '';
         $result[] = '/**';
         $result[] = ' * @package ' . $this->getStructure()->getNamespace();
         $result[] = ' */';
     }
     $result[] = 'class ' . $class_name . ' extends ' . $base_class_name;
     $result[] = '{';
     $result[] = '}';
     $result[] = '';
     $result = implode("\n", $result);
     if ($this->getBuildPath()) {
         file_put_contents($class_build_path, $result);
     } else {
         eval(ltrim($result, '<?php'));
     }
     $this->triggerEvent('on_class_built', [$class_name, $class_build_path]);
 }
開發者ID:activecollab,項目名稱:databasestructure,代碼行數:38,代碼來源:TypeClassBuilder.php

示例6: 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

示例7: 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

示例8: getCollectionsItemNames

 /**
  * Get a list linking an item name with the property it refers to and what kind of collection it is.
  * Ex: [
  *   "byItemName" => "user" => ["property" => "users", "behavior" => "list", "methods" => ["add", "remove"]],
  *   "byProperty" => "users" => ["itemName" => "user", "behavior" => "list", "methods" => ["add", "remove"]]
  * ]
  *
  * @param array  $properties The properties of the object to read.
  * @param \Doctrine\Common\Annotations\Reader $annotationReader The annotation reader to use.
  *
  * @return array The described list.
  */
 public static function getCollectionsItemNames($properties, $annotationReader)
 {
     $objectCollectionsItemNames = array("byProperty" => array(), "byItemName" => array());
     foreach ($properties as $propertyName => $property) {
         $annotation = null;
         $behavior = null;
         foreach (self::$collectionAnnotationClasses as $annotationBehavior => $annotationClass) {
             $annotation = $annotationReader->getPropertyAnnotation($property, $annotationClass);
             if ($annotation !== null) {
                 $behavior = $annotationBehavior;
                 break;
             }
         }
         if ($annotation !== null) {
             // get the item name, or deduce it (singularize the property name)
             $itemName = $annotation->getItemName();
             if ($itemName === null) {
                 $itemName = Inflector::singularize($propertyName);
             }
             $objectCollectionsItemNames["byItemName"][$itemName] = array("property" => $propertyName, "behavior" => $behavior, "methods" => $annotation->getMethods());
             $objectCollectionsItemNames["byProperty"][$propertyName] = array("itemName" => $itemName, "behavior" => $behavior, "methods" => $annotation->getMethods());
         }
     }
     return $objectCollectionsItemNames;
 }
開發者ID:antarestupin,項目名稱:Accessible,代碼行數:37,代碼來源:CollectionsReader.php

示例9: get

 /**
  * @param string $id
  *
  * @return InstanceResource
  */
 public function get($id)
 {
     $instanceClassName = Inflector::singularize(static::class);
     $uri = sprintf('%s/%s', $this->uri, $id);
     /** @var InstanceResource $resource */
     $resource = new $instanceClassName($this->transport, $uri);
     return $resource;
 }
開發者ID:prgtw,項目名稱:basecrm-php-api,代碼行數:13,代碼來源:ListResource.php

示例10: singularize

 /**
  * Singularifies a given value.
  *
  * @param string $value
  *
  * @return string
  */
 protected function singularize($value)
 {
     $singularified = Inflector::singularize($value);
     if (is_array($singularified)) {
         $singularified = end($singularified);
     }
     return $singularified;
 }
開發者ID:treehouselabs,項目名稱:behat-common,代碼行數:15,代碼來源:AbstractPersistenceContext.php

示例11: parseResultCollection

 /**
  * Parse a response body into a collection
  *
  * @param  string $data
  *
  * @return ResultCollection
  */
 public static function parseResultCollection($data)
 {
     $responseBody = json_decode($data, true);
     $rootKey = self::getRootKey($responseBody);
     $data = self::getResultForRootKey($responseBody, $rootKey);
     $className = Inflector::singularize(Inflector::classify($rootKey));
     $resultCollection = new ResultCollection();
     return $resultCollection->fromArrayWithObjects($data, $className);
 }
開發者ID:mailingreport,項目名稱:mailingreport-php,代碼行數:16,代碼來源:Response.php

示例12: api

 /**
  * @param string $name
  *
  * @throws InvalidArgumentException
  *
  * @return ApiInterface
  */
 public function api($name)
 {
     $name = Inflector::singularize($name);
     $apis = ['author', 'billing', 'bundle', 'category', 'expertise', 'language', 'locale', 'project', 'template', 'user'];
     if (!in_array($name, $apis, true)) {
         throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name));
     }
     $class = sprintf('Textmaster\\Api\\%s', ucfirst($name));
     return new $class($this);
 }
開發者ID:worldia,項目名稱:textmaster-api,代碼行數:17,代碼來源:Client.php

示例13: __construct

 public function __construct(FormatterManager $formatterManager, $dataProviderName, $dataSingularName = null, ProxySourceCollection $collection = null, FilterInterface $filter, MapInterface $map, ProxySourceItemFactoryInterface $factory = null)
 {
     $this->formatterManager = $formatterManager;
     $this->dataProviderName = $dataProviderName;
     $this->dataSingularName = $dataSingularName ?: Inflector::singularize($dataProviderName);
     $this->collection = $collection ?: new ProxySourceCollection();
     $this->filter = $filter ?: new NullFilter();
     $this->map = $map ?: new NullMap();
     $this->factory = $factory ?: new SimpleProxySourceItemFactory();
 }
開發者ID:sculpin,項目名稱:sculpin,代碼行數:10,代碼來源:ProxySourceCollectionDataProvider.php

示例14: buildType

 /**
  * @param TypeInterface $type
  */
 public function buildType(TypeInterface $type)
 {
     $base_manager_class_name = Inflector::classify($type->getName());
     $type_class_name = Inflector::classify(Inflector::singularize($type->getName()));
     $base_class_build_path = $this->getBuildPath() ? "{$this->getBuildPath()}/Manager/Base/{$base_manager_class_name}.php" : null;
     $result = [];
     $result[] = '<?php';
     $result[] = '';
     if ($this->getStructure()->getConfig('header_comment')) {
         $result = array_merge($result, explode("\n", $this->getStructure()->getConfig('header_comment')));
         $result[] = '';
     }
     if ($this->getStructure()->getNamespace()) {
         $base_class_namespace = $this->getStructure()->getNamespace() . '\\Manager\\Base';
         $type_class_name = '\\' . ltrim($this->getStructure()->getNamespace(), '\\') . '\\' . $type_class_name;
     } else {
         $base_class_namespace = 'Manager\\Base';
     }
     $result[] = 'namespace ' . $base_class_namespace . ';';
     $result[] = '';
     $result[] = '/**';
     $result[] = ' * @package ' . $base_class_namespace;
     $result[] = ' */';
     $interfaces = $traits = [];
     foreach ($type->getTraits() as $interface => $implementations) {
         if ($interface != '--just-paste-trait--') {
             $interfaces[] = '\\' . ltrim($interface, '\\');
         }
         if (count($implementations)) {
             foreach ($implementations as $implementation) {
                 $traits[] = '\\' . ltrim($implementation, '\\');
             }
         }
     }
     $result[] = 'abstract class ' . $base_manager_class_name . ' extends \\ActiveCollab\\DatabaseObject\\Entity\\Manager';
     $result[] = '{';
     $result[] = '    /**';
     $result[] = '     * Return type that this manager works with.';
     $result[] = '     *';
     $result[] = '     * @return string';
     $result[] = '     */';
     $result[] = '    public function getType()';
     $result[] = '    {';
     $result[] = '        return ' . var_export($type_class_name, true) . ';';
     $result[] = '    }';
     $result[] = '}';
     $result[] = '';
     $result = implode("\n", $result);
     if ($this->getBuildPath()) {
         file_put_contents($base_class_build_path, $result);
     } else {
         eval(ltrim($result, '<?php'));
     }
     $this->triggerEvent('on_class_built', [$base_manager_class_name, $base_class_build_path]);
 }
開發者ID:activecollab,項目名稱:databasestructure,代碼行數:58,代碼來源:BaseTypeManagerBuilder.php

示例15: singularize

 /**
  * Singularize the $plural word if count == 1. If $singular is passed, it 
  * will be used instead of trying to use doctrine\inflector
  *
  * @param string  $plural   - chicken
  * @param int     $count      - e.g. 4
  * @param string  $singular     - (optional) chickens
  * @return string             
  */
 public static function singularize($plural, $count = 1, $singular = null)
 {
     $count = intval($count);
     if ($count != 1) {
         return $plural;
     }
     if (null == $singular) {
         $singular = \Doctrine\Common\Inflector\Inflector::singularize($plural);
     }
     return $singular;
 }
開發者ID:davedevelopment,項目名稱:twig-inflection,代碼行數:20,代碼來源:Inflection.php


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