Skip to content

Instantly share code, notes, and snippets.

@basz
Created July 20, 2012 11:47
Show Gist options
  • Save basz/3150318 to your computer and use it in GitHub Desktop.
Save basz/3150318 to your computer and use it in GitHub Desktop.
WORKS
Rattletrap:juffrouwjansen-winkels.nl bas$ ./vendor/bin/doctrine-module orm:schema-tool:create --dump-sql
CREATE TABLE brand (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) DEFAULT NULL, published TINYINT(1) DEFAULT NULL, siteDomain ENUM('hoofddorp', 'studio', 'all') COMMENT '(DC2Type:enumsitedomain)' NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDB;
=====================
DOES NOT WORK
Rattletrap:juffrouwjansen-winkels.nl bas$ ./vendor/bin/doctrine-module orm:schema-tool:drop --dump-sql
[Doctrine\DBAL\DBALException]
Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.
orm:schema-tool:drop [--dump-sql] [--force] [--full-database]
Rattletrap:juffrouwjansen-winkels.nl bas$
=====================
<?php
namespace Application\DBAL;
class EnumSiteDomainType extends EnumType
{
protected $name = 'enumsitedomain';
protected $values = array('hoofddorp', 'studio', 'all');
}
=========================
<?php
namespace Application\DBAL;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
abstract class EnumType extends Type
{
protected $name;
protected $values = array();
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
$values = array_map(function($val) { return "'".$val."'"; }, $this->values);
return "ENUM(".implode(", ", $values).") COMMENT '(DC2Type:".$this->name.")'";
}
public function convertToPHPValue($value, AbstractPlatform $platform)
{
return $value;
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if (!in_array($value, $this->values)) {
throw new \InvalidArgumentException("Invalid '".$this->name."' value.");
}
return $value;
}
public function getName()
{
return $this->name;
}
}
=============================
<?php
namespace Application\Entity;
use Doctrine\ORM\Mapping as ORM;
abstract class AbstractEntity
{
/**
* @ORM\Id
* @ORM\Column(type="integer");
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
protected $published;
/**
* @ORM\Column(type="enumsitedomain")
*/
protected $siteDomain;
/**
* @return int|null
*/
public function getId()
{
return $this->id;
}
public function setPublished($published) {
$this->published = $published;
}
public function getPublished() {
return $this->published;
}
public function setSiteDomain($siteDomain) {
$this->siteDomain = $siteDomain;
}
public function getSiteDomain() {
return $this->siteDomain;
}
}
=====================================
<?php
namespace Application\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="brand")
*/
class Brand extends AbstractEntity
{
/**
* @ORM\Column(type="string", nullable=true)
*/
protected $name;
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment