Introduced constants: Doctrine::ATTR_AUTO_LENGTH_VLD and Doctrine::ATTR_AUTO_TYPE_VLD.
Both default to TRUE. If set to false, you need to explicitly specify "length" and/or "type" in the parameter of hasColumn that specifies the validators for that column.
This commit is contained in:
parent
05cf2cd1b6
commit
4433e6ff40
@ -149,6 +149,14 @@ final class Doctrine {
|
|||||||
* accessor invoking attribute
|
* accessor invoking attribute
|
||||||
*/
|
*/
|
||||||
const ATTR_ACCESSORS = 18;
|
const ATTR_ACCESSORS = 18;
|
||||||
|
/**
|
||||||
|
* automatic length validations attribute
|
||||||
|
*/
|
||||||
|
const ATTR_AUTO_LENGTH_VLD = 19;
|
||||||
|
/**
|
||||||
|
* automatic type validations attribute
|
||||||
|
*/
|
||||||
|
const ATTR_AUTO_TYPE_VLD = 20;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,231 +1,233 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* $Id$
|
* $Id$
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* This software consists of voluntary contributions made by many individuals
|
* This software consists of voluntary contributions made by many individuals
|
||||||
* and is licensed under the LGPL. For more information, see
|
* and is licensed under the LGPL. For more information, see
|
||||||
* <http://www.phpdoctrine.com>.
|
* <http://www.phpdoctrine.com>.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* Doctrine_Configurable
|
* Doctrine_Configurable
|
||||||
* the base for Doctrine_Table, Doctrine_Manager and Doctrine_Connection
|
* the base for Doctrine_Table, Doctrine_Manager and Doctrine_Connection
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @package Doctrine ORM
|
* @package Doctrine ORM
|
||||||
* @url www.phpdoctrine.com
|
* @url www.phpdoctrine.com
|
||||||
* @license LGPL
|
* @license LGPL
|
||||||
*/
|
*/
|
||||||
abstract class Doctrine_Configurable {
|
abstract class Doctrine_Configurable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array $attributes an array of containing all attributes
|
* @var array $attributes an array of containing all attributes
|
||||||
*/
|
*/
|
||||||
private $attributes = array();
|
private $attributes = array();
|
||||||
/**
|
/**
|
||||||
* @var $parent the parents of this component
|
* @var $parent the parents of this component
|
||||||
*/
|
*/
|
||||||
private $parent;
|
private $parent;
|
||||||
/**
|
/**
|
||||||
* sets a given attribute
|
* sets a given attribute
|
||||||
*
|
*
|
||||||
* @throws Doctrine_Exception if the value is invalid
|
* @throws Doctrine_Exception if the value is invalid
|
||||||
* @param integer $attribute
|
* @param integer $attribute
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setAttribute($attribute,$value) {
|
public function setAttribute($attribute,$value) {
|
||||||
switch($attribute):
|
switch($attribute):
|
||||||
case Doctrine::ATTR_BATCH_SIZE:
|
case Doctrine::ATTR_BATCH_SIZE:
|
||||||
if($value < 0)
|
if($value < 0)
|
||||||
throw new Doctrine_Exception("Batch size should be greater than or equal to zero");
|
throw new Doctrine_Exception("Batch size should be greater than or equal to zero");
|
||||||
break;
|
break;
|
||||||
case Doctrine::ATTR_CACHE_DIR:
|
case Doctrine::ATTR_CACHE_DIR:
|
||||||
if(substr(trim($value),0,6) == "%ROOT%") {
|
if(substr(trim($value),0,6) == "%ROOT%") {
|
||||||
$dir = dirname(__FILE__);
|
$dir = dirname(__FILE__);
|
||||||
$value = $dir.substr($value,6);
|
$value = $dir.substr($value,6);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Doctrine::ATTR_CACHE_TTL:
|
case Doctrine::ATTR_CACHE_TTL:
|
||||||
if($value < 1)
|
if($value < 1)
|
||||||
throw new Doctrine_Exception("Cache TimeToLive should be greater than or equal to 1");
|
throw new Doctrine_Exception("Cache TimeToLive should be greater than or equal to 1");
|
||||||
break;
|
break;
|
||||||
case Doctrine::ATTR_CACHE_SIZE:
|
case Doctrine::ATTR_CACHE_SIZE:
|
||||||
if($value < 1)
|
if($value < 1)
|
||||||
throw new Doctrine_Exception("Cache size should be greater than or equal to 1");
|
throw new Doctrine_Exception("Cache size should be greater than or equal to 1");
|
||||||
break;
|
break;
|
||||||
case Doctrine::ATTR_CACHE_SLAM:
|
case Doctrine::ATTR_CACHE_SLAM:
|
||||||
if($value < 0 || $value > 1)
|
if($value < 0 || $value > 1)
|
||||||
throw new Doctrine_Exception("Cache slam defense should be a floating point number between 0 and 1");
|
throw new Doctrine_Exception("Cache slam defense should be a floating point number between 0 and 1");
|
||||||
break;
|
break;
|
||||||
case Doctrine::ATTR_FETCHMODE:
|
case Doctrine::ATTR_FETCHMODE:
|
||||||
if($value < 0)
|
if($value < 0)
|
||||||
throw new Doctrine_Exception("Unknown fetchmode. See Doctrine::FETCH_* constants.");
|
throw new Doctrine_Exception("Unknown fetchmode. See Doctrine::FETCH_* constants.");
|
||||||
break;
|
break;
|
||||||
case Doctrine::ATTR_LISTENER:
|
case Doctrine::ATTR_LISTENER:
|
||||||
$this->setEventListener($value);
|
$this->setEventListener($value);
|
||||||
break;
|
break;
|
||||||
case Doctrine::ATTR_LOCKMODE:
|
case Doctrine::ATTR_LOCKMODE:
|
||||||
if($this instanceof Doctrine_Connection) {
|
if($this instanceof Doctrine_Connection) {
|
||||||
if($this->getTransaction()->getState() != Doctrine_Connection_Transaction::STATE_OPEN)
|
if($this->getTransaction()->getState() != Doctrine_Connection_Transaction::STATE_OPEN)
|
||||||
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
|
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
|
||||||
|
|
||||||
} elseif($this instanceof Doctrine_Manager) {
|
} elseif($this instanceof Doctrine_Manager) {
|
||||||
foreach($this as $connection) {
|
foreach($this as $connection) {
|
||||||
if($connection->getTransaction()->getState() != Doctrine_Connection_Transaction::STATE_OPEN)
|
if($connection->getTransaction()->getState() != Doctrine_Connection_Transaction::STATE_OPEN)
|
||||||
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
|
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Doctrine_Exception("Lockmode attribute can only be set at the global or connection level.");
|
throw new Doctrine_Exception("Lockmode attribute can only be set at the global or connection level.");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Doctrine::ATTR_CREATE_TABLES:
|
case Doctrine::ATTR_CREATE_TABLES:
|
||||||
$value = (bool) $value;
|
$value = (bool) $value;
|
||||||
break;
|
break;
|
||||||
case Doctrine::ATTR_ACCESSORS:
|
case Doctrine::ATTR_ACCESSORS:
|
||||||
$accessors = array('none','get','set','both');
|
$accessors = array('none','get','set','both');
|
||||||
|
|
||||||
// if( ! in_array($value,$accessors))
|
// if( ! in_array($value,$accessors))
|
||||||
// throw new Doctrine_Exception();
|
// throw new Doctrine_Exception();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Doctrine::ATTR_COLL_LIMIT:
|
case Doctrine::ATTR_COLL_LIMIT:
|
||||||
if($value < 1) {
|
if($value < 1) {
|
||||||
throw new Doctrine_Exception("Collection limit should be a value greater than or equal to 1.");
|
throw new Doctrine_Exception("Collection limit should be a value greater than or equal to 1.");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Doctrine::ATTR_COLL_KEY:
|
case Doctrine::ATTR_COLL_KEY:
|
||||||
if( ! ($this instanceof Doctrine_Table))
|
if( ! ($this instanceof Doctrine_Table))
|
||||||
throw new Doctrine_Exception("This attribute can only be set at table level.");
|
throw new Doctrine_Exception("This attribute can only be set at table level.");
|
||||||
|
|
||||||
if( ! $this->hasColumn($value))
|
if( ! $this->hasColumn($value))
|
||||||
throw new Doctrine_Exception("Couldn't set collection key attribute. No such column '$value'");
|
throw new Doctrine_Exception("Couldn't set collection key attribute. No such column '$value'");
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Doctrine::ATTR_VLD:
|
case Doctrine::ATTR_VLD:
|
||||||
case Doctrine::ATTR_QUERY_LIMIT:
|
case Doctrine::ATTR_AUTO_LENGTH_VLD:
|
||||||
|
case Doctrine::ATTR_AUTO_TYPE_VLD:
|
||||||
break;
|
case Doctrine::ATTR_QUERY_LIMIT:
|
||||||
case Doctrine::ATTR_CACHE:
|
|
||||||
if($value != Doctrine::CACHE_SQLITE && $value != Doctrine::CACHE_NONE)
|
break;
|
||||||
throw new Doctrine_Exception("Unknown cache container. See Doctrine::CACHE_* constants for availible containers.");
|
case Doctrine::ATTR_CACHE:
|
||||||
break;
|
if($value != Doctrine::CACHE_SQLITE && $value != Doctrine::CACHE_NONE)
|
||||||
default:
|
throw new Doctrine_Exception("Unknown cache container. See Doctrine::CACHE_* constants for availible containers.");
|
||||||
throw new Doctrine_Exception("Unknown attribute.");
|
break;
|
||||||
endswitch;
|
default:
|
||||||
|
throw new Doctrine_Exception("Unknown attribute.");
|
||||||
$this->attributes[$attribute] = $value;
|
endswitch;
|
||||||
|
|
||||||
}
|
$this->attributes[$attribute] = $value;
|
||||||
/**
|
|
||||||
* @param Doctrine_EventListener $listener
|
}
|
||||||
* @return void
|
/**
|
||||||
*/
|
* @param Doctrine_EventListener $listener
|
||||||
public function setEventListener($listener) {
|
* @return void
|
||||||
return $this->setListener($listener);
|
*/
|
||||||
}
|
public function setEventListener($listener) {
|
||||||
/**
|
return $this->setListener($listener);
|
||||||
* addListener
|
}
|
||||||
*
|
/**
|
||||||
* @param Doctrine_DB_EventListener_Interface|Doctrine_Overloadable $listener
|
* addListener
|
||||||
* @return Doctrine_DB
|
*
|
||||||
*/
|
* @param Doctrine_DB_EventListener_Interface|Doctrine_Overloadable $listener
|
||||||
public function addListener($listener, $name = null) {
|
* @return Doctrine_DB
|
||||||
if( ! ($this->attributes[Doctrine::ATTR_LISTENER] instanceof Doctrine_EventListener_Chain))
|
*/
|
||||||
$this->attributes[Doctrine::ATTR_LISTENER] = new Doctrine_EventListener_Chain();
|
public function addListener($listener, $name = null) {
|
||||||
|
if( ! ($this->attributes[Doctrine::ATTR_LISTENER] instanceof Doctrine_EventListener_Chain))
|
||||||
$this->attributes[Doctrine::ATTR_LISTENER]->add($listener, $name);
|
$this->attributes[Doctrine::ATTR_LISTENER] = new Doctrine_EventListener_Chain();
|
||||||
|
|
||||||
return $this;
|
$this->attributes[Doctrine::ATTR_LISTENER]->add($listener, $name);
|
||||||
}
|
|
||||||
/**
|
return $this;
|
||||||
* getListener
|
}
|
||||||
*
|
/**
|
||||||
* @return Doctrine_DB_EventListener_Interface|Doctrine_Overloadable
|
* getListener
|
||||||
*/
|
*
|
||||||
public function getListener() {
|
* @return Doctrine_DB_EventListener_Interface|Doctrine_Overloadable
|
||||||
if( ! isset($this->attributes[Doctrine::ATTR_LISTENER])) {
|
*/
|
||||||
if(isset($this->parent))
|
public function getListener() {
|
||||||
return $this->parent->getListener();
|
if( ! isset($this->attributes[Doctrine::ATTR_LISTENER])) {
|
||||||
|
if(isset($this->parent))
|
||||||
return null;
|
return $this->parent->getListener();
|
||||||
}
|
|
||||||
return $this->attributes[Doctrine::ATTR_LISTENER];
|
return null;
|
||||||
}
|
}
|
||||||
/**
|
return $this->attributes[Doctrine::ATTR_LISTENER];
|
||||||
* setListener
|
}
|
||||||
*
|
/**
|
||||||
* @param Doctrine_DB_EventListener_Interface|Doctrine_Overloadable $listener
|
* setListener
|
||||||
* @return Doctrine_DB
|
*
|
||||||
*/
|
* @param Doctrine_DB_EventListener_Interface|Doctrine_Overloadable $listener
|
||||||
public function setListener($listener) {
|
* @return Doctrine_DB
|
||||||
if( ! ($listener instanceof Doctrine_EventListener_Interface) &&
|
*/
|
||||||
! ($listener instanceof Doctrine_Overloadable))
|
public function setListener($listener) {
|
||||||
throw new Doctrine_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_EventListener_Interface or Doctrine_Overloadable");
|
if( ! ($listener instanceof Doctrine_EventListener_Interface) &&
|
||||||
|
! ($listener instanceof Doctrine_Overloadable))
|
||||||
$this->attributes[Doctrine::ATTR_LISTENER] = $listener;
|
throw new Doctrine_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_EventListener_Interface or Doctrine_Overloadable");
|
||||||
|
|
||||||
return $this;
|
$this->attributes[Doctrine::ATTR_LISTENER] = $listener;
|
||||||
}
|
|
||||||
/**
|
return $this;
|
||||||
* returns the value of an attribute
|
}
|
||||||
*
|
/**
|
||||||
* @param integer $attribute
|
* returns the value of an attribute
|
||||||
* @return mixed
|
*
|
||||||
*/
|
* @param integer $attribute
|
||||||
public function getAttribute($attribute) {
|
* @return mixed
|
||||||
$attribute = (int) $attribute;
|
*/
|
||||||
|
public function getAttribute($attribute) {
|
||||||
if($attribute < 1 || $attribute > 18)
|
$attribute = (int) $attribute;
|
||||||
throw new InvalidKeyException();
|
|
||||||
|
if($attribute < 1 || $attribute > 20)
|
||||||
if( ! isset($this->attributes[$attribute])) {
|
throw new InvalidKeyException();
|
||||||
if(isset($this->parent))
|
|
||||||
return $this->parent->getAttribute($attribute);
|
if( ! isset($this->attributes[$attribute])) {
|
||||||
|
if(isset($this->parent))
|
||||||
return null;
|
return $this->parent->getAttribute($attribute);
|
||||||
}
|
|
||||||
return $this->attributes[$attribute];
|
return null;
|
||||||
}
|
}
|
||||||
/**
|
return $this->attributes[$attribute];
|
||||||
* getAttributes
|
}
|
||||||
* returns all attributes as an array
|
/**
|
||||||
*
|
* getAttributes
|
||||||
* @return array
|
* returns all attributes as an array
|
||||||
*/
|
*
|
||||||
public function getAttributes() {
|
* @return array
|
||||||
return $this->attributes;
|
*/
|
||||||
}
|
public function getAttributes() {
|
||||||
/**
|
return $this->attributes;
|
||||||
* sets a parent for this configurable component
|
}
|
||||||
* the parent must be configurable component itself
|
/**
|
||||||
*
|
* sets a parent for this configurable component
|
||||||
* @param Doctrine_Configurable $component
|
* the parent must be configurable component itself
|
||||||
* @return void
|
*
|
||||||
*/
|
* @param Doctrine_Configurable $component
|
||||||
public function setParent(Doctrine_Configurable $component) {
|
* @return void
|
||||||
$this->parent = $component;
|
*/
|
||||||
}
|
public function setParent(Doctrine_Configurable $component) {
|
||||||
/**
|
$this->parent = $component;
|
||||||
* getParent
|
}
|
||||||
* returns the parent of this component
|
/**
|
||||||
*
|
* getParent
|
||||||
* @return Doctrine_Configurable
|
* returns the parent of this component
|
||||||
*/
|
*
|
||||||
public function getParent() {
|
* @return Doctrine_Configurable
|
||||||
return $this->parent;
|
*/
|
||||||
}
|
public function getParent() {
|
||||||
}
|
return $this->parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,297 +1,299 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* $Id$
|
* $Id$
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* This software consists of voluntary contributions made by many individuals
|
* This software consists of voluntary contributions made by many individuals
|
||||||
* and is licensed under the LGPL. For more information, see
|
* and is licensed under the LGPL. For more information, see
|
||||||
* <http://www.phpdoctrine.com>.
|
* <http://www.phpdoctrine.com>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package Doctrine ORM
|
* @package Doctrine ORM
|
||||||
* @url www.phpdoctrine.com
|
* @url www.phpdoctrine.com
|
||||||
* @license LGPL
|
* @license LGPL
|
||||||
*
|
*
|
||||||
* Doctrine_Manager is the base component of all doctrine based projects.
|
* Doctrine_Manager is the base component of all doctrine based projects.
|
||||||
* It opens and keeps track of all connections (database connections).
|
* It opens and keeps track of all connections (database connections).
|
||||||
*/
|
*/
|
||||||
class Doctrine_Manager extends Doctrine_Configurable implements Countable, IteratorAggregate {
|
class Doctrine_Manager extends Doctrine_Configurable implements Countable, IteratorAggregate {
|
||||||
/**
|
/**
|
||||||
* @var array $connections an array containing all the opened connections
|
* @var array $connections an array containing all the opened connections
|
||||||
*/
|
*/
|
||||||
private $connections = array();
|
private $connections = array();
|
||||||
/**
|
/**
|
||||||
* @var array $dataSourceNames an array containing all available data source names
|
* @var array $dataSourceNames an array containing all available data source names
|
||||||
*/
|
*/
|
||||||
private $dataSourceNames = array();
|
private $dataSourceNames = array();
|
||||||
/**
|
/**
|
||||||
* @var integer $index the incremented index
|
* @var integer $index the incremented index
|
||||||
*/
|
*/
|
||||||
private $index = 0;
|
private $index = 0;
|
||||||
/**
|
/**
|
||||||
* @var integer $currIndex the current connection index
|
* @var integer $currIndex the current connection index
|
||||||
*/
|
*/
|
||||||
private $currIndex = 0;
|
private $currIndex = 0;
|
||||||
/**
|
/**
|
||||||
* @var string $root root directory
|
* @var string $root root directory
|
||||||
*/
|
*/
|
||||||
private $root;
|
private $root;
|
||||||
/**
|
/**
|
||||||
* @var Doctrine_Null $null Doctrine_Null object, used for extremely fast null value checking
|
* @var Doctrine_Null $null Doctrine_Null object, used for extremely fast null value checking
|
||||||
*/
|
*/
|
||||||
private $null;
|
private $null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
*
|
*
|
||||||
* this is private constructor (use getInstance to get an instance of this class)
|
* this is private constructor (use getInstance to get an instance of this class)
|
||||||
*/
|
*/
|
||||||
private function __construct() {
|
private function __construct() {
|
||||||
$this->root = dirname(__FILE__);
|
$this->root = dirname(__FILE__);
|
||||||
$this->null = new Doctrine_Null;
|
$this->null = new Doctrine_Null;
|
||||||
|
|
||||||
Doctrine_Record::initNullObject($this->null);
|
Doctrine_Record::initNullObject($this->null);
|
||||||
Doctrine_Collection::initNullObject($this->null);
|
Doctrine_Collection::initNullObject($this->null);
|
||||||
Doctrine_Record_Iterator::initNullObject($this->null);
|
Doctrine_Record_Iterator::initNullObject($this->null);
|
||||||
Doctrine_Validator::initNullObject($this->null);
|
Doctrine_Validator::initNullObject($this->null);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @return Doctrine_Null
|
* @return Doctrine_Null
|
||||||
*/
|
*/
|
||||||
final public function getNullObject() {
|
final public function getNullObject() {
|
||||||
return $this->null;
|
return $this->null;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* setDefaultAttributes
|
* setDefaultAttributes
|
||||||
* sets default attributes
|
* sets default attributes
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
final public function setDefaultAttributes() {
|
final public function setDefaultAttributes() {
|
||||||
static $init = false;
|
static $init = false;
|
||||||
if( ! $init) {
|
if( ! $init) {
|
||||||
$init = true;
|
$init = true;
|
||||||
$attributes = array(
|
$attributes = array(
|
||||||
Doctrine::ATTR_FETCHMODE => Doctrine::FETCH_IMMEDIATE,
|
Doctrine::ATTR_FETCHMODE => Doctrine::FETCH_IMMEDIATE,
|
||||||
Doctrine::ATTR_BATCH_SIZE => 5,
|
Doctrine::ATTR_BATCH_SIZE => 5,
|
||||||
Doctrine::ATTR_COLL_LIMIT => 5,
|
Doctrine::ATTR_COLL_LIMIT => 5,
|
||||||
Doctrine::ATTR_LISTENER => new Doctrine_EventListener(),
|
Doctrine::ATTR_LISTENER => new Doctrine_EventListener(),
|
||||||
Doctrine::ATTR_LOCKMODE => 1,
|
Doctrine::ATTR_LOCKMODE => 1,
|
||||||
Doctrine::ATTR_VLD => false,
|
Doctrine::ATTR_VLD => false,
|
||||||
Doctrine::ATTR_CREATE_TABLES => true,
|
Doctrine::ATTR_AUTO_LENGTH_VLD => true,
|
||||||
Doctrine::ATTR_QUERY_LIMIT => Doctrine::LIMIT_RECORDS
|
Doctrine::ATTR_AUTO_TYPE_VLD => true,
|
||||||
);
|
Doctrine::ATTR_CREATE_TABLES => true,
|
||||||
foreach($attributes as $attribute => $value) {
|
Doctrine::ATTR_QUERY_LIMIT => Doctrine::LIMIT_RECORDS
|
||||||
$old = $this->getAttribute($attribute);
|
);
|
||||||
if($old === null)
|
foreach($attributes as $attribute => $value) {
|
||||||
$this->setAttribute($attribute,$value);
|
$old = $this->getAttribute($attribute);
|
||||||
}
|
if($old === null)
|
||||||
return true;
|
$this->setAttribute($attribute,$value);
|
||||||
}
|
}
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
/**
|
return false;
|
||||||
* returns the root directory of Doctrine
|
}
|
||||||
*
|
/**
|
||||||
* @return string
|
* returns the root directory of Doctrine
|
||||||
*/
|
*
|
||||||
final public function getRoot() {
|
* @return string
|
||||||
return $this->root;
|
*/
|
||||||
}
|
final public function getRoot() {
|
||||||
/**
|
return $this->root;
|
||||||
* getInstance
|
}
|
||||||
* returns an instance of this class
|
/**
|
||||||
* (this class uses the singleton pattern)
|
* getInstance
|
||||||
*
|
* returns an instance of this class
|
||||||
* @return Doctrine_Manager
|
* (this class uses the singleton pattern)
|
||||||
*/
|
*
|
||||||
public static function getInstance() {
|
* @return Doctrine_Manager
|
||||||
static $instance;
|
*/
|
||||||
if( ! isset($instance))
|
public static function getInstance() {
|
||||||
$instance = new self();
|
static $instance;
|
||||||
|
if( ! isset($instance))
|
||||||
return $instance;
|
$instance = new self();
|
||||||
}
|
|
||||||
/**
|
return $instance;
|
||||||
* connection
|
}
|
||||||
* a short cut for Doctrine_Manager::getInstance()->openConnection($dbh);
|
/**
|
||||||
*
|
* connection
|
||||||
* @return Doctrine_Connection
|
* a short cut for Doctrine_Manager::getInstance()->openConnection($dbh);
|
||||||
*/
|
*
|
||||||
public static function connection(PDO $dbh) {
|
* @return Doctrine_Connection
|
||||||
return Doctrine_Manager::getInstance()->openConnection($dbh);
|
*/
|
||||||
}
|
public static function connection(PDO $dbh) {
|
||||||
/**
|
return Doctrine_Manager::getInstance()->openConnection($dbh);
|
||||||
* openConnection
|
}
|
||||||
* opens a new connection and saves it to Doctrine_Manager->connections
|
/**
|
||||||
*
|
* openConnection
|
||||||
* @param PDO $pdo PDO database driver
|
* opens a new connection and saves it to Doctrine_Manager->connections
|
||||||
* @param string $name name of the connection, if empty numeric key is used
|
*
|
||||||
* @throws Doctrine_Manager_Exception if trying to bind a connection with an existing name
|
* @param PDO $pdo PDO database driver
|
||||||
* @return Doctrine_Connection
|
* @param string $name name of the connection, if empty numeric key is used
|
||||||
*/
|
* @throws Doctrine_Manager_Exception if trying to bind a connection with an existing name
|
||||||
public function openConnection(PDO $pdo, $name = null) {
|
* @return Doctrine_Connection
|
||||||
// initialize the default attributes
|
*/
|
||||||
$this->setDefaultAttributes();
|
public function openConnection(PDO $pdo, $name = null) {
|
||||||
|
// initialize the default attributes
|
||||||
if($name !== null) {
|
$this->setDefaultAttributes();
|
||||||
$name = (string) $name;
|
|
||||||
if(isset($this->connections[$name]))
|
if($name !== null) {
|
||||||
throw new Doctrine_Manager_Exception("Connection with $name already exists!");
|
$name = (string) $name;
|
||||||
|
if(isset($this->connections[$name]))
|
||||||
} else {
|
throw new Doctrine_Manager_Exception("Connection with $name already exists!");
|
||||||
$name = $this->index;
|
|
||||||
$this->index++;
|
} else {
|
||||||
}
|
$name = $this->index;
|
||||||
switch($pdo->getAttribute(PDO::ATTR_DRIVER_NAME)):
|
$this->index++;
|
||||||
case "mysql":
|
}
|
||||||
$this->connections[$name] = new Doctrine_Connection_Mysql($this,$pdo);
|
switch($pdo->getAttribute(PDO::ATTR_DRIVER_NAME)):
|
||||||
break;
|
case "mysql":
|
||||||
case "sqlite":
|
$this->connections[$name] = new Doctrine_Connection_Mysql($this,$pdo);
|
||||||
$this->connections[$name] = new Doctrine_Connection_Sqlite($this,$pdo);
|
break;
|
||||||
break;
|
case "sqlite":
|
||||||
case "pgsql":
|
$this->connections[$name] = new Doctrine_Connection_Sqlite($this,$pdo);
|
||||||
$this->connections[$name] = new Doctrine_Connection_Pgsql($this,$pdo);
|
break;
|
||||||
break;
|
case "pgsql":
|
||||||
case "oci":
|
$this->connections[$name] = new Doctrine_Connection_Pgsql($this,$pdo);
|
||||||
$this->connections[$name] = new Doctrine_Connection_Oracle($this,$pdo);
|
break;
|
||||||
break;
|
case "oci":
|
||||||
case "mssql":
|
$this->connections[$name] = new Doctrine_Connection_Oracle($this,$pdo);
|
||||||
$this->connections[$name] = new Doctrine_Connection_Mssql($this,$pdo);
|
break;
|
||||||
break;
|
case "mssql":
|
||||||
case "firebird":
|
$this->connections[$name] = new Doctrine_Connection_Mssql($this,$pdo);
|
||||||
$this->connections[$name] = new Doctrine_Connection_Firebird($this,$pdo);
|
break;
|
||||||
break;
|
case "firebird":
|
||||||
case "informix":
|
$this->connections[$name] = new Doctrine_Connection_Firebird($this,$pdo);
|
||||||
$this->connections[$name] = new Doctrine_Connection_Informix($this,$pdo);
|
break;
|
||||||
break;
|
case "informix":
|
||||||
endswitch;
|
$this->connections[$name] = new Doctrine_Connection_Informix($this,$pdo);
|
||||||
|
break;
|
||||||
|
endswitch;
|
||||||
$this->currIndex = $name;
|
|
||||||
return $this->connections[$name];
|
|
||||||
}
|
$this->currIndex = $name;
|
||||||
public function openSession(PDO $pdo, $name = null) {
|
return $this->connections[$name];
|
||||||
return $this->openConnection($pdo, $name);
|
}
|
||||||
}
|
public function openSession(PDO $pdo, $name = null) {
|
||||||
/**
|
return $this->openConnection($pdo, $name);
|
||||||
* getConnection
|
}
|
||||||
* @param integer $index
|
/**
|
||||||
* @return object Doctrine_Connection
|
* getConnection
|
||||||
* @throws Doctrine_Manager_Exception if trying to get a non-existent connection
|
* @param integer $index
|
||||||
*/
|
* @return object Doctrine_Connection
|
||||||
public function getConnection($name) {
|
* @throws Doctrine_Manager_Exception if trying to get a non-existent connection
|
||||||
if (!isset($this->connections[$name])) {
|
*/
|
||||||
if (isset($this->dataSourceNames[$name])) {
|
public function getConnection($name) {
|
||||||
$conn = Doctrine_DB::getConnection($this->dataSourceNames[$name]); // Establishes the connection
|
if (!isset($this->connections[$name])) {
|
||||||
$this->openConnection($conn, $name);
|
if (isset($this->dataSourceNames[$name])) {
|
||||||
} else {
|
$conn = Doctrine_DB::getConnection($this->dataSourceNames[$name]); // Establishes the connection
|
||||||
throw new Doctrine_Manager_Exception("Unknown connection: $name");
|
$this->openConnection($conn, $name);
|
||||||
}
|
} else {
|
||||||
}
|
throw new Doctrine_Manager_Exception("Unknown connection: $name");
|
||||||
$this->currIndex = $name;
|
}
|
||||||
return $this->connections[$name];
|
}
|
||||||
}
|
$this->currIndex = $name;
|
||||||
|
return $this->connections[$name];
|
||||||
/**
|
}
|
||||||
* Adds the dsn of a connection to the list of available data source names.
|
|
||||||
*
|
/**
|
||||||
* @param string $dsn
|
* Adds the dsn of a connection to the list of available data source names.
|
||||||
* @param string $name
|
*
|
||||||
*/
|
* @param string $dsn
|
||||||
public function addDSN($dsn, $name) {
|
* @param string $name
|
||||||
$this->dataSourceNames[$name] = $dsn;
|
*/
|
||||||
}
|
public function addDSN($dsn, $name) {
|
||||||
/**
|
$this->dataSourceNames[$name] = $dsn;
|
||||||
* closes the connection
|
}
|
||||||
*
|
/**
|
||||||
* @param Doctrine_Connection $connection
|
* closes the connection
|
||||||
* @return void
|
*
|
||||||
*/
|
* @param Doctrine_Connection $connection
|
||||||
public function closeConnection(Doctrine_Connection $connection) {
|
* @return void
|
||||||
$connection->close();
|
*/
|
||||||
unset($connection);
|
public function closeConnection(Doctrine_Connection $connection) {
|
||||||
}
|
$connection->close();
|
||||||
/**
|
unset($connection);
|
||||||
* getConnections
|
}
|
||||||
* returns all opened connections
|
/**
|
||||||
*
|
* getConnections
|
||||||
* @return array
|
* returns all opened connections
|
||||||
*/
|
*
|
||||||
public function getConnections() {
|
* @return array
|
||||||
return $this->connections;
|
*/
|
||||||
}
|
public function getConnections() {
|
||||||
/**
|
return $this->connections;
|
||||||
* setCurrentConnection
|
}
|
||||||
* sets the current connection to $key
|
/**
|
||||||
*
|
* setCurrentConnection
|
||||||
* @param mixed $key the connection key
|
* sets the current connection to $key
|
||||||
* @throws InvalidKeyException
|
*
|
||||||
* @return void
|
* @param mixed $key the connection key
|
||||||
*/
|
* @throws InvalidKeyException
|
||||||
public function setCurrentConnection($key) {
|
* @return void
|
||||||
$key = (string) $key;
|
*/
|
||||||
if( ! isset($this->connections[$key]))
|
public function setCurrentConnection($key) {
|
||||||
throw new InvalidKeyException();
|
$key = (string) $key;
|
||||||
|
if( ! isset($this->connections[$key]))
|
||||||
$this->currIndex = $key;
|
throw new InvalidKeyException();
|
||||||
}
|
|
||||||
/**
|
$this->currIndex = $key;
|
||||||
* count
|
}
|
||||||
* returns the number of opened connections
|
/**
|
||||||
*
|
* count
|
||||||
* @return integer
|
* returns the number of opened connections
|
||||||
*/
|
*
|
||||||
public function count() {
|
* @return integer
|
||||||
return count($this->connections);
|
*/
|
||||||
}
|
public function count() {
|
||||||
/**
|
return count($this->connections);
|
||||||
* getIterator
|
}
|
||||||
* returns an ArrayIterator that iterates through all connections
|
/**
|
||||||
*
|
* getIterator
|
||||||
* @return ArrayIterator
|
* returns an ArrayIterator that iterates through all connections
|
||||||
*/
|
*
|
||||||
public function getIterator() {
|
* @return ArrayIterator
|
||||||
return new ArrayIterator($this->connections);
|
*/
|
||||||
}
|
public function getIterator() {
|
||||||
/**
|
return new ArrayIterator($this->connections);
|
||||||
* getCurrentConnection
|
}
|
||||||
* returns the current connection
|
/**
|
||||||
*
|
* getCurrentConnection
|
||||||
* @throws Doctrine_Connection_Exception if there are no open connections
|
* returns the current connection
|
||||||
* @return Doctrine_Connection
|
*
|
||||||
*/
|
* @throws Doctrine_Connection_Exception if there are no open connections
|
||||||
public function getCurrentConnection() {
|
* @return Doctrine_Connection
|
||||||
$i = $this->currIndex;
|
*/
|
||||||
if( ! isset($this->connections[$i]))
|
public function getCurrentConnection() {
|
||||||
throw new Doctrine_Connection_Exception();
|
$i = $this->currIndex;
|
||||||
|
if( ! isset($this->connections[$i]))
|
||||||
return $this->connections[$i];
|
throw new Doctrine_Connection_Exception();
|
||||||
}
|
|
||||||
/**
|
return $this->connections[$i];
|
||||||
* __toString
|
}
|
||||||
* returns a string representation of this object
|
/**
|
||||||
*
|
* __toString
|
||||||
* @return string
|
* returns a string representation of this object
|
||||||
*/
|
*
|
||||||
public function __toString() {
|
* @return string
|
||||||
$r[] = "<pre>";
|
*/
|
||||||
$r[] = "Doctrine_Manager";
|
public function __toString() {
|
||||||
$r[] = "Connections : ".count($this->connections);
|
$r[] = "<pre>";
|
||||||
$r[] = "</pre>";
|
$r[] = "Doctrine_Manager";
|
||||||
return implode("\n",$r);
|
$r[] = "Connections : ".count($this->connections);
|
||||||
}
|
$r[] = "</pre>";
|
||||||
}
|
return implode("\n",$r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -104,15 +104,12 @@ class Doctrine_Validator {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($column[0] == "array" || $column[0] == "object")
|
if($record->getTable()->getAttribute(Doctrine::ATTR_AUTO_LENGTH_VLD)) {
|
||||||
$length = strlen(serialize($value));
|
if(!$this->validateLength($column, $key, $value)) {
|
||||||
else
|
$errorStack->add($key, 'length');
|
||||||
$length = strlen($value);
|
continue;
|
||||||
|
}
|
||||||
if($length > $column[1]) {
|
|
||||||
$errorStack->add($key, 'length');
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! is_array($column[2]))
|
if( ! is_array($column[2]))
|
||||||
@ -137,7 +134,25 @@ class Doctrine_Validator {
|
|||||||
$name == 'autoincrement' ||
|
$name == 'autoincrement' ||
|
||||||
$name == 'default')
|
$name == 'default')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if(strtolower($name) == 'length') {
|
||||||
|
if(!$record->getTable()->getAttribute(Doctrine::ATTR_AUTO_LENGTH_VLD)) {
|
||||||
|
if(!$this->validateLength($column, $key, $value)) {
|
||||||
|
$errorStack->add($key, 'length');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strtolower($name) == 'type') {
|
||||||
|
if(!$record->getTable()->getAttribute(Doctrine::ATTR_AUTO_TYPE_VLD)) {
|
||||||
|
if( ! self::isValidType($value, $column[0])) {
|
||||||
|
$errorStack->add($key, 'type');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$validator = self::getValidator($name);
|
$validator = self::getValidator($name);
|
||||||
if( ! $validator->validate($record, $key, $value, $args)) {
|
if( ! $validator->validate($record, $key, $value, $args)) {
|
||||||
|
|
||||||
@ -147,15 +162,33 @@ class Doctrine_Validator {
|
|||||||
//$err[$key] = 'not valid';
|
//$err[$key] = 'not valid';
|
||||||
|
|
||||||
// errors found quit validation looping for this column
|
// errors found quit validation looping for this column
|
||||||
break;
|
//break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( ! self::isValidType($value, $column[0])) {
|
|
||||||
$errorStack->add($key, 'type');
|
if($record->getTable()->getAttribute(Doctrine::ATTR_AUTO_TYPE_VLD)) {
|
||||||
continue;
|
if( ! self::isValidType($value, $column[0])) {
|
||||||
|
$errorStack->add($key, 'type');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private function validateLength($column, $key, $value) {
|
||||||
|
if($column[0] == "array" || $column[0] == "object")
|
||||||
|
$length = strlen(serialize($value));
|
||||||
|
else
|
||||||
|
$length = strlen($value);
|
||||||
|
|
||||||
|
if($length > $column[1]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* whether or not this validator has errors
|
* whether or not this validator has errors
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user