當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。