本文整理匯總了PHP中Propel\Generator\Model\Column::getPhpDefaultValue方法的典型用法代碼示例。如果您正苦於以下問題:PHP Column::getPhpDefaultValue方法的具體用法?PHP Column::getPhpDefaultValue怎麽用?PHP Column::getPhpDefaultValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Propel\Generator\Model\Column
的用法示例。
在下文中一共展示了Column::getPhpDefaultValue方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getDefaultValueString
/**
* Returns the type-casted and stringified default value for the specified
* Column. This only works for scalar default values currently.
*
* @param Column $column
* @throws EngineException
* @return string
*/
protected function getDefaultValueString(Column $column)
{
$defaultValue = var_export(null, true);
$val = $column->getPhpDefaultValue();
if (null === $val) {
return $defaultValue;
}
if ($column->isTemporalType()) {
$fmt = $this->getTemporalFormatter($column);
try {
if (!($this->getPlatform() instanceof MysqlPlatform && ($val === '0000-00-00 00:00:00' || $val === '0000-00-00'))) {
// while technically this is not a default value of NULL,
// this seems to be closest in meaning.
$defDt = new \DateTime($val);
$defaultValue = var_export($defDt->format($fmt), true);
}
} catch (\Exception $exception) {
// prevent endless loop when timezone is undefined
date_default_timezone_set('America/Los_Angeles');
throw new EngineException(sprintf('Unable to parse default temporal value "%s" for column "%s"', $column->getDefaultValueString(), $column->getFullyQualifiedName()), 0, $exception);
}
} elseif ($column->isEnumType()) {
$valueSet = $column->getValueSet();
if (!in_array($val, $valueSet)) {
throw new EngineException(sprintf('Default Value "%s" is not among the enumerated values', $val));
}
$defaultValue = array_search($val, $valueSet);
} elseif ($column->isSetType()) {
$defaultValue = SetColumnConverter::convertToInt($val, $column->getValueSet());
} elseif ($column->isPhpPrimitiveType()) {
settype($val, $column->getPhpType());
$defaultValue = var_export($val, true);
} elseif ($column->isPhpObjectType()) {
$defaultValue = 'new ' . $column->getPhpType() . '(' . var_export($val, true) . ')';
} elseif ($column->isPhpArrayType()) {
$defaultValue = var_export($val, true);
} else {
throw new EngineException("Cannot get default value string for " . $column->getFullyQualifiedName());
}
return $defaultValue;
}
示例2: testGetPhpDefaultValue
public function testGetPhpDefaultValue()
{
$domain = $this->getDomainMock();
$domain->expects($this->once())->method('getPhpDefaultValue')->will($this->returnValue(true));
$column = new Column();
$column->setDomain($domain);
$this->assertTrue($column->getPhpDefaultValue());
}