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


PHP Type::getTypesMap方法代码示例

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


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

示例1: generateDocumentStubMethod

 private function generateDocumentStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null)
 {
     // Add/remove methods should use the singular form of the field name
     $formattedFieldName = in_array($type, array('add', 'remove')) ? Inflector::singularize($fieldName) : $fieldName;
     $methodName = $type . Inflector::classify($formattedFieldName);
     $variableName = Inflector::camelize($formattedFieldName);
     if ($this->hasMethod($methodName, $metadata)) {
         return;
     }
     $description = ucfirst($type) . ' ' . $variableName;
     $types = Type::getTypesMap();
     $methodTypeHint = $typeHint && !isset($types[$typeHint]) ? '\\' . $typeHint . ' ' : null;
     $variableType = $typeHint ? $typeHint . ' ' : null;
     $replacements = array('<description>' => $description, '<methodTypeHint>' => $methodTypeHint, '<variableType>' => $variableType, '<variableName>' => $variableName, '<methodName>' => $methodName, '<fieldName>' => $fieldName, '<variableDefault>' => $defaultValue !== null ? ' = ' . $defaultValue : '');
     $templateVar = sprintf('%sMethodTemplate', $type);
     $method = str_replace(array_keys($replacements), array_values($replacements), self::${$templateVar});
     return $this->prefixCodeWithSpaces($method);
 }
开发者ID:Wizkunde,项目名称:mongodb-odm,代码行数:18,代码来源:DocumentGenerator.php

示例2: addFields

 /**
  * @param \Symfony\Component\Console\Input\InputInterface              $input
  * @param \Symfony\Component\Console\Output\OutputInterface            $output
  * @param \Sensio\Bundle\GeneratorBundle\Command\Helper\QuestionHelper $dialog
  *
  * @return array
  * @throws \InvalidArgumentException
  */
 private function addFields(InputInterface $input, OutputInterface $output, QuestionHelper $dialog)
 {
     $fields = $this->parseFields($input->getOption('fields'));
     $output->writeln(array('', 'Instead of starting with a blank document, you can add some fields now.', 'Note that the primary key will be added automatically (named <comment>id</comment>).', ''));
     $output->write('<info>Available types:</info> ');
     $types = array_keys(Type::getTypesMap());
     $count = 20;
     foreach ($types as $i => $type) {
         if ($count > 50) {
             $count = 0;
             $output->writeln('');
         }
         $count += strlen($type);
         $output->write(sprintf('<comment>%s</comment>', $type));
         $output->write(count($types) != $i + 1 ? ', ' : '.');
     }
     $output->writeln('');
     $fieldValidator = function ($type) use($types) {
         if (!in_array($type, $types)) {
             throw new \InvalidArgumentException(sprintf('Invalid type "%s".', $type));
         }
         return $type;
     };
     while (true) {
         $output->writeln('');
         if (!($name = $this->askForFieldName($input, $output, $dialog, $fields))) {
             break;
         }
         $defaultType = 'string';
         if (substr($name, -3) == '_at') {
             $defaultType = 'timestamp';
         }
         $question = new Question($dialog->getQuestion('Field type', $defaultType), $defaultType);
         $question->setValidator($fieldValidator);
         $type = $dialog->ask($input, $output, $question);
         $fields[$name] = array('fieldName' => $name, 'type' => $type);
     }
     return $fields;
 }
开发者ID:anhpha,项目名称:reports,代码行数:47,代码来源:GenerateDoctrineDocumentCommand.php


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