本文整理汇总了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);
}
示例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;
}