This commit is contained in:
parent
de3242227b
commit
7c2dc1a978
@ -38,15 +38,15 @@ class Doctrine_Relation_Parser
|
||||
/**
|
||||
* @var array $_relations an array containing all the Doctrine_Relation objects for this table
|
||||
*/
|
||||
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
|
||||
*
|
||||
@ -63,9 +63,21 @@ class Doctrine_Relation_Parser
|
||||
*/
|
||||
public function getTable()
|
||||
{
|
||||
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
|
||||
*
|
||||
@ -73,7 +85,7 @@ class Doctrine_Relation_Parser
|
||||
* @param string $field
|
||||
* @return void
|
||||
*/
|
||||
public function bind($name, $field, $type, $options = null)
|
||||
public function bind($name, $options = array())
|
||||
{
|
||||
if (isset($this->relations[$name])) {
|
||||
unset($this->relations[$name]);
|
||||
@ -81,8 +93,8 @@ class Doctrine_Relation_Parser
|
||||
|
||||
$lower = strtolower($name);
|
||||
|
||||
if (isset($this->columns[$lower])) {
|
||||
throw new Doctrine_Table_Exception("Couldn't bind relation. Column with name " . $lower . ' already exists!');
|
||||
if ($this->_table->hasColumn($lower)) {
|
||||
throw new Doctrine_Relation_Exception("Couldn't bind relation. Column with name " . $lower . ' already exists!');
|
||||
}
|
||||
|
||||
$e = explode(' as ', $name);
|
||||
@ -90,25 +102,12 @@ class Doctrine_Relation_Parser
|
||||
|
||||
if (isset($e[1])) {
|
||||
$alias = $e[1];
|
||||
$this->boundAliases[$name] = $alias;
|
||||
$this->_aliases[$name] = $alias;
|
||||
} else {
|
||||
$alias = $name;
|
||||
}
|
||||
|
||||
$this->bound[$alias] = array('field' => $field,
|
||||
'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);
|
||||
}
|
||||
$this->_pending[$alias] = array_merge($options, array('class' => $name, 'alias' => $alias));
|
||||
}
|
||||
/**
|
||||
* getRelation
|
||||
|
50
tests/Relation/ParserTestCase.php
Normal file
50
tests/Relation/ParserTestCase.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?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'
|
||||
));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user