当前位置: 首页>>代码示例>>PHP>>正文


PHP Inflector::singularize方法代码示例

本文整理汇总了PHP中Doctrine\Common\Util\Inflector::singularize方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::singularize方法的具体用法?PHP Inflector::singularize怎么用?PHP Inflector::singularize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\Common\Util\Inflector的用法示例。


在下文中一共展示了Inflector::singularize方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setRelationships

 /**
  * @param \ReflectionClass $class
  * @param ResourceEntityInterface $entity
  * @param array $relationships
  * @return self
  */
 protected function setRelationships(\ReflectionClass $class, ResourceEntityInterface $entity, array $relationships)
 {
     foreach ($relationships as $relationship => $value) {
         $camelCased = Inflector::camelize($relationship);
         if (is_array($value)) {
             $getter = DefaultMutator::GET . $camelCased;
             $singular = Inflector::singularize($camelCased);
             $remover = DefaultMutator::REMOVE . $singular;
             $adder = DefaultMutator::ADD . $singular;
             // @todo Improve algorithm.
             foreach ($entity->{$getter}() as $item) {
                 $entity->{$remover}($item);
             }
             foreach ($value as $item) {
                 $entity->{$adder}($item);
             }
         } else {
             $method = DefaultMutator::SET . $camelCased;
             if ($class->hasMethod($method)) {
                 $entity->{$method}($value);
             }
         }
     }
     return $this;
 }
开发者ID:gointegro,项目名称:hateoas,代码行数:31,代码来源:AltersEntities.php

示例2: collection

 /**
  * Serialize a collection.
  *
  * @param string $resourceKey
  * @param array  $data
  *
  * @return array
  */
 public function collection($resourceKey, array $data)
 {
     $dataResponse = [];
     $resourceKey = strtolower($resourceKey);
     $pluralize = Inflector::pluralize($resourceKey);
     $singularize = Inflector::singularize($resourceKey);
     if (!$this->scope->hasParent()) {
         $dataResponse[$pluralize] = [$singularize => $data];
     } else {
         $dataResponse = [$singularize => $data];
     }
     return $dataResponse;
 }
开发者ID:eliberty,项目名称:api-bundle,代码行数:21,代码来源:DataXmlSerializer.php

示例3: findAdderAndRemover

 /**
  * Searches for add and remove methods.
  */
 protected function findAdderAndRemover()
 {
     $reflClass = new \ReflectionClass($this->object);
     $propertyName = Inflector::classify(Inflector::singularize($this->propertyName));
     $addMethod = 'add' . $propertyName;
     $removeMethod = 'remove' . $propertyName;
     $addMethodFound = $this->isAccessible($reflClass, $addMethod, 1);
     $removeMethodFound = $this->isAccessible($reflClass, $removeMethod, 1);
     if ($addMethodFound && $removeMethodFound) {
         $this->addMethod = $addMethod;
         $this->removeMethod = $removeMethod;
     }
     if (!$addMethodFound || !$removeMethodFound) {
         throw new NoSuchPropertyException(sprintf('Not found a public methods "%s()" and/or "%s()" on class %s', $addMethod, $removeMethod, $reflClass->name));
     }
 }
开发者ID:hafeez3000,项目名称:orocommerce,代码行数:19,代码来源:CollectionAccessor.php

示例4: getQuery

 /**
  * Get relation query
  *
  * @return \Blast\Orm\Query
  */
 public function getQuery()
 {
     if (null !== $this->query) {
         return $this->query;
     }
     $provider = $this->createProvider($this->getEntity());
     $foreignProvider = $this->createProvider($this->getForeignEntity());
     $foreignKey = $this->getForeignKey();
     $junction = $this->getJunction();
     $junctionLocalKey = $this->getJunctionLocalKey();
     $junctionForeignKey = $this->getJunctionForeignKey();
     $data = $provider->extract();
     $localKey = $provider->getDefinition()->getPrimaryKeyName();
     //determine foreign key
     if ($foreignKey === null) {
         $foreignKey = $foreignProvider->getDefinition()->getPrimaryKeyName();
     }
     //determine through
     if (!is_string($junction) || $junction === null) {
         $junction = Inflector::singularize($provider->getDefinition()->getTableName()) . '_' . Inflector::singularize($foreignProvider->getDefinition()->getTableName());
     }
     //determine through local key
     if ($junctionLocalKey === null) {
         $junctionLocalKey = Inflector::singularize($provider->getDefinition()->getTableName()) . '_' . $localKey;
     }
     //determine through foreign key
     if ($junctionForeignKey === null) {
         $junctionForeignKey = Inflector::singularize($foreignProvider->getDefinition()->getTableName()) . '_' . $foreignKey;
     }
     $query = new Query($provider->getDefinition()->getMapper()->getConnection());
     //prepare query for foreign table
     $foreignQuery = $foreignProvider->getDefinition()->getMapper()->setConnection($this->getConnection())->select();
     //get relations by through db object
     if (isset($data[$localKey])) {
         $junctionProvider = is_string($junction) ? $this->createProvider($junction) : $junction;
         $junctionMapper = $junctionProvider->getDefinition()->getMapper();
         $junctionMapper->setConnection($this->getConnection());
         if (true) {
         }
         $results = $junctionMapper->select([$junctionForeignKey])->where($query->expr()->eq($junctionLocalKey, $data[$localKey]))->execute(HydratorInterface::HYDRATE_RAW);
         //set conditions on foreign query
         foreach ($results as $result) {
             $foreignQuery->where($query->expr()->eq($foreignKey, $result[$junctionForeignKey]));
         }
     }
     $this->query = $foreignQuery;
     return $this->query;
 }
开发者ID:phpthinktank,项目名称:blast-orm,代码行数:53,代码来源:ManyToMany.php

示例5: generateEntityStubMethod

 /**
  * @param ClassMetadataInfo $metadata
  * @param string            $type
  * @param string            $fieldName
  * @param string|null       $typeHint
  * @param string|null       $defaultValue
  *
  * @return string
  */
 protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null)
 {
     $methodName = $type . Inflector::classify($fieldName);
     $variableName = Inflector::camelize($fieldName);
     if (in_array($type, array("add", "remove"))) {
         $methodName = Inflector::singularize($methodName);
         $variableName = Inflector::singularize($variableName);
     }
     if ($this->hasMethod($methodName, $metadata)) {
         return '';
     }
     $this->staticReflection[$metadata->name]['methods'][] = strtolower($methodName);
     $var = sprintf('%sMethodTemplate', $type);
     $template = static::${$var};
     $methodTypeHint = null;
     $types = Type::getTypesMap();
     $variableType = $typeHint ? $this->getType($typeHint) : null;
     if ($typeHint && !isset($types[$typeHint])) {
         $variableType = '\\' . ltrim($variableType, '\\');
         $methodTypeHint = '\\' . $typeHint . ' ';
     }
     $replacements = array('<description>' => ucfirst($type) . ' ' . $variableName, '<methodTypeHint>' => $methodTypeHint, '<variableType>' => $variableType, '<variableName>' => $variableName, '<methodName>' => $methodName, '<fieldName>' => $fieldName, '<variableDefault>' => $defaultValue !== null ? ' = ' . $defaultValue : '', '<entity>' => $this->getClassName($metadata));
     $method = str_replace(array_keys($replacements), array_values($replacements), $template);
     return $this->prefixCodeWithSpaces($method);
 }
开发者ID:ismael-rivera,项目名称:project-manati,代码行数:34,代码来源:EntityGenerator.php

示例6: save

 /**
  * @param \Doctrine\ORM\Mapping\ClassMetadata $meta
  * @param \Nette\ComponentModel\Component $component
  * @param mixed $entity
  * @return boolean
  */
 public function save(ClassMetadata $meta, Component $component, $entity)
 {
     if (!$component instanceof BaseControl) {
         return false;
     }
     $name = $component->getOption(self::FIELD_NAME, $component->getName());
     $value = $component->getValue();
     if ($this->accessor->isWritable($entity, $name) && !$meta->hasAssociation($name)) {
         try {
             $this->accessor->setValue($entity, $name, $value);
             return true;
         } catch (\Kdyby\Doctrine\MemberAccessException $e) {
         }
     }
     if (!$meta->hasAssociation($name)) {
         return false;
     }
     $value = $component->getValue();
     $entityClass = $this->relatedMetadata($entity, $name)->getName();
     $repository = $this->entityManager->getRepository($entityClass);
     if ($meta->isCollectionValuedAssociation($name)) {
         $property = \Doctrine\Common\Util\Inflector::singularize($name);
         foreach ($repository->findAll() as $associatedEntity) {
             if (in_array($associatedEntity->id, $value)) {
                 $hasMethod = 'has' . ucfirst($property);
                 if (!$entity->{$hasMethod}($associatedEntity)) {
                     $addMethod = 'add' . ucfirst($property);
                     $entity->{$addMethod}($associatedEntity);
                 }
             } else {
                 $removeMethod = 'remove' . ucfirst($property);
                 $entity->{$removeMethod}($associatedEntity);
             }
         }
     } elseif ($value === null || ($value = $repository->find($value))) {
         if ($this->accessor->isWritable($entity, $name)) {
             try {
                 $this->accessor->setValue($entity, $name, $value);
             } catch (\Kdyby\Doctrine\MemberAccessException $e) {
                 return false;
             }
         }
     }
     return true;
 }
开发者ID:venne,项目名称:venne,代码行数:51,代码来源:TextControl.php

示例7: generateEntityStubMethod

 /**
  * {@inheritdoc}
  */
 protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null)
 {
     $methodName = $type . Inflector::classify($fieldName);
     if (in_array($type, array("add", "remove"))) {
         $methodName = Inflector::singularize($methodName);
     }
     if ($this->hasMethod($methodName, $metadata)) {
         return '';
     }
     $this->staticReflection[$metadata->name]['methods'][] = $methodName;
     $var = sprintf('%sMethodTemplate', $type);
     $template = self::${$var};
     $methodTypeHint = null;
     $types = Type::getTypesMap();
     $variableType = $typeHint ? $this->getType($typeHint) . ' ' : null;
     if ($typeHint && !isset($types[$typeHint])) {
         $variableType = '\\' . ltrim($variableType, '\\');
         $methodTypeHint = '\\' . $typeHint . ' ';
     } elseif ($variableType[0] == '\\') {
         $variableType = '\\' . ltrim($variableType, '\\');
         $methodTypeHint = '\\' . ltrim($variableType, '\\');
     }
     switch (trim($variableType)) {
         case 'bool':
         case 'boolean':
             $variableCast = '(bool) ';
             break;
         case 'int':
         case 'integer':
             $variableCast = '(int) ';
             break;
         case 'float':
         case 'double':
             $variableCast = '(float) ';
             break;
         case 'string':
             $variableCast = '(string) ';
             break;
         default:
             $variableCast = '';
     }
     $variableName = Inflector::camelize($fieldName);
     if ($metadata->hasField($fieldName) && $metadata->isNullable($fieldName)) {
         $nullable = true;
     } else {
         $nullable = false;
     }
     if ($nullable && $variableCast) {
         $variableCast = sprintf('$%s === null ? null : %s', $variableName, $variableCast);
     }
     $replacements = array('<description>' => ucfirst($type) . ' ' . $fieldName, '<methodTypeHint>' => $methodTypeHint, '<variableType>' => $variableType, '<variableCast>' => $variableCast, '<variableName>' => $variableName, '<methodName>' => $methodName, '<fieldName>' => $fieldName, '<variableDefault>' => $defaultValue !== null ? ' = ' . $defaultValue : ($nullable ? ' = null' : ''), '<entity>' => $this->getClassName($metadata));
     $method = str_replace(array_keys($replacements), array_values($replacements), $template);
     return $this->prefixCodeWithSpaces($method);
 }
开发者ID:bit3,项目名称:contao-doctrine-orm,代码行数:57,代码来源:EntityGenerator.php


注:本文中的Doctrine\Common\Util\Inflector::singularize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。