本文整理汇总了PHP中Doctrine\DBAL\Types\Type::convertToDatabaseValue方法的典型用法代码示例。如果您正苦于以下问题:PHP Type::convertToDatabaseValue方法的具体用法?PHP Type::convertToDatabaseValue怎么用?PHP Type::convertToDatabaseValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Types\Type
的用法示例。
在下文中一共展示了Type::convertToDatabaseValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testArray
public function testArray()
{
$photo = new Photo();
$photo->setNom('wohoo');
$serialized = $this->type->convertToDatabaseValue([$photo], $this->plateform);
$unserialized = $this->type->convertToPHPValue($serialized, $this->plateform);
$this->assertInstanceOf(Photo::class, $unserialized[0]);
/** @var Photo $var */
$var = $unserialized[0];
$this->assertEquals('wohoo', $var->getNom());
}
示例2: convertToDatabaseValue
/**
* @param DateTimeOfDay $value
* @param AbstractPlatform $platform
*
* @return string
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if ($value instanceof DateTimeOfDay) {
return $value->toDateTime()->format($platform->getDateTimeFormatString());
}
return parent::convertToDatabaseValue($value, $platform);
}
示例3: convertToDatabaseValue
/**
* (non-PHPdoc)
* @see \Doctrine\DBAL\Types\Type::convertToDatabaseValue()
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if ($value === null) {
return null;
} elseif ($value instanceof \DateTime) {
return $value->format('Y-m-d H:i:s.uO');
} elseif (is_string($value)) {
try {
return parent::convertToDatabaseValue($value, $platform);
} catch (\Exception $e) {
try {
$dt = new \DateTime($value);
return $dt->format('Y-m-d H:i:s.uO');
} catch (\Exception $e) {
throw new \Exception('Date "' . $value . '" is not a valid date');
}
}
}
throw new \Exception('Date "' . $value . '" is not a valid date');
}
示例4: testConversionToSQL
/**
* @dataProvider phpValueProvider
*/
public function testConversionToSQL($value, $expected)
{
$sql = $this->type->convertToDatabaseValue($value, $this->platform);
$this->assertEquals($expected, $sql);
}
示例5: testNullConversionForDatabaseValue
public function testNullConversionForDatabaseValue()
{
$this->assertNull($this->type->convertToDatabaseValue(null, $this->platform));
}
示例6: value
private function value(EntityManager $em, Type $type, $value)
{
$platform = $em->getConnection()->getDatabasePlatform();
switch ($type->getName()) {
case Type::BOOLEAN:
return $type->convertToPHPValue($value, $platform);
// json supports boolean values
// json supports boolean values
default:
return $type->convertToDatabaseValue($value, $platform);
}
}