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
57724c4e
Commit
57724c4e
authored
Apr 08, 2013
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup, refactor and document ForeignKeyConstraint asset
parent
226dba89
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
50 deletions
+96
-50
ForeignKeyConstraint.php
lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php
+96
-50
No files found.
lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php
View file @
57724c4e
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
...
...
@@ -21,72 +19,80 @@
namespace
Doctrine\DBAL\Schema
;
use
Doctrine\DBAL\Schema\Visitor\Visitor
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
/**
* An abstraction class for a foreign key constraint.
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @link www.doctrine-project.org
* @since 2.0
*/
class
ForeignKeyConstraint
extends
AbstractAsset
implements
Constraint
{
/**
* @var Table
*/
protected
$_localTable
;
/**
* @var array
* @var Table Instance of the referencing table the foreign key constraint is associated with.
*/
protected
$
_localColumnNames
;
protected
$
localTable
;
/**
* @var
string
* @var
array Names of the referencing table columns the foreign key constraint is associated with.
*/
protected
$
_foreignTableName
;
protected
$
localColumnNames
;
/**
* @var
array
* @var
string Name of the referenced table the foreign key constraint is associated with.
*/
protected
$
_foreignColumnNames
;
protected
$
foreignTableName
;
/**
* @var
string
* @var
array Names of the referenced table columns the foreign key constraint is associated with.
*/
protected
$
_cascade
=
''
;
protected
$
foreignColumnNames
;
/**
* @var array
* @var array
Options associated with the foreign key constraint.
*/
protected
$
_
options
;
protected
$options
;
/**
* Initializes the foreign key constraint.
*
* @param array
$localColumnNames
* @param string
$foreignTableName
* @param array
$foreignColumnNames
* @param string
$cascade
* @param
string|null $name
* @param array
$localColumnNames Names of the referencing table columns.
* @param string
$foreignTableName Name of the referenced table.
* @param array
$foreignColumnNames Names of the referenced table columns.
* @param string
|null $name Name of the foreign key constraint.
* @param
array $options Options associated with the foreign key constraint.
*/
public
function
__construct
(
array
$localColumnNames
,
$foreignTableName
,
array
$foreignColumnNames
,
$name
=
null
,
array
$options
=
array
())
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
=
$localColumnNames
;
$this
->
foreignTableName
=
$foreignTableName
;
$this
->
foreignColumnNames
=
$foreignColumnNames
;
$this
->
options
=
$options
;
}
/**
* Returns the name of the referencing table
* the foreign key constraint is associated with.
*
* @return string
*/
public
function
getLocalTableName
()
{
return
$this
->
_
localTable
->
getName
();
return
$this
->
localTable
->
getName
();
}
/**
* @param Table $table
* Sets the Table instance of the referencing table
* the foreign key constraint is associated with.
*
* @param Table $table Instance of the referencing table.
*/
public
function
setLocalTable
(
Table
$table
)
{
$this
->
_
localTable
=
$table
;
$this
->
localTable
=
$table
;
}
/**
...
...
@@ -98,24 +104,36 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
}
/**
* Returns the names of the referencing table columns
* the foreign key constraint is associated with.
*
* @return array
*/
public
function
getLocalColumns
()
{
return
$this
->
_
localColumnNames
;
return
$this
->
localColumnNames
;
}
/**
* Returns the names of the referencing table columns
* the foreign key constraint is associated with.
*
* @return array
*/
public
function
getColumns
()
{
return
$this
->
_
localColumnNames
;
return
$this
->
localColumnNames
;
}
/**
* Returns the name of the referenced table
* the foreign key constraint is associated with.
*
* @return string
*/
public
function
getForeignTableName
()
{
return
$this
->
_
foreignTableName
;
return
$this
->
foreignTableName
;
}
/**
...
...
@@ -133,14 +151,16 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
* Get the quoted representation of this asset but only if it was defined with one. Otherwise
* return the plain unquoted value as inserted.
*
* @param AbstractPlatform $platform
* @param AbstractPlatform $platform The platform to use for quoting.
*
* @return string
*/
public
function
getQuotedForeignTableName
(
AbstractPlatform
$platform
)
{
$keywords
=
$platform
->
getReservedKeywordsList
();
$parts
=
explode
(
"."
,
$this
->
getForeignTableName
());
foreach
(
$parts
AS
$k
=>
$v
)
{
foreach
(
$parts
as
$k
=>
$v
)
{
$parts
[
$k
]
=
(
$this
->
_quoted
||
$keywords
->
isKeyword
(
$v
))
?
$platform
->
quoteIdentifier
(
$v
)
:
$v
;
}
...
...
@@ -148,65 +168,91 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
}
/**
* Returns the names of the referenced table columns
* the foreign key constraint is associated with.
*
* @return array
*/
public
function
getForeignColumns
()
{
return
$this
->
_
foreignColumnNames
;
return
$this
->
foreignColumnNames
;
}
/**
* Returns whether or not a given option
* is associated with the foreign key constraint.
*
* @param string $name Name of the option to check.
*
* @return boolean
*/
public
function
hasOption
(
$name
)
{
return
isset
(
$this
->
_
options
[
$name
]);
return
isset
(
$this
->
options
[
$name
]);
}
/**
* Returns an option associated with the foreign key constraint.
*
* @param string $name Name of the option the foreign key constraint is associated with.
*
* @return mixed
*/
public
function
getOption
(
$name
)
{
return
$this
->
_
options
[
$name
];
return
$this
->
options
[
$name
];
}
/**
*
Gets the options associated with this constraint
*
Returns the options associated with the foreign key constraint.
*
* @return array
*/
public
function
getOptions
()
{
return
$this
->
_
options
;
return
$this
->
options
;
}
/**
* Foreign Key onUpdate status
* Returns the referential action for UPDATE operations
* on the referenced table the foreign key constraint is associated with.
*
* @return string|null
*/
public
function
onUpdate
()
{
return
$this
->
_
onEvent
(
'onUpdate'
);
return
$this
->
onEvent
(
'onUpdate'
);
}
/**
* Foreign Key onDelete status
* Returns the referential action for DELETE operations
* on the referenced table the foreign key constraint is associated with.
*
* @return string|null
*/
public
function
onDelete
()
{
return
$this
->
_
onEvent
(
'onDelete'
);
return
$this
->
onEvent
(
'onDelete'
);
}
/**
* @param string $event
* Returns the referential action for a given database operation
* on the referenced table the foreign key constraint is associated with.
*
* @param string $event Name of the database operation/event to return the referential action for.
*
* @return string|null
*/
private
function
_
onEvent
(
$event
)
private
function
onEvent
(
$event
)
{
if
(
isset
(
$this
->
_options
[
$event
]))
{
$onEvent
=
strtoupper
(
$this
->
_options
[
$event
]);
if
(
!
in_array
(
$onEvent
,
array
(
'NO ACTION'
,
'RESTRICT'
)))
{
if
(
isset
(
$this
->
options
[
$event
]))
{
$onEvent
=
strtoupper
(
$this
->
options
[
$event
]);
if
(
!
in_array
(
$onEvent
,
array
(
'NO ACTION'
,
'RESTRICT'
)))
{
return
$onEvent
;
}
}
return
false
;
}
}
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