本文整理汇总了PHP中Propel\Generator\Model\Column类的典型用法代码示例。如果您正苦于以下问题:PHP Column类的具体用法?PHP Column怎么用?PHP Column使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Column类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createEnumColumn
public function createEnumColumn($defaultValues, $defaultValue)
{
$column = new Column();
$column->setType(PropelTypes::ENUM);
$column->setValueSet($defaultValues);
$column->setDefaultValue($defaultValue);
return $column;
}
示例2: compareColumns
public static function compareColumns(Column $fromColumn, Column $toColumn)
{
$changedProperties = [];
// compare column types
$fromDomain = $fromColumn->getDomain();
$toDomain = $toColumn->getDomain();
if ($fromDomain->getScale() !== $toDomain->getScale()) {
$changedProperties['scale'] = [$fromDomain->getScale(), $toDomain->getScale()];
}
if ($fromDomain->getSize() !== $toDomain->getSize()) {
$changedProperties['size'] = [$fromDomain->getSize(), $toDomain->getSize()];
}
if (strtoupper($fromDomain->getSqlType()) !== strtoupper($toDomain->getSqlType())) {
if ($fromDomain->getOriginSqlType()) {
if (strtoupper($fromDomain->getOriginSqlType()) !== strtoupper($toDomain->getSqlType())) {
if ($fromDomain->getType() !== $toDomain->getType()) {
$changedProperties['type'] = [$fromDomain->getType(), $toDomain->getType()];
}
$changedProperties['sqlType'] = [$fromDomain->getSqlType(), $toDomain->getSqlType()];
}
} else {
$changedProperties['sqlType'] = [$fromDomain->getSqlType(), $toDomain->getSqlType()];
if ($fromDomain->getType() !== $toDomain->getType()) {
$changedProperties['type'] = [$fromDomain->getType(), $toDomain->getType()];
}
}
}
if ($fromColumn->isNotNull() !== $toColumn->isNotNull()) {
$changedProperties['notNull'] = [$fromColumn->isNotNull(), $toColumn->isNotNull()];
}
// compare column default value
$fromDefaultValue = $fromColumn->getDefaultValue();
$toDefaultValue = $toColumn->getDefaultValue();
if ($fromDefaultValue && !$toDefaultValue) {
$changedProperties['defaultValueType'] = [$fromDefaultValue->getType(), null];
$changedProperties['defaultValueValue'] = [$fromDefaultValue->getValue(), null];
} elseif (!$fromDefaultValue && $toDefaultValue) {
$changedProperties['defaultValueType'] = [null, $toDefaultValue->getType()];
$changedProperties['defaultValueValue'] = [null, $toDefaultValue->getValue()];
} elseif ($fromDefaultValue && $toDefaultValue) {
if (!$fromDefaultValue->equals($toDefaultValue)) {
if ($fromDefaultValue->getType() !== $toDefaultValue->getType()) {
$changedProperties['defaultValueType'] = [$fromDefaultValue->getType(), $toDefaultValue->getType()];
}
if ($fromDefaultValue->getValue() !== $toDefaultValue->getValue()) {
$changedProperties['defaultValueValue'] = [$fromDefaultValue->getValue(), $toDefaultValue->getValue()];
}
}
}
if ($fromColumn->isAutoIncrement() !== $toColumn->isAutoIncrement()) {
$changedProperties['autoIncrement'] = [$fromColumn->isAutoIncrement(), $toColumn->isAutoIncrement()];
}
return $changedProperties;
}
示例3: addBooleanMutator
/**
* Change default propel behaviour
*
* Adds setter method for boolean columns.
*
* @see \Propel\Generator\Builder\Om\ObjectBuilder::addColumnMutators()
*
* @param string &$script The script will be modified in this method.
* @param \Propel\Generator\Model\Column $col The current column.
*
* @return void
*/
protected function addBooleanMutator(&$script, Column $col)
{
$clo = $col->getLowercasedName();
$this->addBooleanMutatorComment($script, $col);
$this->addMutatorOpenOpen($script, $col);
$this->addMutatorOpenBody($script, $col);
$allowNullValues = $col->getAttribute('required', 'true') === 'true' ? 'false' : 'true';
$script .= "\n if (\$v !== null) {\n if (is_string(\$v)) {\n \$v = in_array(strtolower(\$v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;\n } else {\n \$v = (bool) \$v;\n }\n }\n\n \$allowNullValues = {$allowNullValues};\n\n if (\$v === null && !\$allowNullValues) {\n return \$this;\n }\n\n if (\$this->{$clo} !== \$v) {\n \$this->{$clo} = \$v;\n \$this->modifiedColumns[" . $this->getColumnConstant($col) . '] = true;
}
';
$this->addMutatorClose($script, $col);
}
示例4: addTranslatedColumnSetter
protected function addTranslatedColumnSetter(Column $column)
{
$visibility = $column->getTable()->isReadOnly() ? 'protected' : $column->getMutatorVisibility();
$typeHint = '';
$null = '';
if ($column->getTypeHint()) {
$typeHint = $column->getTypeHint();
if ('array' !== $typeHint) {
$typeHint = $this->declareClass($typeHint);
}
$typeHint .= ' ';
if (!$column->isNotNull()) {
$null = ' = null';
}
}
$typeHint = "{$typeHint}\$v{$null}";
$i18nTablePhpName = $this->builder->getClassNameFromBuilder($this->builder->getNewStubObjectBuilder($this->behavior->getI18nTable()));
$tablePhpName = $this->builder->getObjectClassName();
$objectBuilder = $this->builder->getNewObjectBuilder($this->behavior->getI18nTable());
$comment = '';
if ($this->isDateType($column->getType())) {
$objectBuilder->addTemporalMutatorComment($comment, $column);
} else {
$objectBuilder->addMutatorComment($comment, $column);
}
$comment = preg_replace('/^\\t/m', '', $comment);
$comment = str_replace('@return $this|' . $i18nTablePhpName, '@return $this|' . $tablePhpName, $comment);
return $this->renderTemplate('objectTranslatedColumnSetter', ['comment' => $comment, 'column' => $column, 'visibility' => $visibility, 'typeHint' => $typeHint, 'columnPhpName' => $column->getPhpName(), 'localeColumnName' => $this->behavior->getLocaleColumn()->getPhpName()]);
}
示例5: getDefaultValueStringProvider
public static function getDefaultValueStringProvider()
{
$col1 = new Column('Bar');
$col1->setDomain(new Domain('VARCHAR'));
$col1->setDefaultValue(new ColumnDefaultValue('abc', ColumnDefaultValue::TYPE_VALUE));
$val1 = "'abc'";
$col2 = new Column('Bar');
$col2->setDomain(new Domain('INTEGER'));
$col2->setDefaultValue(new ColumnDefaultValue(1234, ColumnDefaultValue::TYPE_VALUE));
$val2 = "1234";
$col3 = new Column('Bar');
$col3->setDomain(new Domain('DATE'));
$col3->setDefaultValue(new ColumnDefaultValue('0000-00-00', ColumnDefaultValue::TYPE_VALUE));
$val3 = "NULL";
return array(array($col1, $val1), array($col2, $val2), array($col3, $val3));
}
示例6: getRefPhpName
/**
* Gets the refPhpName parameter from config array.
*
* @return string
*/
protected function getRefPhpName()
{
$name = $this->getParameter('refPhpName');
if ($name == null) {
$name = Column::generatePhpName($this->getForeignTable());
}
return $name;
}
示例7: __toString
/**
* Returns the string representation of the difference.
*
* @return string
*/
public function __toString()
{
$ret = '';
$ret .= sprintf(" %s:\n", $this->fromColumn->getFullyQualifiedName());
$ret .= " modifiedProperties:\n";
foreach ($this->changedProperties as $key => $value) {
$ret .= sprintf(" %s: %s\n", $key, json_encode($value));
}
return $ret;
}
示例8: getChildrenNames
/**
* Returns the subclasses that can be created from this table.
*
* @return array
*/
public function getChildrenNames()
{
if (null === $this->inheritanceColumn || !$this->inheritanceColumn->isEnumeratedClasses()) {
return null;
}
$names = [];
foreach ($this->inheritanceColumn->getChildren() as $child) {
$names[] = get_class($child);
}
return $names;
}
示例9: addColumn
protected function addColumn(Table $table, $name)
{
if (!$table->hasColumn($name)) {
$column = new Column($name);
// don't know how to define unsigned :(
$domain = new Domain('TINYINT', 'tinyint(3) unsigned');
$column->setDomain($domain);
$table->addColumn($column);
$column_idx_name = $name . '_idx';
if (!$table->hasIndex($column_idx_name)) {
$column_idx = new Index($column_idx_name);
$column_idx->addColumn(['name' => $column->getName()]);
$table->addIndex($column_idx);
}
}
}
示例10: getColumnBindingPHP
/**
* Get the PHP snippet for binding a value to a column.
* Warning: duplicates logic from OracleAdapter::bindValue().
* Any code modification here must be ported there.
*/
public function getColumnBindingPHP(Column $column, $identifier, $columnValueAccessor, $tab = " ")
{
if ($column->getPDOType() == PropelTypes::CLOB_EMU) {
return sprintf("%s\$stmt->bindParam(%s, %s, %s, strlen(%s));\n", $tab, $identifier, $columnValueAccessor, PropelTypes::getPdoTypeString($column->getType()), $columnValueAccessor);
}
return parent::getColumnBindingPHP($column, $identifier, $columnValueAccessor, $tab);
}
示例11: testCompareSeveralColumnDifferences
public function testCompareSeveralColumnDifferences()
{
$t1 = new Table();
$c1 = new Column('col1');
$c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
$c1->getDomain()->replaceSize(255);
$c1->setNotNull(false);
$t1->addColumn($c1);
$c2 = new Column('col2');
$c2->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
$c2->setNotNull(true);
$t1->addColumn($c2);
$c3 = new Column('col3');
$c3->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
$c3->getDomain()->replaceSize(255);
$t1->addColumn($c3);
$t2 = new Table();
$c4 = new Column('col1');
$c4->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
$c4->getDomain()->replaceScale(2);
$c4->getDomain()->replaceSize(3);
$c4->setNotNull(true);
$c4->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE));
$t2->addColumn($c4);
$c5 = new Column('col22');
$c5->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
$c5->setNotNull(true);
$t2->addColumn($c5);
$c6 = new Column('col4');
$c6->getDomain()->copy($this->platform->getDomainForType('LONGVARCHAR'));
$c6->getDomain()->setDefaultValue(new ColumnDefaultValue('123', ColumnDefaultValue::TYPE_VALUE));
$t2->addColumn($c6);
// col1 was modified, col2 was renamed, col3 was removed, col4 was added
$tc = new PropelTableComparator();
$tc->setFromTable($t1);
$tc->setToTable($t2);
$nbDiffs = $tc->compareColumns();
$tableDiff = $tc->getTableDiff();
$this->assertEquals(4, $nbDiffs);
$this->assertEquals(array(array($c2, $c5)), $tableDiff->getRenamedColumns());
$this->assertEquals(array('col4' => $c6), $tableDiff->getAddedColumns());
$this->assertEquals(array('col3' => $c3), $tableDiff->getRemovedColumns());
$columnDiff = PropelColumnComparator::computeDiff($c1, $c4);
$this->assertEquals(array('col1' => $columnDiff), $tableDiff->getModifiedColumns());
}
示例12: addFilterByArrayCol
/**
* Adds the singular filterByCol method for an Array column.
* @param string &$script The script will be modified in this method.
* @param Column $col
*/
protected function addFilterByArrayCol(&$script, Column $col)
{
$colPhpName = $col->getPhpName();
$singularPhpName = $col->getPhpSingularName();
$colName = $col->getName();
$variableName = $col->getCamelCaseName();
$qualifiedName = $this->getColumnConstant($col);
$script .= "\n /**\n * Filter the query on the {$colName} column\n * @param mixed \${$variableName} The value to use as filter\n * @param string \$comparison Operator to use for the column comparison, defaults to Criteria::CONTAINS_ALL\n *\n * @return \$this|" . $this->getQueryClassName() . " The current query, for fluid interface\n */\n public function filterBy{$singularPhpName}(\${$variableName} = null, \$comparison = null)\n {\n if (null === \$comparison || \$comparison == Criteria::CONTAINS_ALL) {\n if (is_scalar(\${$variableName})) {\n \${$variableName} = '%| ' . \${$variableName} . ' |%';\n \$comparison = Criteria::LIKE;\n }\n } elseif (\$comparison == Criteria::CONTAINS_NONE) {\n \${$variableName} = '%| ' . \${$variableName} . ' |%';\n \$comparison = Criteria::NOT_LIKE;\n \$key = \$this->getAliasedColName({$qualifiedName});\n if (\$this->containsKey(\$key)) {\n \$this->addAnd(\$key, \${$variableName}, \$comparison);\n } else {\n \$this->addAnd(\$key, \${$variableName}, \$comparison);\n }\n \$this->addOr(\$key, null, Criteria::ISNULL);\n\n return \$this;\n }\n\n return \$this->addUsingAlias({$qualifiedName}, \${$variableName}, \$comparison);\n }\n";
}
示例13: getColumnDDL
public function getColumnDDL(Column $col)
{
if ($col->isAutoIncrement()) {
$col->setType('INTEGER');
$col->setDomainForType('INTEGER');
}
if ($col->getDefaultValue() && $col->getDefaultValue()->isExpression() && 'CURRENT_TIMESTAMP' === $col->getDefaultValue()->getValue()) {
//sqlite use CURRENT_TIMESTAMP different than mysql/pgsql etc
//we set it to the more common behavior
$col->setDefaultValue(new ColumnDefaultValue("(datetime(CURRENT_TIMESTAMP, 'localtime'))", ColumnDefaultValue::TYPE_EXPR));
}
return parent::getColumnDDL($col);
}
示例14: addColumns
/**
* Adds Columns to the specified table.
*
* @param Table $table The Table model class to add columns to.
*/
protected function addColumns(Table $table)
{
$tableName = $table->getName();
// var_dump("PRAGMA table_info('$tableName') //");
$stmt = $this->dbh->query("PRAGMA table_info('{$tableName}')");
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$name = $row['name'];
$fulltype = $row['type'];
$size = null;
$scale = null;
if (preg_match('/^([^\\(]+)\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)$/', $fulltype, $matches)) {
$type = $matches[1];
$size = $matches[2];
$scale = $matches[3];
} elseif (preg_match('/^([^\\(]+)\\(\\s*(\\d+)\\s*\\)$/', $fulltype, $matches)) {
$type = $matches[1];
$size = $matches[2];
} else {
$type = $fulltype;
}
$notNull = $row['notnull'];
$default = $row['dflt_value'];
$propelType = $this->getMappedPropelType(strtolower($type));
if (!$propelType) {
$propelType = Column::DEFAULT_TYPE;
$this->warn('Column [' . $table->getName() . '.' . $name . '] has a column type (' . $type . ') that Propel does not support.');
}
$column = new Column($name);
$column->setTable($table);
$column->setDomainForType($propelType);
// We may want to provide an option to include this:
// $column->getDomain()->replaceSqlType($type);
$column->getDomain()->replaceSize($size);
$column->getDomain()->replaceScale($scale);
if (null !== $default) {
if ("'" !== substr($default, 0, 1) && strpos($default, '(')) {
$defaultType = ColumnDefaultValue::TYPE_EXPR;
if ('datetime(CURRENT_TIMESTAMP, \'localtime\')' === $default) {
$default = 'CURRENT_TIMESTAMP';
}
} else {
$defaultType = ColumnDefaultValue::TYPE_VALUE;
$default = str_replace("'", '', $default);
}
$column->getDomain()->setDefaultValue(new ColumnDefaultValue($default, $defaultType));
}
$column->setNotNull($notNull);
if (0 < $row['pk'] + 0) {
$column->setPrimaryKey(true);
}
if ($column->isPrimaryKey()) {
// check if autoIncrement
$autoIncrementStmt = $this->dbh->prepare('
SELECT tbl_name
FROM sqlite_master
WHERE
tbl_name = ?
AND
sql LIKE "%AUTOINCREMENT%"
');
$autoIncrementStmt->execute([$table->getName()]);
$autoincrementRow = $autoIncrementStmt->fetch(\PDO::FETCH_ASSOC);
if ($autoincrementRow && $autoincrementRow['tbl_name'] == $table->getName()) {
$column->setAutoIncrement(true);
}
}
$table->addColumn($column);
}
}
示例15: addColumns
/**
* Adds Columns to the specified table.
*
* @param Table $table The Table model class to add columns to.
*/
protected function addColumns(Table $table)
{
$stmt = $this->dbh->query("PRAGMA table_info('" . $table->getName() . "')");
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$name = $row['name'];
$fulltype = $row['type'];
$size = null;
$precision = null;
$scale = null;
if (preg_match('/^([^\\(]+)\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)$/', $fulltype, $matches)) {
$type = $matches[1];
$precision = $matches[2];
$scale = $matches[3];
// aka precision
} elseif (preg_match('/^([^\\(]+)\\(\\s*(\\d+)\\s*\\)$/', $fulltype, $matches)) {
$type = $matches[1];
$size = $matches[2];
} else {
$type = $fulltype;
}
// If column is primary key and of type INTEGER, it is auto increment
// See: http://sqlite.org/faq.html#q1
$autoincrement = 1 == $row['pk'] && 'integer' === strtolower($type);
$notNull = $row['notnull'];
$default = $row['dflt_value'];
$propelType = $this->getMappedPropelType(strtolower($type));
if (!$propelType) {
$propelType = Column::DEFAULT_TYPE;
$this->warn('Column [' . $table->getName() . '.' . $name . '] has a column type (' . $type . ') that Propel does not support.');
}
$column = new Column($name);
$column->setTable($table);
$column->setDomainForType($propelType);
// We may want to provide an option to include this:
// $column->getDomain()->replaceSqlType($type);
$column->getDomain()->replaceSize($size);
$column->getDomain()->replaceScale($scale);
if (null !== $default) {
$column->getDomain()->setDefaultValue(new ColumnDefaultValue($default, ColumnDefaultValue::TYPE_VALUE));
}
$column->setAutoIncrement($autoincrement);
$column->setNotNull($notNull);
if (1 == $row['pk'] || 'integer' === strtolower($type)) {
$column->setPrimaryKey(true);
}
$table->addColumn($column);
}
}