本文整理汇总了PHP中Doctrine\DBAL\Types\Type::getTypesMap方法的典型用法代码示例。如果您正苦于以下问题:PHP Type::getTypesMap方法的具体用法?PHP Type::getTypesMap怎么用?PHP Type::getTypesMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Types\Type
的用法示例。
在下文中一共展示了Type::getTypesMap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testItAddsTypeThatIsNotYetInStorage
public function testItAddsTypeThatIsNotYetInStorage()
{
$this->generator->shouldReceive('getTypeClassName')->with(FooBar::class)->andReturn('__Enum__\\' . FooBarType::class);
$this->storage->shouldReceive('exists')->with('__Enum__\\' . FooBarType::class)->andReturn(false);
$this->generator->shouldNotReceive('generate')->with('foobar', FooBar::class)->andReturn(new GenerationResult('__Enum__\\' . FooBarType::class, 'type_class_content'));
$this->storage->shouldReceive('save')->with('__Enum__\\' . FooBarType::class, 'type_class_content');
$this->assertFalse(Type::hasType('foobar'));
$this->sut->addType('foobar', FooBar::class);
$map = Type::getTypesMap();
$this->assertEquals('__Enum__\\' . FooBarType::class, $map['foobar']);
}
示例2: compile
public function compile()
{
$gClass = new \Psc\Code\Generate\GClass(\Psc\Code\Code::getClass($this));
$gClass->elevateClass();
$this->log('compiling ProjectEntities:');
foreach ($gClass->getMethods() as $method) {
if (\Psc\Preg::match($method->getName(), '/^compile[a-z0-9A-Z_]+$/') && $method->isPublic()) {
$this->modelCompiler = NULL;
// neuen erzeugen damit flags resetted werden, etc
$m = $method->getName();
$this->log(' ' . $m . ':');
try {
$out = $this->{$m}($this->getModelCompiler());
} catch (\Doctrine\DBAL\DBALException $e) {
if (mb_strpos($e->getMessage(), 'Unknown column type') !== FALSE) {
$types = A::implode(\Doctrine\DBAL\Types\Type::getTypesMap(), "\n", function ($fqn, $type) {
return $type . "\t\t" . ': ' . $fqn;
});
throw new \Psc\Exception('Database Error: Unknown Column Type: types are: ' . "\n" . $types, $e->getCode(), $e);
}
throw $e;
} catch (\Exception $e) {
$this->log(' Fehler beim Aufruf von ' . $m);
throw $e;
}
if ($out instanceof \Webforge\Common\System\File) {
$this->log(' ' . $out . ' geschrieben');
} elseif (is_array($out)) {
foreach ($out as $file) {
$this->log(' ' . $file . ' geschrieben');
}
} elseif ($out instanceof \Psc\Doctrine\EntityBuilder) {
$this->log(' ' . $out->getWrittenFile() . ' geschrieben');
}
}
}
$this->log('finished.');
return $this;
}
示例3: initializeCommentedDoctrineTypes
/**
* Initializes the Doctrine Type comments instance variable for in_array() checks.
*
* @return void
*/
protected function initializeCommentedDoctrineTypes()
{
$this->doctrineTypeComments = array();
foreach (Type::getTypesMap() as $typeName => $className) {
$type = Type::getType($typeName);
if ($type->requiresSQLCommentHint($this)) {
$this->doctrineTypeComments[] = $typeName;
}
}
}
示例4: function
<?php
/**
* This file is part of Mismatch.
*
* @author ♥ <hi@drwrf.com>
* @license MIT
*/
namespace Mismatch\ORM;
use Mismatch\Model\Attrs;
// Install native ORM types.
foreach (['belongs-to' => 'Mismatch\\ORM\\Attr\\BelongsTo', 'has-many' => 'Mismatch\\ORM\\Attr\\HasMany', 'has-one' => 'Mismatch\\ORM\\Attr\\HasOne'] as $name => $type) {
Attrs::registerType($name, $type);
}
// Install doctrine-specific types
use Doctrine\DBAL\Types\Type;
use Mismatch\ORM\Attr\Native;
$types = Type::getTypesMap();
foreach ($types as $type => $class) {
Attrs::registerType($type, function ($name, $opts) use($type) {
$opts['type'] = Type::getType($type);
return new Native($name, $opts);
});
}
示例5: generateEntityStubMethod
private function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null)
{
$methodName = $type . Inflector::classify($fieldName);
if (in_array($type, array("add", "remove")) && substr($methodName, -1) == "s") {
$methodName = substr($methodName, 0, -1);
}
if ($this->hasMethod($methodName, $metadata)) {
return;
}
$this->staticReflection[$metadata->name]['methods'][] = $methodName;
$var = sprintf('%sMethodTemplate', $type);
$template = self::${$var};
$methodTypeHint = null;
$types = Type::getTypesMap();
$variableType = $typeHint ? $this->getType($typeHint) . ' ' : null;
if ($typeHint && !isset($types[$typeHint])) {
$variableType = '\\' . ltrim($variableType, '\\');
$methodTypeHint = '\\' . $typeHint . ' ';
}
$replacements = array('<description>' => ucfirst($type) . ' ' . $fieldName, '<methodTypeHint>' => $methodTypeHint, '<variableType>' => $variableType, '<variableName>' => Inflector::camelize($fieldName), '<methodName>' => $methodName, '<fieldName>' => $fieldName, '<variableDefault>' => $defaultValue !== null ? ' = ' . $defaultValue : '', '<entity>' => $this->getClassName($metadata));
$method = str_replace(array_keys($replacements), array_values($replacements), $template);
return $this->prefixCodeWithSpaces($method);
}
示例6: __construct
public function __construct(\Espo\Core\Utils\File\Manager $fileManager)
{
$this->fileManager = $fileManager;
$this->typeList = array_keys(\Doctrine\DBAL\Types\Type::getTypesMap());
}
示例7: formatQuery
/**
* @param string $query
* @param array $params
* @param array $types
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
* @throws \Doctrine\DBAL\DBALException
* @throws \Nette\Utils\RegexpException
* @return string
*/
public static function formatQuery($query, $params, array $types = [], AbstractPlatform $platform = NULL)
{
if (!$platform) {
$platform = new Doctrine\DBAL\Platforms\MySqlPlatform();
}
if (!$types) {
foreach ($params as $key => $param) {
if (is_array($param)) {
$types[$key] = Doctrine\DBAL\Connection::PARAM_STR_ARRAY;
} else {
$types[$key] = 'string';
}
}
}
try {
list($query, $params, $types) = \Doctrine\DBAL\SQLParserUtils::expandListParameters($query, $params, $types);
} catch (Doctrine\DBAL\SQLParserUtilsException $e) {
}
$formattedParams = [];
foreach ($params as $key => $param) {
if (isset($types[$key])) {
if (is_scalar($types[$key]) && array_key_exists($types[$key], Type::getTypesMap())) {
$types[$key] = Type::getType($types[$key]);
}
/** @var Type[] $types */
if ($types[$key] instanceof Type) {
$param = $types[$key]->convertToDatabaseValue($param, $platform);
}
}
$formattedParams[] = SimpleParameterFormatter::format($param);
}
$params = $formattedParams;
if (Nette\Utils\Validators::isList($params)) {
$parts = explode('?', $query);
if (count($params) > $parts) {
throw new Kdyby\Doctrine\InvalidStateException("Too mny parameters passed to query.");
}
return implode('', Kdyby\Doctrine\Helpers::zipper($parts, $params));
}
return Strings::replace($query, '~(\\:[a-z][a-z0-9]*|\\?[0-9]*)~i', function ($m) use(&$params) {
if (substr($m[0], 0, 1) === '?') {
if (strlen($m[0]) > 1) {
if (isset($params[$k = substr($m[0], 1)])) {
return $params[$k];
}
} else {
return array_shift($params);
}
} else {
if (isset($params[$k = substr($m[0], 1)])) {
return $params[$k];
}
}
return $m[0];
});
}
示例8: I_can_register_all_enums_at_once
/**
* @test
*/
public function I_can_register_all_enums_at_once()
{
$registered = Type::getTypesMap();
SkillsEnumsRegistrar::registerAll();
self::assertGreaterThan(count($registered), Type::getTypesMap());
}
示例9: addFields
/**
* Interactively ask user to add field to his new Entity.
*
* @param InputInterface $input
* @param OutputInterface $output
* @param QuestionHelper $questionHelper
*
* @return $fields
*/
private function addFields(InputInterface $input, OutputInterface $output, QuestionHelper $questionHelper)
{
$fields = $this->parseFields($input->getOption('fields'));
$output->writeln(['', 'Instead of starting with a blank entity, 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));
if (count($types) != $i + 1) {
$output->write(', ');
} else {
$output->write('.');
}
}
$output->writeln('');
$fieldValidator = function ($type) use($types) {
if (!in_array($type, $types)) {
throw new \InvalidArgumentException(sprintf('Invalid type "%s".', $type));
}
return $type;
};
$lengthValidator = function ($length) {
if (!$length) {
return $length;
}
$result = filter_var($length, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
if (false === $result) {
throw new \InvalidArgumentException(sprintf('Invalid length "%s".', $length));
}
return $length;
};
while (true) {
$output->writeln('');
$generator = $this->getEntityGenerator();
$question = new Question($questionHelper->getQuestion('New field name (press <return> to stop adding fields)', null));
$question->setValidator(function ($name) use($fields, $generator) {
if (isset($fields[$name]) || 'id' == $name) {
throw new \InvalidArgumentException(sprintf('Field "%s" is already defined.', $name));
}
// check reserved words by database
if ($generator->isReservedKeyword($name)) {
throw new \InvalidArgumentException(sprintf('Name "%s" is a reserved word.', $name));
}
// check reserved words by victoire
if ($this->isReservedKeyword($name)) {
throw new \InvalidArgumentException(sprintf('Name "%s" is a Victoire reserved word.', $name));
}
return $name;
});
$columnName = $questionHelper->ask($input, $output, $question);
if (!$columnName) {
break;
}
$defaultType = 'string';
// try to guess the type by the column name prefix/suffix
if (substr($columnName, -3) == '_at') {
$defaultType = 'datetime';
} elseif (substr($columnName, -3) == '_id') {
$defaultType = 'integer';
} elseif (substr($columnName, 0, 3) == 'is_') {
$defaultType = 'boolean';
} elseif (substr($columnName, 0, 4) == 'has_') {
$defaultType = 'boolean';
}
$question = new Question($questionHelper->getQuestion('Field type', $defaultType), $defaultType);
$question->setValidator($fieldValidator);
$question->setAutocompleterValues($types);
$type = $questionHelper->ask($input, $output, $question);
$data = ['columnName' => $columnName, 'fieldName' => lcfirst(Container::camelize($columnName)), 'type' => $type];
if ($type == 'string') {
$question = new Question($questionHelper->getQuestion('Field length', 255), 255);
$question->setValidator($lengthValidator);
$data['length'] = $questionHelper->ask($input, $output, $question);
}
$fields[$columnName] = $data;
}
return $fields;
}
示例10: addFields
/**
* Add the entity fields
*
* @param InputInterface $input
* @param OutputInterface $output
* @param DialogHelper $dialog
*
* @return array
*/
private function addFields(InputInterface $input, OutputInterface $output, DialogHelper $dialog)
{
$fields = $this->parseFields($input->getOption('fields'));
$output->writeln(array('', 'Instead of starting with a blank entity, you can add some fields now.', 'Note that the primary key will be added automatically (named <comment>id</comment>) as well as the <comment>active</comment> field.', ''));
$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));
if (count($types) != $i + 1) {
$output->write(', ');
} else {
$output->write('.');
}
}
$output->writeln('');
$fieldValidator = function ($type) use($types) {
// FIXME: take into account user-defined field types
if (!in_array($type, $types)) {
throw new \InvalidArgumentException(sprintf('Invalid type "%s".', $type));
}
return $type;
};
$lengthValidator = function ($length) {
if (!$length) {
return $length;
}
$result = filter_var($length, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1)));
if (false === $result) {
throw new \InvalidArgumentException(sprintf('Invalid length "%s".', $length));
}
return $length;
};
$i18nValidator = function ($isI18n) {
if (!in_array($isI18n, array('Yes', 'No', 'yes', 'no', 'Y', 'N', 'y', 'n'))) {
throw new \InvalidArgumentException(sprintf('Invalid answer (Yes/No) "%s".', $isI18n));
}
return $isI18n;
};
$isNullableValidator = function ($isNullable) {
if (!in_array($isNullable, array('Yes', 'No', 'yes', 'no', 'Y', 'N', 'y', 'n'))) {
throw new \InvalidArgumentException(sprintf('Invalid answer (Yes/No) "%s".', $isNullable));
}
return substr(strtolower($isNullable), 0, 1) == 'y' ? true : false;
};
while (true) {
$output->writeln('');
$generator = $this->getGenerator();
$columnName = $dialog->askAndValidate($output, $dialog->getQuestion('New field name (press <return> to stop adding fields)', null), function ($name) use($fields, $generator) {
if (isset($fields[$name]) || 'id' == $name) {
throw new \InvalidArgumentException(sprintf('Field "%s" is already defined.', $name));
}
// check reserved words
if ($generator->isReservedKeyword($name)) {
throw new \InvalidArgumentException(sprintf('Name "%s" is a reserved word.', $name));
}
return $name;
});
if (!$columnName) {
break;
}
$defaultType = 'string';
// try to guess the type by the column name prefix/suffix
if (substr($columnName, -3) == '_at') {
$defaultType = 'datetime';
} elseif (substr($columnName, -3) == '_id') {
$defaultType = 'integer';
} elseif (substr($columnName, 0, 3) == 'is_') {
$defaultType = 'boolean';
} elseif (substr($columnName, 0, 4) == 'has_') {
$defaultType = 'boolean';
}
$type = $dialog->askAndValidate($output, $dialog->getQuestion('Field type', $defaultType), $fieldValidator, false, $defaultType, $types);
$data = array('columnName' => $columnName, 'fieldName' => lcfirst(Container::camelize($columnName)), 'type' => $type);
if ($type == 'string') {
$data['length'] = $dialog->askAndValidate($output, $dialog->getQuestion('Field length', 255), $lengthValidator, false, 255);
}
$data['i18n'] = $dialog->askAndValidate($output, $dialog->getQuestion('Field is i18n', 'no'), $i18nValidator, false, 'no');
if ($columnName != 'slug') {
$data['nullable'] = $dialog->askAndValidate($output, $dialog->getQuestion('Field is nullable', 'no'), $isNullableValidator, false, 'no');
}
$fields[$columnName] = $data;
}
return $fields;
}
示例11: generateEntityStubMethod
/**
* @param ClassMetadataInfo $metadata
* @param string $type
* @param string $fieldName
* @param string|null $typeHint
* @param string|null $defaultValue
*
* @return string
*/
protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null)
{
$methodName = $type . Inflector::classify($fieldName);
$variableName = Inflector::camelize($fieldName);
if (in_array($type, ["add", "remove"])) {
$methodName = Inflector::singularize($methodName);
$variableName = Inflector::singularize($variableName);
}
if ($this->hasMethod($methodName, $metadata)) {
return '';
}
$this->staticReflection[$metadata->name]['methods'][] = strtolower($methodName);
$var = sprintf('%sMethodTemplate', $type);
$template = static::${$var};
$methodTypeHint = null;
$types = Type::getTypesMap();
$variableType = $typeHint ? $this->getType($typeHint) : null;
if ($typeHint && !isset($types[$typeHint])) {
$variableType = '\\' . ltrim($variableType, '\\');
$methodTypeHint = '\\' . $typeHint . ' ';
}
$replacements = ['<description>' => ucfirst($type) . ' ' . $variableName . '.', '<methodTypeHint>' => $methodTypeHint, '<variableType>' => $variableType . (null !== $defaultValue ? '|' . $defaultValue : ''), '<variableName>' => $variableName, '<methodName>' => $methodName, '<fieldName>' => $fieldName, '<variableDefault>' => $defaultValue !== null ? ' = ' . $defaultValue : '', '<entity>' => $this->getClassName($metadata)];
$method = str_replace(array_keys($replacements), array_values($replacements), $template);
return $this->prefixCodeWithSpaces($method);
}
示例12: generateEntityStubMethod
/**
* {@inheritdoc}
*/
protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null)
{
$methodName = $type . Inflector::classify($fieldName);
if (in_array($type, array("add", "remove"))) {
$methodName = Inflector::singularize($methodName);
}
if ($this->hasMethod($methodName, $metadata)) {
return '';
}
$this->staticReflection[$metadata->name]['methods'][] = $methodName;
$var = sprintf('%sMethodTemplate', $type);
$template = self::${$var};
$methodTypeHint = null;
$types = Type::getTypesMap();
$variableType = $typeHint ? $this->getType($typeHint) . ' ' : null;
if ($typeHint && !isset($types[$typeHint])) {
$variableType = '\\' . ltrim($variableType, '\\');
$methodTypeHint = '\\' . $typeHint . ' ';
} elseif ($variableType[0] == '\\') {
$variableType = '\\' . ltrim($variableType, '\\');
$methodTypeHint = '\\' . ltrim($variableType, '\\');
}
switch (trim($variableType)) {
case 'bool':
case 'boolean':
$variableCast = '(bool) ';
break;
case 'int':
case 'integer':
$variableCast = '(int) ';
break;
case 'float':
case 'double':
$variableCast = '(float) ';
break;
case 'string':
$variableCast = '(string) ';
break;
default:
$variableCast = '';
}
$variableName = Inflector::camelize($fieldName);
if ($metadata->hasField($fieldName) && $metadata->isNullable($fieldName)) {
$nullable = true;
} else {
$nullable = false;
}
if ($nullable && $variableCast) {
$variableCast = sprintf('$%s === null ? null : %s', $variableName, $variableCast);
}
$replacements = array('<description>' => ucfirst($type) . ' ' . $fieldName, '<methodTypeHint>' => $methodTypeHint, '<variableType>' => $variableType, '<variableCast>' => $variableCast, '<variableName>' => $variableName, '<methodName>' => $methodName, '<fieldName>' => $fieldName, '<variableDefault>' => $defaultValue !== null ? ' = ' . $defaultValue : ($nullable ? ' = null' : ''), '<entity>' => $this->getClassName($metadata));
$method = str_replace(array_keys($replacements), array_values($replacements), $template);
return $this->prefixCodeWithSpaces($method);
}
示例13: mapByTypesMap
/**
* Map by Doctrine DBAL types map
* @param $types
* @param $key
* @return null|string
*/
protected function mapByTypesMap($types, $key)
{
$typesMap = Type::getTypesMap();
if (array_key_exists($key, $types) && array_key_exists($types[$key], $typesMap)) {
$name = $types[$key];
} else {
$name = null;
}
return $name;
}
示例14: _generateEntityStubMethod
private function _generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null)
{
$methodName = $type . Inflector::classify($fieldName);
if ($this->_hasMethod($methodName, $metadata)) {
return;
}
$var = sprintf('_%sMethodTemplate', $type);
$template = self::${$var};
$variableType = $typeHint ? $typeHint . ' ' : null;
$types = \Doctrine\DBAL\Types\Type::getTypesMap();
$methodTypeHint = $typeHint && !isset($types[$typeHint]) ? '\\' . $typeHint . ' ' : null;
$replacements = array('<description>' => ucfirst($type) . ' ' . $fieldName, '<methodTypeHint>' => $methodTypeHint, '<variableType>' => $variableType, '<variableName>' => Inflector::camelize($fieldName), '<methodName>' => $methodName, '<fieldName>' => $fieldName);
$method = str_replace(array_keys($replacements), array_values($replacements), $template);
return $this->_prefixCodeWithSpaces($method);
}
示例15: addFields
private function addFields(InputInterface $input, OutputInterface $output, DialogHelper $dialog)
{
$fields = $this->parseFields($input->getOption('fields'));
$output->writeln(array('', 'Instead of starting with a blank entity, 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));
if (count($types) != $i + 1) {
$output->write(', ');
} else {
$output->write('.');
}
}
$output->writeln('');
$fieldValidator = function ($type) use($types) {
// FIXME: take into account user-defined field types
if (!in_array($type, $types)) {
throw new \InvalidArgumentException(sprintf('Invalid type "%s".', $type));
}
return $type;
};
$lengthValidator = function ($length) {
if (!$length) {
return $length;
}
$result = filter_var($length, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1)));
if (false === $result) {
throw new \InvalidArgumentException(sprintf('Invalid length "%s".', $length));
}
return $length;
};
while (true) {
$output->writeln('');
$self = $this;
$name = $dialog->askAndValidate($output, $dialog->getQuestion('New field name (press <return> to stop adding fields)', null), function ($name) use($fields, $self) {
if (isset($fields[$name]) || 'id' == $name) {
throw new \InvalidArgumentException(sprintf('Field "%s" is already defined.', $name));
}
// check reserved words
if ($self->getGenerator()->isReservedKeyword($name)) {
throw new \InvalidArgumentException(sprintf('Name "%s" is a reserved word.', $name));
}
return $name;
});
if (!$name) {
break;
}
$defaultType = 'string';
if (substr($name, -3) == '_at') {
$defaultType = 'datetime';
} elseif (substr($name, -3) == '_id') {
$defaultType = 'integer';
}
$type = $dialog->askAndValidate($output, $dialog->getQuestion('Field type', $defaultType), $fieldValidator, false, $defaultType);
$data = array('fieldName' => $name, 'type' => $type);
if ($type == 'string') {
$data['length'] = $dialog->askAndValidate($output, $dialog->getQuestion('Field length', 255), $lengthValidator, false, 255);
}
$fields[$name] = $data;
}
return $fields;
}