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
7c2dc1a9
Commit
7c2dc1a9
authored
May 20, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
de324222
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
25 deletions
+74
-25
Parser.php
lib/Doctrine/Relation/Parser.php
+24
-25
ParserTestCase.php
tests/Relation/ParserTestCase.php
+50
-0
No files found.
lib/Doctrine/Relation/Parser.php
View file @
7c2dc1a9
...
@@ -40,13 +40,13 @@ class Doctrine_Relation_Parser
...
@@ -40,13 +40,13 @@ class Doctrine_Relation_Parser
*/
*/
protected
$_relations
=
array
();
protected
$_relations
=
array
();
/**
/**
* @var array $_
bound bound relations
* @var array $_
pending relations waiting for parsing
*/
*/
protected
$_
bound
=
array
();
protected
$_
pending
=
array
();
/**
/**
* @var array $_
boundAliases bound
relation aliases
* @var array $_
relationAliases
relation aliases
*/
*/
protected
$_
boundAliases
=
array
();
protected
$_
aliases
=
array
();
/**
/**
* constructor
* constructor
*
*
...
@@ -65,7 +65,19 @@ class Doctrine_Relation_Parser
...
@@ -65,7 +65,19 @@ class Doctrine_Relation_Parser
{
{
return
$this
->
_table
;
return
$this
->
_table
;
}
}
/**
* getPendingRelation
*
* @return array an array defining a pending relation
*/
public
function
getPendingRelation
(
$name
)
{
if
(
!
isset
(
$this
->
_pending
[
$name
]))
{
throw
new
Doctrine_Relation_Exception
(
'Unknown pending relation '
.
$name
);
}
return
$this
->
_pending
[
$name
];
}
/**
/**
* binds a relation
* binds a relation
*
*
...
@@ -73,7 +85,7 @@ class Doctrine_Relation_Parser
...
@@ -73,7 +85,7 @@ class Doctrine_Relation_Parser
* @param string $field
* @param string $field
* @return void
* @return void
*/
*/
public
function
bind
(
$name
,
$
field
,
$type
,
$options
=
null
)
public
function
bind
(
$name
,
$
options
=
array
()
)
{
{
if
(
isset
(
$this
->
relations
[
$name
]))
{
if
(
isset
(
$this
->
relations
[
$name
]))
{
unset
(
$this
->
relations
[
$name
]);
unset
(
$this
->
relations
[
$name
]);
...
@@ -81,8 +93,8 @@ class Doctrine_Relation_Parser
...
@@ -81,8 +93,8 @@ class Doctrine_Relation_Parser
$lower
=
strtolower
(
$name
);
$lower
=
strtolower
(
$name
);
if
(
isset
(
$this
->
columns
[
$lower
]
))
{
if
(
$this
->
_table
->
hasColumn
(
$lower
))
{
throw
new
Doctrine_
Table
_Exception
(
"Couldn't bind relation. Column with name "
.
$lower
.
' already exists!'
);
throw
new
Doctrine_
Relation
_Exception
(
"Couldn't bind relation. Column with name "
.
$lower
.
' already exists!'
);
}
}
$e
=
explode
(
' as '
,
$name
);
$e
=
explode
(
' as '
,
$name
);
...
@@ -90,25 +102,12 @@ class Doctrine_Relation_Parser
...
@@ -90,25 +102,12 @@ class Doctrine_Relation_Parser
if
(
isset
(
$e
[
1
]))
{
if
(
isset
(
$e
[
1
]))
{
$alias
=
$e
[
1
];
$alias
=
$e
[
1
];
$this
->
boundA
liases
[
$name
]
=
$alias
;
$this
->
_a
liases
[
$name
]
=
$alias
;
}
else
{
}
else
{
$alias
=
$name
;
$alias
=
$name
;
}
}
$this
->
bound
[
$alias
]
=
array
(
'field'
=>
$field
,
$this
->
_pending
[
$alias
]
=
array_merge
(
$options
,
array
(
'class'
=>
$name
,
'alias'
=>
$alias
));
'type'
=>
$type
,
'class'
=>
$name
,
'alias'
=>
$alias
);
if
(
$options
!==
null
)
{
$opt
=
array
();
if
(
is_string
(
$options
))
{
$opt
[
'local'
]
=
$options
;
}
else
{
$opt
=
(
array
)
$options
;
}
$this
->
bound
[
$alias
]
=
array_merge
(
$this
->
bound
[
$alias
],
$opt
);
}
}
}
/**
/**
* getRelation
* getRelation
...
...
tests/Relation/ParserTestCase.php
0 → 100644
View file @
7c2dc1a9
<?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
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Relation_Parser_TestCase
*
* @package Doctrine
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class
Doctrine_Relation_Parser_TestCase
extends
Doctrine_UnitTestCase
{
public
function
testPendingRelations
()
{
$r
=
new
Doctrine_Relation_Parser
(
$this
->
conn
->
getTable
(
'User'
));
$p
=
array
(
'type'
=>
Doctrine_Relation
::
ONE
,
'local'
=>
'email_id'
);
$r
->
bind
(
'Email'
,
$p
);
$this
->
assertEqual
(
$r
->
getPendingRelation
(
'Email'
),
array
(
'type'
=>
Doctrine_Relation
::
ONE
,
'local'
=>
'email_id'
,
'class'
=>
'Email'
,
'alias'
=>
'Email'
));
}
}
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