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
f042fd8b
Commit
f042fd8b
authored
Apr 08, 2013
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adjust ForeignKeyContraint asset to be able to return quoted column names
parent
89aecb10
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
110 additions
and
35 deletions
+110
-35
ForeignKeyConstraint.php
lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php
+110
-35
No files found.
lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php
View file @
f042fd8b
...
...
@@ -25,6 +25,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
* An abstraction class for a foreign key constraint.
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.0
*/
...
...
@@ -33,27 +34,33 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
/**
* @var Table Instance of the referencing table the foreign key constraint is associated with.
*/
protected
$localTable
;
protected
$
_
localTable
;
/**
* @var array Names of the referencing table columns the foreign key constraint is associated with.
* Asset identifier instances of the referencing table column names the foreign key constraint is associated with.
* array($columnName => Identifier)
*
* @var Identifier[]
*/
protected
$localColumnNames
;
protected
$
_
localColumnNames
;
/**
* @var
string Name of the referenced tabl
e the foreign key constraint is associated with.
* @var
Identifier Asset identifier instance of the referenced table nam
e the foreign key constraint is associated with.
*/
protected
$foreignTableName
;
protected
$
_
foreignTableName
;
/**
* @var array Names of the referenced table columns the foreign key constraint is associated with.
* Asset identifier instances of the referenced table column names the foreign key constraint is associated with.
* array($columnName => Identifier)
*
* @var Identifier[]
*/
protected
$foreignColumnNames
;
protected
$
_
foreignColumnNames
;
/**
* @var array Options associated with the foreign key constraint.
*/
protected
$options
;
protected
$
_
options
;
/**
* Initializes the foreign key constraint.
...
...
@@ -67,10 +74,14 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
public
function
__construct
(
array
$localColumnNames
,
$foreignTableName
,
array
$foreignColumnNames
,
$name
=
null
,
array
$options
=
array
())
{
$this
->
_setName
(
$name
);
$this
->
localColumnNames
=
$localColumnNames
;
$this
->
foreignTableName
=
$foreignTableName
;
$this
->
foreignColumnNames
=
$foreignColumnNames
;
$this
->
options
=
$options
;
$this
->
_localColumnNames
=
array_combine
(
$localColumnNames
,
array_map
(
function
(
$column
)
{
return
new
Identifier
(
$column
);
},
$localColumnNames
));
$this
->
_foreignTableName
=
new
Identifier
(
$foreignTableName
);
$this
->
_foreignColumnNames
=
array_combine
(
$foreignColumnNames
,
array_map
(
function
(
$column
)
{
return
new
Identifier
(
$column
);
},
$foreignColumnNames
));
$this
->
_options
=
$options
;
}
/**
...
...
@@ -81,7 +92,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
*/
public
function
getLocalTableName
()
{
return
$this
->
localTable
->
getName
();
return
$this
->
_
localTable
->
getName
();
}
/**
...
...
@@ -92,7 +103,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
*/
public
function
setLocalTable
(
Table
$table
)
{
$this
->
localTable
=
$table
;
$this
->
_
localTable
=
$table
;
}
/**
...
...
@@ -111,18 +122,62 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
*/
public
function
getLocalColumns
()
{
return
$this
->
localColumnNames
;
return
array_keys
(
$this
->
_localColumnNames
);
}
/**
* Returns the quoted representation of the referencing table column names
* the foreign key constraint is associated with.
*
* But only if they were defined with one or the referencing table column name
* is a keyword reserved by the platform.
* Otherwise the plain unquoted value as inserted is returned.
*
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The platform to use for quotation.
*
* @return array
*/
public
function
getQuotedLocalColumns
(
AbstractPlatform
$platform
)
{
$columns
=
array
();
foreach
(
$this
->
_localColumnNames
as
$column
)
{
$columns
[]
=
$column
->
getQuotedName
(
$platform
);
}
return
$columns
;
}
/**
* Returns the names of the referencing table columns
* the foreign key constraint is associated with.
*
* @see getLocalColumns
*
* @return array
*/
public
function
getColumns
()
{
return
$this
->
localColumnNames
;
return
$this
->
getLocalColumns
();
}
/**
* Returns the quoted representation of the referencing table column names
* the foreign key constraint is associated with.
*
* But only if they were defined with one or the referencing table column name
* is a keyword reserved by the platform.
* Otherwise the plain unquoted value as inserted is returned.
*
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The platform to use for quotation.
*
* @see getQuotedLocalColumns
*
* @return array
*/
public
function
getQuotedColumns
(
AbstractPlatform
$platform
)
{
return
$this
->
getQuotedLocalColumns
(
$platform
);
}
/**
...
...
@@ -133,7 +188,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
*/
public
function
getForeignTableName
()
{
return
$this
->
foreignTableName
;
return
$this
->
_foreignTableName
->
getName
()
;
}
/**
...
...
@@ -143,28 +198,25 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
*/
public
function
getUnqualifiedForeignTableName
()
{
$parts
=
explode
(
"."
,
$this
->
_foreignTableName
);
$parts
=
explode
(
"."
,
$this
->
_foreignTableName
->
getName
()
);
return
strtolower
(
end
(
$parts
));
}
/**
* Get the quoted representation of this asset but only if it was defined with one. Otherwise
* return the plain unquoted value as inserted.
* Returns the quoted representation of the referenced table name
* the foreign key constraint is associated with.
*
* But only if it was defined with one or the referenced table name
* is a keyword reserved by the platform.
* Otherwise the plain unquoted value as inserted is returned.
*
* @param
AbstractPlatform $platform The platform to use for quoting
.
* @param
\Doctrine\DBAL\Platforms\AbstractPlatform $platform The platform to use for quotation
.
*
* @return string
*/
public
function
getQuotedForeignTableName
(
AbstractPlatform
$platform
)
{
$keywords
=
$platform
->
getReservedKeywordsList
();
$parts
=
explode
(
"."
,
$this
->
getForeignTableName
());
foreach
(
$parts
as
$k
=>
$v
)
{
$parts
[
$k
]
=
(
$this
->
_quoted
||
$keywords
->
isKeyword
(
$v
))
?
$platform
->
quoteIdentifier
(
$v
)
:
$v
;
}
return
implode
(
"."
,
$parts
);
return
$this
->
_foreignTableName
->
getQuotedName
(
$platform
);
}
/**
...
...
@@ -175,7 +227,30 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
*/
public
function
getForeignColumns
()
{
return
$this
->
foreignColumnNames
;
return
array_keys
(
$this
->
_foreignColumnNames
);
}
/**
* Returns the quoted representation of the referenced table column names
* the foreign key constraint is associated with.
*
* But only if they were defined with one or the referenced table column name
* is a keyword reserved by the platform.
* Otherwise the plain unquoted value as inserted is returned.
*
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The platform to use for quotation.
*
* @return array
*/
public
function
getQuotedForeignColumns
(
AbstractPlatform
$platform
)
{
$columns
=
array
();
foreach
(
$this
->
_foreignColumnNames
as
$column
)
{
$columns
[]
=
$column
->
getQuotedName
(
$platform
);
}
return
$columns
;
}
/**
...
...
@@ -188,7 +263,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
*/
public
function
hasOption
(
$name
)
{
return
isset
(
$this
->
options
[
$name
]);
return
isset
(
$this
->
_
options
[
$name
]);
}
/**
...
...
@@ -200,7 +275,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
*/
public
function
getOption
(
$name
)
{
return
$this
->
options
[
$name
];
return
$this
->
_
options
[
$name
];
}
/**
...
...
@@ -210,7 +285,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
*/
public
function
getOptions
()
{
return
$this
->
options
;
return
$this
->
_
options
;
}
/**
...
...
@@ -245,8 +320,8 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
*/
private
function
onEvent
(
$event
)
{
if
(
isset
(
$this
->
options
[
$event
]))
{
$onEvent
=
strtoupper
(
$this
->
options
[
$event
]);
if
(
isset
(
$this
->
_
options
[
$event
]))
{
$onEvent
=
strtoupper
(
$this
->
_
options
[
$event
]);
if
(
!
in_array
(
$onEvent
,
array
(
'NO ACTION'
,
'RESTRICT'
)))
{
return
$onEvent
;
...
...
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