Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
07e84011
Commit
07e84011
authored
Dec 08, 2011
by
jsor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change SchemaCreateTable event handling
parent
ff5f1fdc
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
113 additions
and
38 deletions
+113
-38
SchemaCreateTableColumnEventArgs.php
lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php
+58
-3
SchemaCreateTableEventArgs.php
lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php
+33
-3
Events.php
lib/Doctrine/DBAL/Events.php
+1
-3
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+18
-23
AbstractPlatformTestCase.php
...octrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
+3
-6
No files found.
lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php
View file @
07e84011
...
@@ -35,13 +35,28 @@ use Doctrine\Common\EventArgs,
...
@@ -35,13 +35,28 @@ use Doctrine\Common\EventArgs,
* @version $Revision$
* @version $Revision$
* @author Jan Sorgalla <jsorgalla@googlemail.com>
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
*/
class
SchemaCreateTableColumnEventArgs
extends
Schema
CreateTable
EventArgs
class
SchemaCreateTableColumnEventArgs
extends
SchemaEventArgs
{
{
/**
/**
* @var Column
* @var Column
*/
*/
private
$_column
=
null
;
private
$_column
=
null
;
/**
* @var Table
*/
private
$_table
=
null
;
/**
* @var AbstractPlatform
*/
private
$_platform
=
null
;
/**
* @var array
*/
private
$_sql
=
array
();
/**
/**
* @param Column $column
* @param Column $column
* @param Table $table
* @param Table $table
...
@@ -49,8 +64,9 @@ class SchemaCreateTableColumnEventArgs extends SchemaCreateTableEventArgs
...
@@ -49,8 +64,9 @@ class SchemaCreateTableColumnEventArgs extends SchemaCreateTableEventArgs
*/
*/
public
function
__construct
(
Column
$column
,
Table
$table
,
AbstractPlatform
$platform
)
public
function
__construct
(
Column
$column
,
Table
$table
,
AbstractPlatform
$platform
)
{
{
parent
::
__construct
(
$table
,
$platform
);
$this
->
_column
=
$column
;
$this
->
_column
=
$column
;
$this
->
_table
=
$table
;
$this
->
_platform
=
$platform
;
}
}
/**
/**
...
@@ -60,4 +76,43 @@ class SchemaCreateTableColumnEventArgs extends SchemaCreateTableEventArgs
...
@@ -60,4 +76,43 @@ class SchemaCreateTableColumnEventArgs extends SchemaCreateTableEventArgs
{
{
return
$this
->
_column
;
return
$this
->
_column
;
}
}
/**
* @return Doctrine\DBAL\Schema\Table
*/
public
function
getTable
()
{
return
$this
->
_table
;
}
/**
* @return Doctrine\DBAL\Platforms\AbstractPlatform
*/
public
function
getPlatform
()
{
return
$this
->
_platform
;
}
/**
* @param string|array $sql
* @return SchemaEventArgs
*/
public
function
addSql
(
$sql
)
{
if
(
is_array
(
$sql
))
{
$this
->
_sql
=
array_merge
(
$this
->
_sql
,
$sql
);
}
else
{
$this
->
_sql
[]
=
$sql
;
}
return
$this
;
}
/**
* @return array
*/
public
function
getSql
()
{
return
$this
->
_sql
;
}
}
}
lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php
View file @
07e84011
...
@@ -40,7 +40,17 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
...
@@ -40,7 +40,17 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
* @var Table
* @var Table
*/
*/
private
$_table
=
null
;
private
$_table
=
null
;
/**
* @var array
*/
private
$_columns
=
null
;
/**
* @var array
*/
private
$_options
=
null
;
/**
/**
* @var AbstractPlatform
* @var AbstractPlatform
*/
*/
...
@@ -53,11 +63,15 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
...
@@ -53,11 +63,15 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
/**
/**
* @param Table $table
* @param Table $table
* @param array $columns
* @param array $options
* @param AbstractPlatform $platform
* @param AbstractPlatform $platform
*/
*/
public
function
__construct
(
Table
$table
,
AbstractPlatform
$platform
)
public
function
__construct
(
Table
$table
,
array
$columns
,
array
$options
,
AbstractPlatform
$platform
)
{
{
$this
->
_table
=
$table
;
$this
->
_table
=
$table
;
$this
->
_columns
=
$columns
;
$this
->
_options
=
$options
;
$this
->
_platform
=
$platform
;
$this
->
_platform
=
$platform
;
}
}
...
@@ -69,6 +83,22 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
...
@@ -69,6 +83,22 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
return
$this
->
_table
;
return
$this
->
_table
;
}
}
/**
* @return array
*/
public
function
getColumns
()
{
return
$this
->
_columns
;
}
/**
* @return array
*/
public
function
getOptions
()
{
return
$this
->
_options
;
}
/**
/**
* @return Doctrine\DBAL\Platforms\AbstractPlatform
* @return Doctrine\DBAL\Platforms\AbstractPlatform
*/
*/
...
...
lib/Doctrine/DBAL/Events.php
View file @
07e84011
...
@@ -35,10 +35,8 @@ final class Events
...
@@ -35,10 +35,8 @@ final class Events
const
postConnect
=
'postConnect'
;
const
postConnect
=
'postConnect'
;
const
preSchemaCreateTable
=
'pre
SchemaCreateTable'
;
const
onSchemaCreateTable
=
'on
SchemaCreateTable'
;
const
onSchemaCreateTableColumn
=
'onSchemaCreateTableColumn'
;
const
onSchemaCreateTableColumn
=
'onSchemaCreateTableColumn'
;
const
postSchemaCreateTable
=
'postSchemaCreateTable'
;
const
onSchemaDropTable
=
'onSchemaDropTable'
;
const
onSchemaDropTable
=
'onSchemaDropTable'
;
const
onSchemaColumnDefinition
=
'onSchemaColumnDefinition'
;
const
onSchemaColumnDefinition
=
'onSchemaColumnDefinition'
;
}
}
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
07e84011
...
@@ -971,15 +971,6 @@ abstract class AbstractPlatform
...
@@ -971,15 +971,6 @@ abstract class AbstractPlatform
throw
new
\InvalidArgumentException
(
"Second argument of AbstractPlatform::getCreateTableSQL() has to be integer."
);
throw
new
\InvalidArgumentException
(
"Second argument of AbstractPlatform::getCreateTableSQL() has to be integer."
);
}
}
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
preSchemaCreateTable
))
{
$eventArgs
=
new
SchemaCreateTableEventArgs
(
$table
,
$this
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
preSchemaCreateTable
,
$eventArgs
);
if
(
$eventArgs
->
isDefaultPrevented
())
{
return
$eventArgs
->
getSql
();
}
}
if
(
count
(
$table
->
getColumns
())
==
0
)
{
if
(
count
(
$table
->
getColumns
())
==
0
)
{
throw
DBALException
::
noColumnsSpecifiedForTable
(
$table
->
getName
());
throw
DBALException
::
noColumnsSpecifiedForTable
(
$table
->
getName
());
}
}
...
@@ -1050,25 +1041,29 @@ abstract class AbstractPlatform
...
@@ -1050,25 +1041,29 @@ abstract class AbstractPlatform
}
}
}
}
$sql
=
$this
->
_getCreateTableSQL
(
$tableName
,
$columns
,
$options
);
$tableSql
=
array
();
if
(
$this
->
supportsCommentOnStatement
())
{
$defaultPrevented
=
false
;
foreach
(
$table
->
getColumns
()
AS
$column
)
{
if
(
$column
->
getComment
())
{
$sql
[]
=
$this
->
getCommentOnColumnSQL
(
$tableName
,
$column
->
getName
(),
$this
->
getColumnComment
(
$column
));
}
}
}
$sql
=
array_merge
(
$sql
,
$columnSql
);
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
onSchemaCreateTable
))
{
$eventArgs
=
new
SchemaCreateTableEventArgs
(
$table
,
$columns
,
$options
,
$this
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
onSchemaCreateTable
,
$eventArgs
);
if
(
null
!==
$this
->
_eventManager
&&
$this
->
_eventManager
->
hasListeners
(
Events
::
postSchemaCreateTable
))
{
$defaultPrevented
=
$eventArgs
->
isDefaultPrevented
();
$
eventArgs
=
new
SchemaCreateTableEventArgs
(
$table
,
$this
);
$
tableSql
=
$eventArgs
->
getSql
(
);
$this
->
_eventManager
->
dispatchEvent
(
Events
::
postSchemaCreateTable
,
$eventArgs
);
}
$sql
=
array_merge
(
$sql
,
$eventArgs
->
getSql
());
if
(
!
$defaultPrevented
)
{
$tableSql
=
$this
->
_getCreateTableSQL
(
$tableName
,
$columns
,
$options
);
if
(
$this
->
supportsCommentOnStatement
())
{
foreach
(
$table
->
getColumns
()
AS
$column
)
{
if
(
$column
->
getComment
())
{
$tableSql
[]
=
$this
->
getCommentOnColumnSQL
(
$tableName
,
$column
->
getName
(),
$this
->
getColumnComment
(
$column
));
}
}
}
}
}
return
$sql
;
return
array_merge
(
$tableSql
,
$columnSql
)
;
}
}
public
function
getCommentOnColumnSQL
(
$tableName
,
$columnName
,
$comment
)
public
function
getCommentOnColumnSQL
(
$tableName
,
$columnName
,
$comment
)
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
View file @
07e84011
...
@@ -181,19 +181,16 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
...
@@ -181,19 +181,16 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
public
function
testGetCreateTableSqlDispatchEvent
()
public
function
testGetCreateTableSqlDispatchEvent
()
{
{
$listenerMock
=
$this
->
getMock
(
'GetCreateTableSqlDispatchEvenListener'
,
array
(
'
preSchemaCreateTable'
,
'onSchemaCreateTableColumn'
,
'postSchemaCreateTable
'
));
$listenerMock
=
$this
->
getMock
(
'GetCreateTableSqlDispatchEvenListener'
,
array
(
'
onSchemaCreateTable'
,
'onSchemaCreateTableColumn
'
));
$listenerMock
$listenerMock
->
expects
(
$this
->
once
())
->
expects
(
$this
->
once
())
->
method
(
'
pre
SchemaCreateTable'
);
->
method
(
'
on
SchemaCreateTable'
);
$listenerMock
$listenerMock
->
expects
(
$this
->
exactly
(
2
))
->
expects
(
$this
->
exactly
(
2
))
->
method
(
'onSchemaCreateTableColumn'
);
->
method
(
'onSchemaCreateTableColumn'
);
$listenerMock
->
expects
(
$this
->
once
())
->
method
(
'postSchemaCreateTable'
);
$eventManager
=
new
EventManager
();
$eventManager
=
new
EventManager
();
$eventManager
->
addEventListener
(
array
(
Events
::
preSchemaCreateTable
,
Events
::
onSchemaCreateTableColumn
,
Events
::
postSchemaCreateTable
),
$listenerMock
);
$eventManager
->
addEventListener
(
array
(
Events
::
onSchemaCreateTable
,
Events
::
onSchemaCreateTableColumn
),
$listenerMock
);
$this
->
_platform
->
setEventManager
(
$eventManager
);
$this
->
_platform
->
setEventManager
(
$eventManager
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment