Commit ea473f7d authored by Claudio Zizza's avatar Claudio Zizza

Add Schema events skeleton and documentation of onSchemaCreateTable

parent 625dd635
......@@ -39,3 +39,101 @@ instance passed to the Connection factory:
$conn = DriverManager::getConnection($connectionParams, null, $evm);
Schema Events
-------------
There are multiple events in Doctrine DBAL that are triggered on schema changes
of the database. It is possible to add your own event listener to be able to run
your own code before changes to the database are commited. An instance of
``Doctrine\Common\EventManager`` can also be added to :doc:`platforms`.
A event listener class can contain one or more methods to schema events. These
methods must be named like the events itself.
.. code-block:: php
<?php
$evm = new EventManager();
$eventName = 'onSchemaCreateTable';
$evm->addEventListener($eventName, new MyEventListener());
.. code-block:: php
<?php
$evm = new EventManager();
$eventNames = array('onSchemaCreateTable', 'onSchemaCreateTableColumn');
$evm->addEventListener($eventNames, new MyEventListener());
The following events are available.
OnSchemaCreateTable Event
^^^^^^^^^^^^^^^^^^^^^^^^^
``Doctrine\DBAL\Events::onSchemaCreateTable`` is triggered before every
create statement that is executed by one of the Platform instances and gets
an instance of ``Doctrine\DBAL\Event\SchemaCreateTableEventArgs`` as event argument.
.. code-block:: php
<?php
class MyEventListener
{
public function onSchemaCreateTable(SchemaCreateTableEventArgs $event)
{
// Your EventListener code
}
}
$evm = new EventManager();
$evm->addEventListener('onSchemaCreateTable', new MyEventListener());
$conn = DriverManager::getConnection($connectionParams, null, $evm);
It allows you to access the ``Doctrine\DBAL\Schema\Table`` instances and its columns, the used Platform and
provides a way to add your own SQL statements.
OnSchemaCreateTableColumn Event
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``Doctrine\DBAL\Events::postConnect`` is triggered
OnSchemaDropTable Event
^^^^^^^^^^^^^^^^^^^^^^^
``Doctrine\DBAL\Events::postConnect`` is triggered
OnSchemaAlterTable Event
^^^^^^^^^^^^^^^^^^^^^^^^
``Doctrine\DBAL\Events::postConnect`` is triggered
OnSchemaAlterTableAddColumn Event
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``Doctrine\DBAL\Events::postConnect`` is triggered
OnSchemaAlterTableRemoveColumn Event
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``Doctrine\DBAL\Events::postConnect`` is triggered
OnSchemaAlterTableChangeColumn Event
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``Doctrine\DBAL\Events::postConnect`` is triggered
OnSchemaAlterTableRenameColumn Event
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``Doctrine\DBAL\Events::postConnect`` is triggered
OnSchemaColumnDefinition Event
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``Doctrine\DBAL\Events::postConnect`` is triggered
OnSchemaIndexDefinition Event
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``Doctrine\DBAL\Events::postConnect`` is triggered
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment