本文整理汇总了PHP中Doctrine\DBAL\Schema\Column::getType方法的典型用法代码示例。如果您正苦于以下问题:PHP Column::getType方法的具体用法?PHP Column::getType怎么用?PHP Column::getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Schema\Column
的用法示例。
在下文中一共展示了Column::getType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: diffColumn
public function diffColumn(Column $column1, Column $column2)
{
$changedProperties = array();
if ($column1->getType() != $column2->getType()) {
//espo: fix problem with executing query for custom types
$column1DbTypeName = method_exists($column1->getType(), 'getDbTypeName') ? $column1->getType()->getDbTypeName() : $column1->getType()->getName();
$column2DbTypeName = method_exists($column2->getType(), 'getDbTypeName') ? $column2->getType()->getDbTypeName() : $column2->getType()->getName();
if (strtolower($column1DbTypeName) != strtolower($column2DbTypeName)) {
$changedProperties[] = 'type';
}
//END: espo
}
if ($column1->getNotnull() != $column2->getNotnull()) {
$changedProperties[] = 'notnull';
}
if ($column1->getDefault() != $column2->getDefault()) {
$changedProperties[] = 'default';
}
if ($column1->getUnsigned() != $column2->getUnsigned()) {
$changedProperties[] = 'unsigned';
}
if ($column1->getType() instanceof \Doctrine\DBAL\Types\StringType) {
// check if value of length is set at all, default value assumed otherwise.
$length1 = $column1->getLength() ?: 255;
$length2 = $column2->getLength() ?: 255;
if ($length1 != $length2) {
$changedProperties[] = 'length';
}
if ($column1->getFixed() != $column2->getFixed()) {
$changedProperties[] = 'fixed';
}
}
if ($column1->getType() instanceof \Doctrine\DBAL\Types\DecimalType) {
if (($column1->getPrecision() ?: 10) != ($column2->getPrecision() ?: 10)) {
$changedProperties[] = 'precision';
}
if ($column1->getScale() != $column2->getScale()) {
$changedProperties[] = 'scale';
}
}
if ($column1->getAutoincrement() != $column2->getAutoincrement()) {
$changedProperties[] = 'autoincrement';
}
// only allow to delete comment if its set to '' not to null.
if ($column1->getComment() !== null && $column1->getComment() != $column2->getComment()) {
$changedProperties[] = 'comment';
}
$options1 = $column1->getCustomSchemaOptions();
$options2 = $column2->getCustomSchemaOptions();
$commonKeys = array_keys(array_intersect_key($options1, $options2));
foreach ($commonKeys as $key) {
if ($options1[$key] !== $options2[$key]) {
$changedProperties[] = $key;
}
}
$diffKeys = array_keys(array_diff_key($options1, $options2) + array_diff_key($options2, $options1));
$changedProperties = array_merge($changedProperties, $diffKeys);
return $changedProperties;
}
示例2: getSql
public function getSql(Column $column, $table)
{
if (!$table instanceof Table) {
$table = new Identifier($table);
}
$sql = array();
$normalized = $column->getType()->getNormalizedPostGISColumnOptions($column->getCustomSchemaOptions());
$srid = $normalized['srid'];
// PostGIS 1.5 uses -1 for undefined SRID's
if ($srid <= 0) {
$srid = -1;
}
$type = strtoupper($normalized['geometry_type']);
if ('ZM' === substr($type, -2)) {
$dimension = 4;
$type = substr($type, 0, -2);
} elseif ('M' === substr($type, -1)) {
$dimension = 3;
} elseif ('Z' === substr($type, -1)) {
$dimension = 3;
$type = substr($type, 0, -1);
} else {
$dimension = 2;
}
// Geometry columns are created by the AddGeometryColumn stored procedure
$sql[] = sprintf("SELECT AddGeometryColumn('%s', '%s', %d, '%s', %d)", $table->getName(), $column->getName(), $srid, $type, $dimension);
if ($column->getNotnull()) {
// Add a NOT NULL constraint to the field
$sql[] = sprintf('ALTER TABLE %s ALTER %s SET NOT NULL', $table->getQuotedName($this->platform), $column->getQuotedName($this->platform));
}
return $sql;
}
示例3: __construct
public function __construct(TableInformation $parent, \Doctrine\DBAL\Schema\Table $table, \Doctrine\DBAL\Schema\Column $column)
{
$this->table = $parent;
foreach ($table->getForeignKeys() as $foreign) {
if (in_array($column->getName(), $foreign->getColumns())) {
$foreign_columns = $foreign->getForeignColumns();
$this->foreignTable = $foreign->getForeignTableName();
$this->foreignColumn = reset($foreign_columns);
$this->isForeign = true;
}
}
if ($primary_key = $table->getPrimaryKey()) {
$this->isPrimary = in_array($column->getName(), $primary_key->getColumns());
}
$this->name = $column->getName();
$this->type = $column->getType()->getName();
$this->length = $column->getLength();
$this->precision = $column->getPrecision();
$this->default = $column->getDefault();
$this->isNotNull = $column->getNotnull();
$this->isUnsigned = $column->getUnsigned();
$this->isFixed = $column->getFixed();
$this->isAutoIncrement = $column->getAutoincrement();
$this->comment = $column->getComment();
if ($this->type === \Doctrine\DBAL\Types\Type::BLOB) {
$this->length = min($this->bytesFromIni('post_max_size'), $this->bytesFromIni('upload_max_filesize'));
}
}
示例4: createColumnReplacement
/**
* Creates a column replacement, which has a quoted name.
*
* @param Column $column
*
* @return Column
*/
private function createColumnReplacement(Column $column)
{
$columnConfig = $column->toArray();
$columnConfig['platformOptions'] = $column->getPlatformOptions();
$columnConfig['customSchemaOptions'] = $column->getCustomSchemaOptions();
return new Column($this->platform->quoteIdentifier($column->getName()), $column->getType(), $columnConfig);
}
示例5: getFormElement
protected function getFormElement()
{
if (!empty($this->config['form_type'])) {
if (!in_array($this->config['form_type'], $this->databaseTypeToFormType)) {
throw new FactoryException('Unknown form type ' . $this->config['form_type']);
}
$formElementType = $this->config['form_type'];
} else {
if (!array_key_exists($this->column->getType()->getName(), $this->databaseTypeToFormType)) {
throw new FactoryException('No form type found for database type ' . $this->column->getType()->getName());
}
$formElementType = $this->databaseTypeToFormType[$this->column->getType()->getName()];
}
if (isset($this->config['defaults']) && is_array($this->config['defaults'])) {
$formElementType = 'select';
}
$formElement = $this->factory->get($formElementType, []);
if (!empty($this->config['attr']) && is_array($this->config['attr'])) {
$formElement->attr($this->config['attr']);
}
if ($formElementType !== 'hidden') {
$formElement->class('form-control')->label($this->getPresentation())->placeholder($this->getPresentation());
}
if ($formElementType === 'textarea') {
$formElement->class('form-control ' . config('anavel-crud.text_editor'));
}
if ($formElementType === 'checkbox') {
$formElement->class('checkbox');
}
if (isset($this->config['defaults'])) {
if (!is_array($this->config['defaults'])) {
$formElement->val(transcrud($this->config['defaults']));
} else {
$defaults = [];
foreach ($this->config['defaults'] as $key => $default) {
$defaults[$key] = transcrud($default);
}
$formElement->options($defaults);
}
}
return $formElement;
}
示例6: getMaxlength
/**
* Metodo responsavel por recuperar o maxlength
*
* @param Column $objColumn
* @return int|null
*/
private function getMaxlength($objColumn)
{
$intMaxLength = 0;
$objType = $objColumn->getType();
if ($objType instanceof IntegerType) {
$intMaxLength = $objColumn->getPrecision();
} elseif ($objType instanceof StringType) {
$intMaxLength = $objColumn->getLength();
} elseif ($objType instanceof DateTimeType) {
$intMaxLength = 0;
} elseif ($objType instanceof FloatType) {
$intMaxLength = $objColumn->getPrecision();
}
return $intMaxLength;
}
示例7: getType
protected function getType(Column $column)
{
$type = 0;
if ($column->getLength() > 0) {
$type += $column->getLength();
}
$type = $type | SerializeTrait::getTypeByDoctrineType($column->getType());
if (!$column->getNotnull()) {
$type = $type | TableInterface::IS_NULL;
}
if ($column->getAutoincrement()) {
$type = $type | TableInterface::AUTO_INCREMENT;
}
return $type;
}
示例8: getAddColumnSQL
/**
* @param string $tableName
* @param string $columnName
* @param \Doctrine\DBAL\Schema\Column $column
* @return array
*/
protected function getAddColumnSQL($tableName, $columnName, Column $column)
{
$query = array();
$spatial = array('srid' => 4326, 'dimension' => 2, 'index' => false);
foreach ($spatial as $key => &$val) {
if ($column->hasCustomSchemaOption('spatial_' . $key)) {
$val = $column->getCustomSchemaOption('spatial_' . $key);
}
}
// Geometry columns are created by AddGeometryColumn stored procedure
$query[] = sprintf("SELECT AddGeometryColumn('%s', '%s', %d, '%s', %d)", $tableName, $columnName, $spatial['srid'], strtoupper($column->getType()->getName()), $spatial['dimension']);
if ($spatial['index']) {
// Add a spatial index to the field
$query[] = sprintf("Select CreateSpatialIndex('%s', '%s')", $tableName, $columnName);
}
return $query;
}
示例9: buildColumn
/**
* @param Column $column
* @param Collection $foreignKeyColumns
* @param Collection $foreignTables
* @param Collection $indexes
* @return ColumnInterface
*/
protected function buildColumn(Column $column, Collection $foreignKeyColumns, Collection $foreignTables, Collection $indexes)
{
$uniqued = $indexes->filter(function (Index $index) use($column) {
return $index->getColumns()[0] == $column->getName() && $index->isUnique();
})->count() > 0;
if ($column->getAutoincrement()) {
return new ColumnAutoincrement($column, null, null, $uniqued);
} else {
if ($foreignKeyColumns->has($column->getName())) {
$table = $foreignKeyColumns->get($column->getName());
return new ColumnSelect($column, $table, $foreignTables->get($table), $uniqued);
} else {
if ($column->getType()->getName() == Type::INTEGER) {
return new ColumnNumericText($column, null, null, $uniqued);
} else {
return new ColumnText($column, null, null, $uniqued);
}
}
}
}
示例10: isCarbonField
/**
* Is carbon cast field.
*
* @param Column $column
* @param bool $hasTimestamps
* @return bool
*/
protected function isCarbonField(Column $column, $hasTimestamps)
{
if (in_array($column->getType()->getName(), $this->carbon['types'])) {
$fields = array_merge([$this->deletedAtColumn], $this->carbon['fields']);
if ($hasTimestamps) {
$fields = array_merge($fields, $this->timestamps);
}
return !in_array($column->getName(), $fields);
}
return false;
}
示例11: getType
/**
* Set the type of a column.
*
* @param mixed $type
* @return $this
*/
public function getType()
{
$type = $this->column->getType();
return $type->getName();
}
示例12: getFieldTypeFor
/**
* Get the field type for a given column.
*
* @param string $name
* @param \Doctrine\DBAL\Schema\Column $column
* @param null $field Optional field value for repeaters/array based columns
*
* @return string
*/
public function getFieldTypeFor($name, $column, $field = null)
{
if ($column instanceof Column) {
if ($column->getType()) {
$type = get_class($column->getType());
}
$column = $column->getName();
}
if ($field !== null) {
if (isset($this->contenttypes[$name]) && isset($this->contenttypes[$name]['fields'][$column]['fields'][$field])) {
$type = $this->contenttypes[$name]['fields'][$column]['fields'][$field]['type'];
}
} elseif (isset($this->contenttypes[$name]) && isset($this->contenttypes[$name]['fields'][$column])) {
$type = $this->contenttypes[$name]['fields'][$column]['type'];
}
if ($column === 'slug') {
$type = 'slug';
}
if ($type === 'select' && isset($this->contenttypes[$name]['fields'][$column]['multiple']) && $this->contenttypes[$name]['fields'][$column]['multiple'] === true) {
$type = 'selectmultiple';
}
if ($type && isset($this->typemap[$type])) {
$type = $this->typemap[$type];
} else {
$type = $this->typemap['text'];
}
return $type;
}
示例13: isLikeImage
/**
* @param \Doctrine\DBAL\Schema\Column $column
* return boolean
*/
public function isLikeImage($column)
{
$type = $column->getType()->getName();
$name = $column->getName();
$result = false;
if (($name == "image" || $name == "picture") && ($type == "string" || $type == "text")) {
$result = true;
}
return $result;
}
示例14: buildFieldMapping
/**
* Build field mapping from a schema column definition
*
* @param string $tableName
* @param \Doctrine\DBAL\Schema\Column $column
*
* @return array
*/
private function buildFieldMapping($tableName, Column $column)
{
$fieldMapping = array('fieldName' => $this->getFieldNameForColumn($tableName, $column->getName(), false), 'columnName' => $column->getName(), 'type' => $column->getType()->getName(), 'nullable' => !$column->getNotNull());
// Type specific elements
switch ($fieldMapping['type']) {
case Type::TARRAY:
case Type::BLOB:
case Type::GUID:
case Type::JSON_ARRAY:
case Type::OBJECT:
case Type::SIMPLE_ARRAY:
case Type::STRING:
case Type::TEXT:
$fieldMapping['length'] = $column->getLength();
$fieldMapping['options']['fixed'] = $column->getFixed();
break;
case Type::DECIMAL:
case Type::FLOAT:
$fieldMapping['precision'] = $column->getPrecision();
$fieldMapping['scale'] = $column->getScale();
break;
case Type::INTEGER:
case Type::BIGINT:
case Type::SMALLINT:
$fieldMapping['options']['unsigned'] = $column->getUnsigned();
break;
}
// Comment
if (($comment = $column->getComment()) !== null) {
$fieldMapping['options']['comment'] = $comment;
}
// Weather
if (($default = $column->getDefault()) !== null) {
$fieldMapping['options']['default'] = $default;
}
return $fieldMapping;
}
示例15: getFieldTypeFor
/**
* Get the field type for a given column.
*
* @param string $name
* @param \Doctrine\DBAL\Schema\Column $column
*
* @return string
*/
protected function getFieldTypeFor($name, $column)
{
if (isset($this->contenttypes[$name]['fields'][$column->getName()])) {
$type = $this->contenttypes[$name]['fields'][$column->getName()]['type'];
} elseif ($column->getType()) {
$type = get_class($column->getType());
}
if ($column->getName() === 'slug') {
$type = 'slug';
}
if ($type === 'select' && isset($this->contenttypes[$name]['fields'][$column->getName()]['multiple']) && $this->contenttypes[$name]['fields'][$column->getName()]['multiple'] === true) {
$type = 'selectmultiple';
}
if (isset($this->typemap[$type])) {
$type = $this->typemap[$type];
} else {
$type = $this->typemap['text'];
}
return $type;
}