Refs #175, Removed $collections instance variable from Doctrine_Record
This commit is contained in:
parent
1c8cf0271e
commit
c1280d31dc
@ -27,10 +27,21 @@
|
||||
* @license LGPL
|
||||
*/
|
||||
class Doctrine_Query extends Doctrine_Hydrate implements Countable {
|
||||
/**
|
||||
* QUERY TYPE CONSTANTS
|
||||
*/
|
||||
|
||||
/**
|
||||
* constant for SELECT queries
|
||||
*/
|
||||
const SELECT = 0;
|
||||
|
||||
/**
|
||||
* constant for DELETE queries
|
||||
*/
|
||||
const DELETE = 1;
|
||||
|
||||
/**
|
||||
* constant for UPDATE queries
|
||||
*/
|
||||
const UPDATE = 2;
|
||||
/**
|
||||
* @param array $subqueryAliases the table aliases needed in some LIMIT subqueries
|
||||
@ -52,7 +63,11 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
|
||||
private $isDistinct = false;
|
||||
|
||||
private $pendingFields = array();
|
||||
|
||||
/**
|
||||
* @var integer $type the query type
|
||||
*
|
||||
* @see Doctrine_Query::* constants
|
||||
*/
|
||||
protected $type = self::SELECT;
|
||||
|
||||
/**
|
||||
@ -297,7 +312,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
|
||||
break;
|
||||
case 'update':
|
||||
$this->type = self::UPDATE;
|
||||
break;
|
||||
$name = 'from';
|
||||
case 'from':
|
||||
$this->parts['from'] = array();
|
||||
$this->parts['select'] = array();
|
||||
@ -359,6 +374,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
|
||||
* @return boolean
|
||||
*/
|
||||
public function set($name, $value) {
|
||||
/**
|
||||
|
||||
if(isset($this->parts[$name])) {
|
||||
$method = "parse".ucwords($name);
|
||||
@ -390,6 +406,9 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
*/
|
||||
$class = new Doctrine_Query_Set($this);
|
||||
$class->parse($name, $value);
|
||||
}
|
||||
/**
|
||||
* @return boolean
|
||||
@ -451,8 +470,10 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
|
||||
$q .= implode(", ",$a);
|
||||
|
||||
if($needsSubQuery)
|
||||
$subquery = 'SELECT DISTINCT '.$table->getTableName().".".$table->getIdentifier().
|
||||
' FROM '.$table->getTableName();
|
||||
$subquery = 'SELECT DISTINCT ' . $table->getTableName()
|
||||
. '.' . $table->getIdentifier()
|
||||
. ' FROM '.$table->getTableName();
|
||||
|
||||
|
||||
if( ! empty($this->parts['join'])) {
|
||||
foreach($this->parts['join'] as $part) {
|
||||
@ -570,7 +591,9 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
|
||||
$part = trim($part);
|
||||
switch(strtolower($part)) {
|
||||
case 'delete':
|
||||
case 'update':
|
||||
case 'select':
|
||||
case 'set':
|
||||
case 'from':
|
||||
case 'where':
|
||||
case 'limit':
|
||||
@ -604,15 +627,18 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
|
||||
case 'DELETE':
|
||||
$this->type = self::DELETE;
|
||||
break;
|
||||
case 'UPDATE':
|
||||
$this->type = self::UPDATE;
|
||||
break;
|
||||
|
||||
case 'SELECT':
|
||||
$this->type = self::SELECT;
|
||||
$this->parseSelect($part);
|
||||
break;
|
||||
case 'UPDATE':
|
||||
$this->type = self::UPDATE;
|
||||
$k = 'FROM';
|
||||
|
||||
case 'FROM':
|
||||
$class = "Doctrine_Query_".ucwords(strtolower($k));
|
||||
case 'SET':
|
||||
$class = 'Doctrine_Query_'.ucwords(strtolower($k));
|
||||
$parser = new $class($this);
|
||||
$parser->parse($part);
|
||||
break;
|
||||
|
@ -1,6 +1,31 @@
|
||||
<?php
|
||||
require_once("Part.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::autoload('Doctrine_Query_Part');
|
||||
/**
|
||||
* Doctrine_Query_Orderby
|
||||
*
|
||||
* @package Doctrine ORM
|
||||
* @url www.phpdoctrine.com
|
||||
* @license LGPL
|
||||
*/
|
||||
class Doctrine_Query_Orderby extends Doctrine_Query_Part {
|
||||
/**
|
||||
* DQL ORDER BY PARSER
|
||||
@ -9,17 +34,17 @@ class Doctrine_Query_Orderby extends Doctrine_Query_Part {
|
||||
* @param string $str
|
||||
* @return void
|
||||
*/
|
||||
final public function parse($str) {
|
||||
public function parse($str) {
|
||||
$ret = array();
|
||||
|
||||
foreach(explode(",",trim($str)) as $r) {
|
||||
foreach(explode(',', trim($str)) as $r) {
|
||||
$r = trim($r);
|
||||
$e = explode(" ",$r);
|
||||
$a = explode(".",$e[0]);
|
||||
$e = explode(' ', $r);
|
||||
$a = explode('.', $e[0]);
|
||||
|
||||
if(count($a) > 1) {
|
||||
$field = array_pop($a);
|
||||
$reference = implode(".",$a);
|
||||
$reference = implode('.', $a);
|
||||
$name = end($a);
|
||||
|
||||
|
||||
@ -29,18 +54,18 @@ class Doctrine_Query_Orderby extends Doctrine_Query_Part {
|
||||
|
||||
$tname = $this->query->getTable($alias)->getTableName();
|
||||
|
||||
$r = $alias.".".$field;
|
||||
$r = $alias . '.' . $field;
|
||||
|
||||
if(isset($e[1]))
|
||||
$r .= " ".$e[1];
|
||||
$r .= ' '.$e[1];
|
||||
}
|
||||
$ret[] = $r;
|
||||
}
|
||||
|
||||
return implode(", ", $ret);
|
||||
return implode(', ', $ret);
|
||||
}
|
||||
public function __toString() {
|
||||
return ( ! empty($this->parts))?implode(", ", $this->parts):'';
|
||||
return ( ! empty($this->parts))?implode(', ', $this->parts):'';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,23 +1,59 @@
|
||||
<?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::autoload("Doctrine_Access");
|
||||
|
||||
/**
|
||||
* Doctrine_Query_Part
|
||||
*
|
||||
* @package Doctrine ORM
|
||||
* @url www.phpdoctrine.com
|
||||
* @license LGPL
|
||||
*/
|
||||
abstract class Doctrine_Query_Part extends Doctrine_Access {
|
||||
|
||||
/**
|
||||
* @var Doctrine_Query $query the query object associated with this parser
|
||||
*/
|
||||
protected $query;
|
||||
|
||||
/**
|
||||
* @var string $name the name of this parser
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @var array $parts
|
||||
*/
|
||||
protected $parts = array();
|
||||
|
||||
/**
|
||||
* @param Doctrine_Query $query the query object associated with this parser
|
||||
*/
|
||||
public function __construct(Doctrine_Query $query) {
|
||||
$this->query = $query;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string $name the name of this parser
|
||||
*/
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Doctrine_Query $query the query object associated with this parser
|
||||
*/
|
||||
public function getQuery() {
|
||||
return $this->query;
|
||||
}
|
||||
|
34
lib/Doctrine/Query/Set.php
Normal file
34
lib/Doctrine/Query/Set.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?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_Query
|
||||
*
|
||||
* @package Doctrine ORM
|
||||
* @url www.phpdoctrine.com
|
||||
* @license LGPL
|
||||
*/
|
||||
class Doctrine_Query_Set extends Doctrine_Query_Part {
|
||||
public function parse($dql) {
|
||||
$e = Doctrine_Query::sqlExplode($dql, '=');
|
||||
}
|
||||
}
|
||||
?>
|
@ -95,10 +95,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
* @var Doctrine_Validator_ErrorStack error stack object
|
||||
*/
|
||||
protected $_errorStack;
|
||||
/**
|
||||
* @var array $collections the collections this record is in
|
||||
*/
|
||||
private $collections = array();
|
||||
/**
|
||||
* @var array $references an array containing all the references
|
||||
*/
|
||||
@ -494,38 +490,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
$this->_table->getAttribute(Doctrine::ATTR_LISTENER)->onWakeUp($this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* addCollection
|
||||
*
|
||||
* @param Doctrine_Collection $collection
|
||||
* @param mixed $key
|
||||
*/
|
||||
final public function addCollection(Doctrine_Collection $collection,$key = null) {
|
||||
if($key !== null) {
|
||||
$this->collections[$key] = $collection;
|
||||
} else {
|
||||
$this->collections[] = $collection;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* getCollection
|
||||
* @param integer $key
|
||||
* @return Doctrine_Collection
|
||||
*/
|
||||
final public function getCollection($key) {
|
||||
return $this->collections[$key];
|
||||
}
|
||||
/**
|
||||
* hasCollections
|
||||
* whether or not this record is part of a collection
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
final public function hasCollections() {
|
||||
return (! empty($this->collections));
|
||||
}
|
||||
/**
|
||||
* getState
|
||||
* returns the current state of the object
|
||||
@ -646,16 +610,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
public function load() {
|
||||
// only load the data from database if the Doctrine_Record is in proxy state
|
||||
if($this->_state == Doctrine_Record::STATE_PROXY) {
|
||||
if( ! empty($this->collections)) {
|
||||
// delegate the loading operation to collections in which this record resides
|
||||
foreach($this->collections as $collection) {
|
||||
$collection->load($this);
|
||||
$this->refresh();
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
$this->refresh();
|
||||
}
|
||||
$this->_state = Doctrine_Record::STATE_CLEAN;
|
||||
|
||||
return true;
|
||||
@ -680,9 +636,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
if(isset($this->_data[$lower])) {
|
||||
|
||||
// check if the property is null (= it is the Doctrine_Null object located in self::$null)
|
||||
if($this->_data[$lower] === self::$null) {
|
||||
if($this->_data[$lower] === self::$null)
|
||||
$this->load();
|
||||
}
|
||||
|
||||
|
||||
if($this->_data[$lower] === self::$null)
|
||||
$value = null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user