本文整理汇总了PHP中Doctrine\DBAL\Schema\Column类的典型用法代码示例。如果您正苦于以下问题:PHP Column类的具体用法?PHP Column怎么用?PHP Column使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Column类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mapForeignKeys
public function mapForeignKeys($table, Column $column, $id = null)
{
try {
$relatedRows = $this->db->executeQuery("SELECT * FROM {$table} ORDER BY id ASC")->fetchAll();
if (isset($relatedRows[0]['name'])) {
$foreign = 'name';
} else {
$comments = json_decode($column->getComment(), true);
if (!empty($comments) && is_array($comments)) {
$foreign = $foreign['foreign'];
} else {
$foreign = 'id';
}
}
$choices = array();
foreach ($relatedRows as $relatedRow) {
if (null !== $id && $relatedRow['id'] == $id) {
return $relatedRow[$foreign];
}
$choices[$relatedRow['id']] = $relatedRow[$foreign];
}
return $choices;
} catch (\Exception $e) {
return false;
}
}
示例2: checkColumn
/**
* Do checks for columns.
*
* @param Column $column
* @param array $alterData
*
* @return boolean
*/
protected function checkColumn(Column $column, array $alterData)
{
// Not needed to be implemented yet
if ($alterData['propertyName'] !== $column->getName()) {
return false;
}
return false;
}
示例3: checkColumn
/**
* Do checks for columns.
*
* @param Column $column
* @param IgnoredChange $ignoredChange
*
* @return boolean
*/
protected function checkColumn(Column $column, IgnoredChange $ignoredChange)
{
// Not needed to be implemented yet
if ($ignoredChange->getPropertyName() !== $column->getName()) {
return false;
}
return false;
}
示例4: generateField
/**
* @param \Doctrine\DBAL\Schema\Column $column
* @param mixed $value
*/
public function generateField($column, $value = null)
{
if ($value) {
$this->value = $value;
}
$this->setLabel($column->getName());
$this->name = $column->getName();
return $this;
}
示例5: testQuotedColumnName
/**
* @group DBAL-64
*/
public function testQuotedColumnName()
{
$string = Type::getType('string');
$column = new Column("`bar`", $string, array());
$mysqlPlatform = new \Doctrine\DBAL\Platforms\MySqlPlatform();
$sqlitePlatform = new \Doctrine\DBAL\Platforms\SqlitePlatform();
$this->assertEquals('bar', $column->getName());
$this->assertEquals('`bar`', $column->getQuotedName($mysqlPlatform));
$this->assertEquals('"bar"', $column->getQuotedName($sqlitePlatform));
}
示例6: testColumnComment
/**
* @group DBAL-42
*/
public function testColumnComment()
{
$column = new Column("bar", Type::getType('string'));
$this->assertNull($column->getComment());
$column->setComment("foo");
$this->assertEquals("foo", $column->getComment());
$columnArray = $column->toArray();
$this->assertArrayHasKey('comment', $columnArray);
$this->assertEquals('foo', $columnArray['comment']);
}
示例7: getHtmlAttributes
/**
* @param \Doctrine\DBAL\Schema\Column $column
* @param mixed $value
* @return string
*/
protected function getHtmlAttributes($column, $value = null)
{
$result = "";
if (isset($value)) {
$result .= "value='{$value}' ";
}
if ($name = $column->getName()) {
$fieldName = $this->generateFieldName($name);
$result .= "id='field_{$name}' {$fieldName}";
}
return $result;
}
示例8: __construct
/**
* Maps only needed definitions defined as __CLASS__ properties
* @param Column $column
*/
public function __construct(Column $column)
{
foreach ($column->toArray() as $type => $value) {
if (array_key_exists($type, get_class_vars(__CLASS__))) {
if ($value instanceof Type) {
$this->{$type} = $value->getName();
continue;
}
$this->{$type} = $value;
}
}
return $this;
}
示例9: _getPortableTableColumnDefinition
/**
* {@inheritdoc}
*/
protected function _getPortableTableColumnDefinition($tableColumn)
{
$dbType = strtolower($tableColumn['DATA_TYPE']);
$type = $this->_platform->getDoctrineTypeMapping($dbType);
$type = $this->extractDoctrineTypeFromComment($tableColumn['COLUMN_COMMENT'], $type);
$tableColumn['COLUMN_COMMENT'] = $this->removeDoctrineTypeFromComment($tableColumn['COLUMN_COMMENT'], $type);
$options = array('notnull' => !(bool) $tableColumn['IS_NULLABLE'], 'length' => (int) $tableColumn['CHARACTER_MAXIMUM_LENGTH'], 'default' => isset($tableColumn['COLUMN_DEFAULT']) ? $tableColumn['COLUMN_DEFAULT'] : null, 'autoincrement' => (bool) $tableColumn['IS_AUTO_INCREMENT'], 'scale' => (int) $tableColumn['NUMERIC_SCALE'], 'precision' => (int) $tableColumn['NUMERIC_PRECISION'], 'comment' => isset($tableColumn['COLUMN_COMMENT']) && '' !== $tableColumn['COLUMN_COMMENT'] ? $tableColumn['COLUMN_COMMENT'] : null);
$column = new Column($tableColumn['COLUMN_NAME'], Type::getType($type), $options);
if (!empty($tableColumn['COLLATION_NAME'])) {
$column->setPlatformOption('collation', $tableColumn['COLLATION_NAME']);
}
return $column;
}
示例10: testGetIntegerColumnOptions
public function testGetIntegerColumnOptions()
{
$this->assertPlatform();
$this->platform->expects($this->once())->method('isCommentedDoctrineType')->will($this->returnValue(true));
$column = new Column('string_column', Type::getType(Type::INTEGER));
$column->setNotnull(false);
$column->setAutoincrement(true);
$column->setUnsigned(true);
$result = $this->extension->getColumnOptions($column);
$this->assertEquals(4, count($result));
$this->assertTrue($result['unsigned']);
$this->assertTrue($result['autoincrement']);
$this->assertFalse($result['notnull']);
$this->assertEquals('(DC2Type:integer)', $result['comment']);
}
示例11: execute
/**
* Check for Sequence Duplicates.
*
* Episodes of the same entity that overlap in time.
*
* @access public
* @return boolean the result of the operation
* @param mixed $oMixed The Entity to do operation on
*/
public function execute($oMixed)
{
$oOperation = $this->oOperation;
$oConnection = $this->oConnection;
# execute operation, only care if its successful
$bResult = $oOperation->execute($oMixed);
$sTableName = $this->sTableName;
if (true === $bResult) {
try {
$oInnerQuery = new QueryBuilder($oConnection);
$oInnerQuery->select('count(*)')->from($sTableName, 's2')->andWhere('s1.' . $this->oFromColum->getName() . ' < s2.' . $this->oToColumn->getName() . ' ')->andWhere('s2.' . $this->oFromColum->getName() . ' < s1.' . $this->oToColumn->getName() . ' ');
# process the key columns
foreach ($this->oNaturalKeyColumns as $oColumn) {
$oInnerQuery->andWhere('s1.' . $oColumn->getName() . ' = s2.' . $oColumn->getName() . ' ');
}
// verify the consistence
$sSql = "SELECT count(*) FROM '.{$sTableName}.' AS s1\n WHERE 1 < (\n '.{$oInnerQuery->getSql}().' \n ); ";
$iCount = (int) $oConnection->fetchColumn($sSql, array(), 0);
if ($iCount > 0) {
throw new VoucherException('This entity has a sequence duplicate unable to finish operation');
}
} catch (DBALException $e) {
throw new VoucherException($e->getMessage(), 0, $e);
}
}
return $bResult;
}
示例12: 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;
}
示例13: generateField
/**
* @param \Doctrine\DBAL\Schema\Column $column
* @param mixed $value
*/
public function generateField($column, $value = null)
{
$multiple = false;
$options = $column->getValues();
$options_temp = array();
foreach ($options as $index => $option) {
$option = str_replace("'", '', $option);
$option = str_replace("\"", '', $option);
$options_temp[$option] = $option;
}
$options = $options_temp;
if (!$column->hasUniqueValue()) {
$multiple = true;
}
$value = explode(",", $value);
$name = $column->getName();
return $this->generateFilledField($options, $name, $multiple, $value);
}
示例14: _getPortableTableColumnDefinition
/**
* {@inheritdoc}
*/
protected function _getPortableTableColumnDefinition($tableColumn)
{
$dbType = strtok($tableColumn['type'], '(), ');
$fixed = null;
$length = (int) $tableColumn['length'];
$default = $tableColumn['default'];
if (!isset($tableColumn['name'])) {
$tableColumn['name'] = '';
}
while ($default != ($default2 = preg_replace("/^\\((.*)\\)\$/", '$1', $default))) {
$default = trim($default2, "'");
if ($default == 'getdate()') {
$default = $this->_platform->getCurrentTimestampSQL();
}
}
switch ($dbType) {
case 'nchar':
case 'nvarchar':
case 'ntext':
// Unicode data requires 2 bytes per character
$length = $length / 2;
break;
case 'varchar':
// TEXT type is returned as VARCHAR(MAX) with a length of -1
if ($length == -1) {
$dbType = 'text';
}
break;
}
if ('char' === $dbType || 'nchar' === $dbType || 'binary' === $dbType) {
$fixed = true;
}
$type = $this->_platform->getDoctrineTypeMapping($dbType);
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type);
$tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type);
$options = array('length' => $length == 0 || !in_array($type, array('text', 'string')) ? null : $length, 'unsigned' => false, 'fixed' => (bool) $fixed, 'default' => $default !== 'NULL' ? $default : null, 'notnull' => (bool) $tableColumn['notnull'], 'scale' => $tableColumn['scale'], 'precision' => $tableColumn['precision'], 'autoincrement' => (bool) $tableColumn['autoincrement'], 'comment' => $tableColumn['comment'] !== '' ? $tableColumn['comment'] : null);
$column = new Column($tableColumn['name'], Type::getType($type), $options);
if (isset($tableColumn['collation']) && $tableColumn['collation'] !== 'NULL') {
$column->setPlatformOption('collation', $tableColumn['collation']);
}
return $column;
}
示例15: 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;
}