• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Inflector\Inflector类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getName

 public function getName()
 {
     $name = $this->reflection->getName();
     $inflector = new Inflector();
     $name = $inflector->tableize($name);
     return $name;
 }
开发者ID:patgod85,项目名称:phpdoc2rst,代码行数:7,代码来源:PropertyElement.php


示例2: validate

 public function validate(Request $request, array $rules)
 {
     $valid = true;
     foreach ($rules as $field => $rule) {
         if (is_null($rule) || !is_string($rule) || strlen($rule) == 0) {
             throw new ValidationException("Rule must be a string");
         }
         // get field value
         $value = $request->input($field);
         // split validation rule into required / sometimes (no validation if not set or empty)
         // contract and contract parameters
         $parts = explode("|", $rule);
         if (is_null($parts) || !is_array($parts) || count($parts) < 3) {
             throw new ValidationException("Invalid rule");
         }
         $required = strtolower($parts[0]) == "required" ? true : false;
         if ($required && is_null($value)) {
             $valid = false;
             continue;
         }
         $args = explode(":", $parts[1]);
         $clazz = Inflector::classify($args[0]) . "Contract";
         if (!class_exists($clazz)) {
             throw new ValidationException("Invalid rule: invalid validation class '{$clazz}'");
         }
         $instance = new $clazz($value, isset($args[1]) ? $args[1] : array());
         if (!$instance instanceof Contract) {
             throw new ValidationException("Invalid rule: invalid validation class '{$clazz}'. Class must extend Simplified\\Validator\\Contract");
         }
         if (!$instance->isValid()) {
             $valid = false;
         }
     }
     return $valid;
 }
开发者ID:simplified-framework,项目名称:validator,代码行数:35,代码来源:Validator.php


示例3: prePersist

 /**
  * @param LifecycleEventArgs $event
  */
 public function prePersist(LifecycleEventArgs $event)
 {
     $document = $event->getDocument();
     $className = get_class($document);
     $generateAnnotations = $this->annotationReader->getClassAnnotation(new \ReflectionClass($className), 'OpenOrchestra\\Mapping\\Annotations\\Document');
     if (!is_null($generateAnnotations)) {
         $repository = $this->container->get($generateAnnotations->getServiceName());
         $getSource = $generateAnnotations->getSource($document);
         $getGenerated = $generateAnnotations->getGenerated($document);
         $setGenerated = $generateAnnotations->setGenerated($document);
         $testMethod = $generateAnnotations->getTestMethod();
         if ($testMethod === null && $repository instanceof FieldAutoGenerableRepositoryInterface) {
             $testMethod = 'testUniquenessInContext';
         }
         if (is_null($document->{$getGenerated}())) {
             $source = $document->{$getSource}();
             $source = Inflector::tableize($source);
             $sourceField = $this->suppressSpecialCharacterHelper->transform($source);
             $generatedField = $sourceField;
             $count = 1;
             while ($repository->{$testMethod}($generatedField)) {
                 $generatedField = $sourceField . '-' . $count;
                 $count++;
             }
             $document->{$setGenerated}($generatedField);
         }
     }
 }
开发者ID:open-orchestra,项目名称:open-orchestra-model-bundle,代码行数:31,代码来源:GenerateIdListener.php


示例4: getDirection

 /**
  * {@inheritdoc}
  */
 public function getDirection($activity, $target)
 {
     //check if target is entity created from admin part
     if (!$target instanceof EmailHolderInterface) {
         $metadata = $this->doctrineHelper->getEntityMetadata($target);
         $columns = $metadata->getColumnNames();
         $className = get_class($target);
         foreach ($columns as $column) {
             //check only columns with 'contact_information'
             if ($this->isEmailType($className, $column)) {
                 $getMethodName = "get" . Inflector::classify($column);
                 /** @var $activity Email */
                 if ($activity->getFromEmailAddress()->getEmail() === $target->{$getMethodName}()) {
                     return DirectionProviderInterface::DIRECTION_OUTGOING;
                 } else {
                     foreach ($activity->getTo() as $recipient) {
                         if ($recipient->getEmailAddress()->getEmail() === $target->{$getMethodName}()) {
                             return DirectionProviderInterface::DIRECTION_INCOMING;
                         }
                     }
                 }
             }
         }
         return DirectionProviderInterface::DIRECTION_UNKNOWN;
     }
     /** @var $activity Email */
     /** @var $target EmailHolderInterface */
     if ($activity->getFromEmailAddress()->getEmail() === $target->getEmail()) {
         return DirectionProviderInterface::DIRECTION_OUTGOING;
     }
     return DirectionProviderInterface::DIRECTION_INCOMING;
 }
开发者ID:antrampa,项目名称:crm,代码行数:35,代码来源:EmailDirectionProvider.php


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


示例6: toIdentifier

 private function toIdentifier($object)
 {
     $className = get_class($object);
     $className = substr($className, strrpos($className, '\\') + 1);
     $className = str_replace('SystemInfo', '', $className);
     return Inflector::tableize($className);
 }
开发者ID:ezsystems,项目名称:ez-support-tools,代码行数:7,代码来源:Identifier.php


示例7: postPersist

 public function postPersist(LifecycleEventArgs $event)
 {
     /** @var OroEntityManager $em */
     $em = $event->getEntityManager();
     $entity = $event->getEntity();
     $configProvider = $em->getExtendManager()->getConfigProvider();
     $className = get_class($entity);
     if ($configProvider->hasConfig($className)) {
         $config = $configProvider->getConfig($className);
         $schema = $config->get('schema');
         if (isset($schema['relation'])) {
             foreach ($schema['relation'] as $fieldName) {
                 /** @var Config $fieldConfig */
                 $fieldConfig = $configProvider->getConfig($className, $fieldName);
                 if ($fieldConfig->getId()->getFieldType() == 'optionSet' && ($setData = $entity->{Inflector::camelize('get_' . $fieldName)}())) {
                     $model = $configProvider->getConfigManager()->getConfigFieldModel($fieldConfig->getId()->getClassName(), $fieldConfig->getId()->getFieldName());
                     /**
                      * in case of single select field type, should wrap value in array
                      */
                     if ($setData && !is_array($setData)) {
                         $setData = [$setData];
                     }
                     foreach ($setData as $option) {
                         $optionSetRelation = new OptionSetRelation();
                         $optionSetRelation->setData(null, $entity->getId(), $model, $em->getRepository(OptionSet::ENTITY_NAME)->find($option));
                         $em->persist($optionSetRelation);
                         $this->needFlush = true;
                     }
                 }
             }
         }
     }
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:33,代码来源:OptionSetListener.php


示例8: theFollowingEntitiesExist

 /**
  * @Given the following :entityName entities exist:
  */
 public function theFollowingEntitiesExist($entityName, TableNode $table)
 {
     /** @var EntityManager $doctrine */
     $doctrine = $this->get('doctrine')->getManager();
     $meta = $doctrine->getClassMetadata($entityName);
     $rows = [];
     $hash = $table->getHash();
     foreach ($hash as $row) {
         $id = $row['id'];
         unset($row['id']);
         foreach ($row as $property => &$value) {
             $propertyName = Inflector::camelize($property);
             $fieldType = $meta->getTypeOfField($propertyName);
             switch ($fieldType) {
                 case 'array':
                 case 'json_array':
                     $value = json_decode($value, true);
                     break;
                 case 'datetime':
                     $value = new \DateTime($value);
                     break;
             }
         }
         $rows[$id] = $row;
     }
     $this->persistEntities($entityName, $rows);
 }
开发者ID:treehouselabs,项目名称:base-api-bundle,代码行数:30,代码来源:FixtureContext.php


示例9: getParametersFromObject

 /**
  * @param $keys
  * @param $object
  * @return array
  */
 protected function getParametersFromObject($keys, $object)
 {
     $parameters = [];
     foreach ($keys as $key) {
         $relation = $object;
         $method = 'get' . Inflector::classify($key);
         if (method_exists($relation, $method)) {
             $relation = $relation->{$method}();
         } else {
             $segments = explode('_', $key);
             if (count($segments) > 1) {
                 foreach ($segments as $segment) {
                     $method = 'get' . Inflector::classify($segment);
                     if (method_exists($relation, $method)) {
                         $relation = $relation->{$method}();
                     } else {
                         $relation = $object;
                         break;
                     }
                 }
             }
         }
         if ($object !== $relation) {
             $parameters[$key] = $relation;
         }
     }
     return $parameters;
 }
开发者ID:piotrminkina,项目名称:routing-bundle,代码行数:33,代码来源:UrlGenerator.php


示例10: fromArray

 /**
  * @param array $data
  */
 public function fromArray(array $data)
 {
     foreach ($data as $key => $value) {
         $property = Inflector::camelize($key);
         $this->{$property} = $value;
     }
 }
开发者ID:pablorsk,项目名称:packagist-api,代码行数:10,代码来源:AbstractResult.php


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


示例12: reverseTransform

 /**
  * @param Request $request
  * @param string $id
  * @param string $type
  * @param string $event
  * @param string $eventClass
  *
  * @return Response
  */
 protected function reverseTransform(Request $request, $id, $type, $event, $eventClass)
 {
     $facadeName = Inflector::classify($type) . 'Facade';
     $typeName = Inflector::tableize($type);
     $format = $request->get('_format', 'json');
     $facade = $this->get('jms_serializer')->deserialize($request->getContent(), 'OpenOrchestra\\ApiBundle\\Facade\\' . $facadeName, $format);
     $mixed = $this->get('open_orchestra_model.repository.' . $typeName)->find($id);
     $oldStatus = null;
     if ($mixed instanceof StatusableInterface) {
         $oldStatus = $mixed->getStatus();
     }
     $mixed = $this->get('open_orchestra_api.transformer_manager')->get($typeName)->reverseTransform($facade, $mixed);
     if ($this->isValid($mixed)) {
         $em = $this->get('object_manager');
         $em->persist($mixed);
         $em->flush();
         if (in_array('OpenOrchestra\\ModelInterface\\Event\\EventTrait\\EventStatusableInterface', class_implements($eventClass))) {
             $this->dispatchEvent($event, new $eventClass($mixed, $oldStatus));
             return array();
         }
         $this->dispatchEvent($event, new $eventClass($mixed));
         return array();
     }
     return $this->getViolations();
 }
开发者ID:open-orchestra,项目名称:open-orchestra-base-api-bundle,代码行数:34,代码来源:BaseController.php


示例13: invoke

 /**
  * @param FactoryArguments $arguments
  * @param $method
  * @param array $parameters
  * @return mixed
  * @throws \LukaszMordawski\CampaignMonitorBundle\Exception\Exception
  * @throws \LogicException
  *
  * This method invokes proper API method and stores result in cache.
  */
 public function invoke(FactoryArguments $arguments, $method, $parameters = [])
 {
     if (!$arguments->clientId) {
         $arguments->clientId = $this->clientId;
     }
     $method = Inflector::tableize($method);
     $cacheKey = $this->getCacheKey($arguments, $method, $parameters);
     if ($this->cache->contains($cacheKey)) {
         return unserialize($this->cache->fetch($cacheKey));
     }
     $csClient = $this->factory->factory($arguments);
     if (method_exists($csClient, $method)) {
         if (is_array($parameters)) {
             $data = call_user_func_array([$csClient, $method], $parameters);
         } else {
             $data = call_user_func([$csClient, $method], $parameters);
         }
     } else {
         throw new \LogicException(sprintf('Method %s does not exist for class %s', $method, get_class($csClient)));
     }
     if ($data->http_status_code != 200 && $data->http_status_code != 201) {
         throw new Exception($data->response->Message, $data->response->Code);
     }
     $this->cache->save($cacheKey, serialize($data->response), $this->cacheLifetime);
     return $data->response;
 }
开发者ID:nibynool,项目名称:CampaignMonitorBundle,代码行数:36,代码来源:Invoker.php


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


示例15: process

 /**
  * {@inheritDoc}
  */
 public function process(ContainerBuilder $container)
 {
     if (!$container->hasDefinition(self::SERVICE_KEY)) {
         return;
     }
     // find providers
     $providers = [];
     $taggedServices = $container->findTaggedServiceIds(self::TAG);
     foreach ($taggedServices as $id => $attributes) {
         if (empty($attributes[0]['scope'])) {
             throw new InvalidConfigurationException(sprintf('Tag attribute "scope" is required for "%s" service', $id));
         }
         $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
         $scope = $attributes[0]['scope'];
         $providers[$scope][$priority][] = new Reference($id);
     }
     if (empty($providers)) {
         return;
     }
     // add to chain
     $serviceDef = $container->getDefinition(self::SERVICE_KEY);
     foreach ($providers as $scope => $items) {
         // sort by priority and flatten
         krsort($items);
         $items = call_user_func_array('array_merge', $items);
         // register
         foreach ($items as $provider) {
             $serviceDef->addMethodCall(sprintf('add%sVariablesProvider', Inflector::classify($scope)), [$provider]);
         }
     }
 }
开发者ID:ramunasd,项目名称:platform,代码行数:34,代码来源:EmailTemplateVariablesPass.php


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


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


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


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


示例20: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('added', 'oro_entity_identifier', array('class' => $options['class'], 'multiple' => true))->add('removed', 'oro_entity_identifier', array('class' => $options['class'], 'multiple' => true));
     if ($options['extend']) {
         $em = $this->entityManager;
         $class = $options['class'];
         $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use($em, $class) {
             $data = $event->getData();
             $repository = $em->getRepository($class);
             $targetData = $event->getForm()->getParent()->getData();
             $fieldName = $event->getForm()->getName();
             foreach (explode(',', $data['added']) as $id) {
                 $entity = $repository->find($id);
                 if ($entity) {
                     $targetData->{Inflector::camelize('add_' . $fieldName)}($entity);
                 }
             }
             foreach (explode(',', $data['removed']) as $id) {
                 $entity = $repository->find($id);
                 if ($entity) {
                     $targetData->{Inflector::camelize('remove_' . $fieldName)}($entity);
                 }
             }
         });
     }
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:29,代码来源:MultipleEntityType.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Persistence\ManagerRegistry类代码示例发布时间:2022-05-23
下一篇:
PHP Executor\ORMExecutor类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap