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


PHP Inflector::camelize方法代码示例

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


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

 /**
  * @inheritdoc
  */
 public static function camelize($word)
 {
     if (!isset(static::$cache['camelize'][$word])) {
         static::$cache['camelize'][$word] = parent::camelize($word);
     }
     return static::$cache['camelize'][$word];
 }
开发者ID:doctrine,项目名称:orientdb-odm,代码行数:10,代码来源:Cached.php

示例3: createObject

 /**
  * Creates and returns one object based on the given data and metadata
  *
  * @param $class object's class name
  * @param $data array of the object's fixture data
  * @param $metadata the class metadata for doctrine
  * @param $embedded true for embedded documents
  * @return Object
  */
 public function createObject($class, $data, $metadata, $options = array())
 {
     // options to state if a document is to be embedded or persisted on its own
     $embedded = isset($options['embedded']);
     $mapping = array_keys($metadata->fieldMappings);
     // Instantiate new object
     $object = new $class();
     foreach ($data as $field => $value) {
         // Add the fields defined in the fixtures file
         $method = Inflector::camelize('set_' . $field);
         // This is a standard field
         if (in_array($field, $mapping)) {
             // Dates need to be converted to DateTime objects
             $type = $metadata->fieldMappings[$field]['type'];
             if ($type == 'many') {
                 $method = Inflector::camelize('add_' . $field);
                 // EmbedMany
                 if (isset($metadata->fieldMappings[$field]['embedded']) && $metadata->fieldMappings[$field]['embedded']) {
                     foreach ($value as $embedded_value) {
                         $embed_class = $metadata->fieldMappings[$field]['targetDocument'];
                         $embed_data = $embedded_value;
                         $embed_meta = $this->getMetaDataForClass($embed_class);
                         $value = $this->createObject($embed_class, $embed_data, $embed_meta, array('embedded' => true));
                         $object->{$method}($value);
                     }
                     //ReferenceMany
                 } else {
                     foreach ($value as $reference_object) {
                         $object->{$method}($this->loader->getReference($reference_object));
                     }
                 }
             } else {
                 if ($type == 'datetime' || $type == 'date' || $type == 'time') {
                     $value = new \DateTime($value);
                 }
                 if ($type == 'one') {
                     // EmbedOne
                     if (isset($metadata->fieldMappings[$field]['embedded']) && $metadata->fieldMappings[$field]['embedded']) {
                         $embed_class = $metadata->fieldMappings[$field]['targetDocument'];
                         $embed_data = $value;
                         $embed_meta = $this->getMetaDataForClass($embed_class);
                         $value = $this->createObject($embed_class, $embed_data, $embed_meta, array('embedded' => true));
                         // ReferenceOne
                     } else {
                         $value = $this->loader->getReference($value);
                     }
                 }
                 $object->{$method}($value);
             }
         } else {
             // The key is not a field's name but the name of a method to be called
             $object->{$method}($value);
         }
     }
     // Save a reference to the current object
     if (!$embedded) {
         $this->runServiceCalls($object);
     }
     return $object;
 }
开发者ID:Eskro,项目名称:KhepinYamlFixturesBundle,代码行数:69,代码来源:MongoYamlFixture.php

示例4: load

 public function load(ObjectManager $manager)
 {
     $yaml = new Parser();
     // TODO: find a way of obtainin Bundle's path with the help of $this->container
     $bpath = $this->container->get('kernel')->getBundle('SiwappEstimateBundle')->getPath();
     $value = $yaml->parse(file_get_contents($bpath . '/DataFixtures/estimates.yml'));
     foreach ($value['Item'] as $ref => $values) {
         $item = new Item();
         $estimate = new Estimate();
         foreach ($values as $fname => $fvalue) {
             if ($fname == 'Estimate') {
                 $fvalue = $manager->merge($this->getReference($fvalue));
                 $fvalue->addItem($item);
                 $manager->persist($fvalue);
             }
             $method = 'set' . Inflector::camelize($fname);
             if (is_callable(array($item, $method))) {
                 call_user_func(array($item, $method), $fvalue);
             }
         }
         $manager->persist($item);
         $manager->flush();
         $this->addReference($ref, $item);
     }
     foreach ($value['ItemTax'] as $ref => $values) {
         $item = $this->getReference($values['Item']);
         $tax = $this->getReference($values['Tax']);
         $item->addTax($tax);
         $manager->persist($item);
         $manager->flush();
     }
 }
开发者ID:siwapp,项目名称:siwapp-sf3,代码行数:32,代码来源:LoadItemData.php

示例5: executeHookHandler

 /**
  * Execute certain hook handler
  *
  * @return void
  */
 public function executeHookHandler()
 {
     // It's the metadata collected by Doctrine
     foreach ($this->getMetadata() as $main) {
         $node = static::getClassesTree()->find($main->name);
         // Process only certain classes
         if (!$node->isTopLevelNode() && !$node->isDecorator()) {
             foreach ($main->fieldMappings as $field => $info) {
                 if ('money' == $info['type']) {
                     $fieldName = \Includes\Utils\Converter::convertToCamelCase($field);
                     $purposes = array('net' => '');
                     $behaviors = array();
                     if (isset($info['options']) && is_array($info['options'])) {
                         foreach ($info['options'] as $option) {
                             if ($option instanceof \XLite\Core\Doctrine\Annotation\Behavior) {
                                 $behaviors = array_merge($behaviors, $option->list);
                             } elseif ($option instanceof \XLite\Core\Doctrine\Annotation\Purpose) {
                                 $purposes[$option->name] = $option->source;
                             }
                         }
                     }
                     foreach ($purposes as $purpose => $source) {
                         $camelField = ucfirst(\Doctrine\Common\Util\Inflector::camelize($field));
                         $source = $source ? ucfirst($source) . $camelField : $camelField;
                         $this->addReplacement($main, 'get', array('<getter>' => 'get' . $source, '<fieldName>' => $fieldName, '<methodName>' => ucfirst($purpose) . $camelField, '<behaviors>' => $behaviors ? '\'' . implode('\',\'', $behaviors) . '\'' : '', '<purpose>' => $purpose));
                     }
                 }
             }
         }
     }
     // Populate changes
     $this->writeData();
 }
开发者ID:kirkbauer2,项目名称:kirkxc,代码行数:38,代码来源:Main.php

示例6: load

 public function load(ObjectManager $manager)
 {
     $yaml = new Parser();
     $bpath = $this->container->get('kernel')->getBundle('SiwappRecurringInvoiceBundle')->getPath();
     $value = $yaml->parse(file_get_contents($bpath . '/DataFixtures/recurring_invoices.yml'));
     foreach ($value['Item'] as $ref => $values) {
         $item = new Item();
         $recurring_invoice = new RecurringInvoice();
         foreach ($values as $fname => $fvalue) {
             if ($fname == 'RecurringInvoice') {
                 $fvalue = $manager->merge($this->getReference($fvalue));
             }
             $method = 'set' . Inflector::camelize($fname);
             if (is_callable(array($item, $method))) {
                 call_user_func(array($item, $method), $fvalue);
             }
         }
         $manager->persist($item);
         $manager->flush();
         $this->addReference($ref, $item);
     }
     foreach ($value['ItemTax'] as $ref => $values) {
         $item = $this->getReference($values['Item']);
         $tax = $this->getReference($values['Tax']);
         $item->addTax($tax);
         $manager->persist($item);
         $manager->flush();
     }
 }
开发者ID:rvdavid,项目名称:siwapp-sf2,代码行数:29,代码来源:LoadItemData.php

示例7: transformName

 /**
  * {@inheritdoc}
  */
 public function transformName($name)
 {
     if ($this->ucFirst) {
         return Inflector::classify($name);
     } else {
         return Inflector::camelize($name);
     }
 }
开发者ID:rafrsr,项目名称:lib-array2object,代码行数:11,代码来源:CamelCaseNamingStrategy.php

示例8: load

 public function load(ObjectManager $manager, $tags = null)
 {
     if (!$this->hasTag($tags)) {
         return;
     }
     $cmf = $manager->getMetadataFactory();
     // The model class for all fixtures defined in this file
     $class = $this->file['model'];
     // Get the fields that are not "associations"
     $metadata = $cmf->getMetaDataFor($class);
     $mapping = array_keys($metadata->fieldMappings);
     $associations = array_keys($metadata->associationMappings);
     foreach ($this->file['fixtures'] as $reference => $fixture) {
         // Instantiate new object
         $object = new $class();
         foreach ($fixture as $field => $value) {
             // Add the fields defined in the fistures file
             $method = Inflector::camelize('set_' . $field);
             //
             if (strpos($value, '$') === 0) {
                 // custom reference loader format: $<referencedEntityKey>|<referencedColumn>
                 // ex: $first_campaign|idcampaign
                 list($referencedEntity, $referenceColumn) = explode('|', ltrim($value, '$'));
                 $getterMethod = Inflector::camelize('get_' . $referenceColumn);
                 $object->{$method}($this->loader->getReference($referencedEntity)->{$getterMethod}());
             } elseif (in_array($field, $mapping)) {
                 // Dates need to be converted to DateTime objects
                 $type = $metadata->fieldMappings[$field]['type'];
                 if ($type == 'datetime' or $type == 'date') {
                     $value = new \DateTime($value);
                 }
                 $object->{$method}($value);
             } else {
                 if (in_array($field, $associations)) {
                     // This field is an association, we load it from the references
                     $object->{$method}($this->loader->getReference($value));
                 } else {
                     // It's a method call that will set a field named differently
                     // eg: FOSUserBundle ->setPlainPassword sets the password after
                     // Encrypting it
                     $object->{$method}($value);
                 }
             }
         }
         // Save a reference to the current object
         $this->loader->setReference($reference, $object);
         if (!$this->isReverseSaveOrder()) {
             $manager->persist($object);
         }
     }
     if ($this->isReverseSaveOrder()) {
         $refs = array_keys($this->file['fixtures']);
         for ($i = count($refs) - 1; $i >= 0; $i--) {
             $manager->persist($this->loader->getReference($refs[$i]));
         }
     }
     $manager->flush();
 }
开发者ID:rombob,项目名称:KhepinYamlFixturesBundle,代码行数:58,代码来源:YamlFixture.php

示例9: setData

 /**
  * @param $data
  */
 public function setData($data)
 {
     foreach ($data as $field => $value) {
         //Ex: user_id => user id => userId => UserId => setUserId
         $setter_method_name = Inflector::camelize(str_replace('_', ' ', $field));
         $setter_method_name = ucfirst($setter_method_name);
         $setter_method_name = 'set' . $setter_method_name;
         $this->{$setter_method_name}($value);
     }
     return $data;
 }
开发者ID:BDNelson123,项目名称:acaAdvanced,代码行数:14,代码来源:ACABaseEntity.php

示例10: toArray

 /**
  * convert to array from object.
  *
  * @return array
  */
 public function toArray() : array
 {
     $result = [];
     foreach ($this->getObjectVars() as $property) {
         $method = Inflector::camelize('get_' . $property);
         if (method_exists($this, $method)) {
             $result[$property] = $this->{$method}();
         }
     }
     return $result;
 }
开发者ID:inaka-phper,项目名称:lunchlog,代码行数:16,代码来源:EntityBase.php

示例11: testTimestamps

 public function testTimestamps()
 {
     $entity = new Document();
     foreach (['created', 'updated'] as $field) {
         $setter = sprintf('set%s', ucfirst(Inflector::camelize($field)));
         $getter = sprintf('get%s', ucfirst(Inflector::camelize($field)));
         $this->assertNull($entity->{$getter}());
         $fluent = $entity->{$setter}(new \DateTime());
         $this->assertEquals($entity, $fluent, 'Fluent interface is not working');
         $this->assertNotNull($entity->{$getter}());
     }
 }
开发者ID:wurstpress,项目名称:core-bundle,代码行数:12,代码来源:DocumentTest.php

示例12: transform

 /**
  * @param $rawCart
  * @return Cart
  * @throws ApiTransformationException
  */
 public function transform($rawCart)
 {
     $cart = new Cart();
     foreach (json_decode($rawCart) as $key => $value) {
         $setter = 'set' . ucfirst(Inflector::camelize($key));
         if (!method_exists($cart, $setter)) {
             throw new ApiTransformationException();
         }
         $cart->{$setter}($value);
     }
     return $cart;
 }
开发者ID:holgergr,项目名称:api,代码行数:17,代码来源:CartTransformer.php

示例13: call

 /**
  * Calls methods from the specified object in underscore case.
  *
  * @param  object      $object
  * @param  string      $method
  * @param  mixed       $parameters
  * @param  object|null $anotherObject
  * @return mixed
  */
 public static function call($object, $method, $parameters, $anotherObject = null)
 {
     $method = \Doctrine\Common\Util\Inflector::camelize($method);
     $result = $object;
     if (is_null($anotherObject)) {
         $anotherObject = $object;
     }
     if (method_exists($anotherObject, $method)) {
         $result = call_user_func_array([$anotherObject, $method], $parameters);
     }
     return $result;
 }
开发者ID:rougin,项目名称:credo,代码行数:21,代码来源:MagicMethodHelper.php

示例14: generatePageUrl

 /**
  * Generate page url from name and parameters.
  *
  * @param string $page
  * @param array  $parameters
  *
  * @return string
  */
 private function generatePageUrl($page, array $parameters = array())
 {
     $parts = explode(' ', trim($page), 2);
     if (2 === count($parts)) {
         $parts[1] = Inflector::camelize($parts[1]);
     }
     $route = implode('_', $parts);
     $routes = $this->getContainer()->get('router')->getRouteCollection();
     if (null === $routes->get($route)) {
         $route = 'app_' . $route;
     }
     return $this->getMinkParameter('base_url') . $this->generateUrl($route, $parameters);
 }
开发者ID:next-sentence,项目名称:sylius-test,代码行数:21,代码来源:FeatureContext.php

示例15: createStep

 /**
  * @param string $title
  * @param string $class
  * @param array  $services
  * @param array  $parameters
  *
  * @return ItemStep
  */
 public function createStep($title, $class, array $services, array $parameters)
 {
     $step = new $class($title);
     $step->setEventDispatcher($this->eventDispatcher);
     $step->setJobRepository($this->jobRepository);
     foreach ($services as $setter => $service) {
         $method = 'set' . Inflector::camelize($setter);
         $step->{$method}($service);
     }
     foreach ($parameters as $setter => $param) {
         $method = 'set' . Inflector::camelize($setter);
         $step->{$method}($param);
     }
     return $step;
 }
开发者ID:xleliberty,项目名称:BatchBundle,代码行数:23,代码来源:StepFactory.php


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