<?php
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Events;
use Doctrine\DBAL\Event\SchemaCreateTableEventArgs;
class Foo
{
public function onSchemaCreateTable(SchemaCreateTableEventArgs $event)
{
dump('Do stuff before table creation');
}
}
/** @var $conn Doctrine\DBAL\Connection */
$conn->getEventManager()
->addEventListener(Events::onSchemaCreateTable, new Foo());
$column = new Column('bar', Type::getType('string'));
$table = new Table('foo', [$column]);
$sql = $conn->getDatabasePlatform()
->getCreateTableSql($table);
dump($sql);
^ "Do stuff before table creation"
^ array:1 [
0 => "CREATE TABLE foo (bar VARCHAR(255) NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB"
]