[2.0] Removing Doctrine.php and removing references to some remaining Doctrine constants
This commit is contained in:
parent
87fd08e427
commit
15beb5e43b
111
lib/Doctrine.php
111
lib/Doctrine.php
@ -1,111 +0,0 @@
|
|||||||
<?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.org>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Doctrine
|
|
||||||
* the base class of Doctrine framework
|
|
||||||
*
|
|
||||||
* @package Doctrine
|
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
||||||
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
|
|
||||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
||||||
* @link www.phpdoctrine.org
|
|
||||||
* @since 1.0
|
|
||||||
* @version $Revision$
|
|
||||||
* @todo Remove all the constants, attributes to the new attribute system,
|
|
||||||
* All methods to appropriate classes.
|
|
||||||
* Finally remove this class.
|
|
||||||
*/
|
|
||||||
final class Doctrine
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* PDO derived constants
|
|
||||||
*/
|
|
||||||
const CASE_NATURAL = 0;
|
|
||||||
const CASE_UPPER = 1;
|
|
||||||
const CASE_LOWER = 2;
|
|
||||||
const CURSOR_FWDONLY = 0;
|
|
||||||
const CURSOR_SCROLL = 1;
|
|
||||||
const ERRMODE_EXCEPTION = 2;
|
|
||||||
const ERRMODE_SILENT = 0;
|
|
||||||
const ERRMODE_WARNING = 1;
|
|
||||||
const FETCH_ASSOC = 2;
|
|
||||||
const FETCH_BOTH = 4;
|
|
||||||
const FETCH_BOUND = 6;
|
|
||||||
const FETCH_CLASS = 8;
|
|
||||||
const FETCH_CLASSTYPE = 262144;
|
|
||||||
const FETCH_COLUMN = 7;
|
|
||||||
const FETCH_FUNC = 10;
|
|
||||||
const FETCH_GROUP = 65536;
|
|
||||||
const FETCH_INTO = 9;
|
|
||||||
const FETCH_LAZY = 1;
|
|
||||||
const FETCH_NAMED = 11;
|
|
||||||
const FETCH_NUM = 3;
|
|
||||||
const FETCH_OBJ = 5;
|
|
||||||
const FETCH_ORI_ABS = 4;
|
|
||||||
const FETCH_ORI_FIRST = 2;
|
|
||||||
const FETCH_ORI_LAST = 3;
|
|
||||||
const FETCH_ORI_NEXT = 0;
|
|
||||||
const FETCH_ORI_PRIOR = 1;
|
|
||||||
const FETCH_ORI_REL = 5;
|
|
||||||
const FETCH_SERIALIZE = 524288;
|
|
||||||
const FETCH_UNIQUE = 196608;
|
|
||||||
const NULL_EMPTY_STRING = 1;
|
|
||||||
const NULL_NATURAL = 0;
|
|
||||||
const NULL_TO_STRING = NULL;
|
|
||||||
const PARAM_BOOL = 5;
|
|
||||||
const PARAM_INPUT_OUTPUT = -2147483648;
|
|
||||||
const PARAM_INT = 1;
|
|
||||||
const PARAM_LOB = 3;
|
|
||||||
const PARAM_NULL = 0;
|
|
||||||
const PARAM_STMT = 4;
|
|
||||||
const PARAM_STR = 2;
|
|
||||||
const ATTR_AUTOCOMMIT = 0;
|
|
||||||
const ATTR_PREFETCH = 1;
|
|
||||||
const ATTR_TIMEOUT = 2;
|
|
||||||
const ATTR_ERRMODE = 3;
|
|
||||||
const ATTR_SERVER_VERSION = 4;
|
|
||||||
const ATTR_CLIENT_VERSION = 5;
|
|
||||||
const ATTR_SERVER_INFO = 6;
|
|
||||||
const ATTR_CONNECTION_STATUS = 7;
|
|
||||||
const ATTR_CASE = 8;
|
|
||||||
const ATTR_CURSOR_NAME = 9;
|
|
||||||
const ATTR_CURSOR = 10;
|
|
||||||
const ATTR_ORACLE_NULLS = 11;
|
|
||||||
const ATTR_PERSISTENT = 12;
|
|
||||||
const ATTR_STATEMENT_CLASS = 13;
|
|
||||||
const ATTR_FETCH_TABLE_NAMES = 14;
|
|
||||||
const ATTR_FETCH_CATALOG_NAMES = 15;
|
|
||||||
const ATTR_DRIVER_NAME = 16;
|
|
||||||
const ATTR_STRINGIFY_FETCHES = 17;
|
|
||||||
const ATTR_MAX_COLUMN_LEN = 18;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* __construct
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @throws Doctrine_Exception
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
throw new Doctrine_Exception('Doctrine is static class. No instances can be created.');
|
|
||||||
}
|
|
||||||
}
|
|
@ -749,77 +749,6 @@ class Connection
|
|||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes any formatting in an sequence name using the 'seqname_format' option
|
|
||||||
*
|
|
||||||
* @param string $sqn string that containts name of a potential sequence
|
|
||||||
* @return string name of the sequence with possible formatting removed
|
|
||||||
*/
|
|
||||||
protected function _fixSequenceName($sqn)
|
|
||||||
{
|
|
||||||
$seqPattern = '/^'.preg_replace('/%s/', '([a-z0-9_]+)', $this->conn->getAttribute(Doctrine::ATTR_SEQNAME_FORMAT)).'$/i';
|
|
||||||
$seqName = preg_replace($seqPattern, '\\1', $sqn);
|
|
||||||
|
|
||||||
if ($seqName && ! strcasecmp($sqn, $this->getSequenceName($seqName))) {
|
|
||||||
return $seqName;
|
|
||||||
}
|
|
||||||
return $sqn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes any formatting in an index name using the 'idxname_format' option
|
|
||||||
*
|
|
||||||
* @param string $idx string that containts name of anl index
|
|
||||||
* @return string name of the index with possible formatting removed
|
|
||||||
*/
|
|
||||||
protected function _fixIndexName($idx)
|
|
||||||
{
|
|
||||||
$indexPattern = '/^'.preg_replace('/%s/', '([a-z0-9_]+)', $this->conn->getAttribute(Doctrine::ATTR_IDXNAME_FORMAT)).'$/i';
|
|
||||||
$indexName = preg_replace($indexPattern, '\\1', $idx);
|
|
||||||
if ($indexName && ! strcasecmp($idx, $this->getIndexName($indexName))) {
|
|
||||||
return $indexName;
|
|
||||||
}
|
|
||||||
return $idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* adds sequence name formatting to a sequence name
|
|
||||||
*
|
|
||||||
* @param string name of the sequence
|
|
||||||
* @return string formatted sequence name
|
|
||||||
*/
|
|
||||||
protected function _getSequenceName($sqn)
|
|
||||||
{
|
|
||||||
return sprintf($this->conn->getAttribute(Doctrine::ATTR_SEQNAME_FORMAT),
|
|
||||||
preg_replace('/[^a-z0-9_\$.]/i', '_', $sqn));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* adds index name formatting to a index name
|
|
||||||
*
|
|
||||||
* @param string name of the index
|
|
||||||
* @return string formatted index name
|
|
||||||
*/
|
|
||||||
protected function _getIndexName($idx)
|
|
||||||
{
|
|
||||||
return sprintf($this->conn->getAttribute(Doctrine::ATTR_IDXNAME_FORMAT),
|
|
||||||
preg_replace('/[^a-z0-9_\$]/i', '_', $idx));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* adds table name formatting to a table name
|
|
||||||
*
|
|
||||||
* @param string name of the table
|
|
||||||
* @return string formatted table name
|
|
||||||
*/
|
|
||||||
protected function _getTableName($table)
|
|
||||||
{
|
|
||||||
return $table;
|
|
||||||
/*
|
|
||||||
return sprintf($this->conn->getAttribute(Doctrine::ATTR_TBLNAME_FORMAT),
|
|
||||||
$table);*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the wrapped driver connection.
|
* Gets the wrapped driver connection.
|
||||||
*
|
*
|
||||||
|
@ -23,4 +23,3 @@ interface Connection
|
|||||||
public function errorCode();
|
public function errorCode();
|
||||||
public function errorInfo();
|
public function errorInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ interface Statement
|
|||||||
* If using the column name, be aware that the name should match
|
* If using the column name, be aware that the name should match
|
||||||
* the case of the column, as returned by the driver.
|
* the case of the column, as returned by the driver.
|
||||||
* @param string $param Name of the PHP variable to which the column will be bound.
|
* @param string $param Name of the PHP variable to which the column will be bound.
|
||||||
* @param integer $type Data type of the parameter, specified by the Doctrine::PARAM_* constants.
|
* @param integer $type Data type of the parameter, specified by the PDO::PARAM_* constants.
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure
|
* @return boolean Returns TRUE on success or FALSE on failure
|
||||||
*/
|
*/
|
||||||
public function bindColumn($column, &$param, $type = null);
|
public function bindColumn($column, &$param, $type = null);
|
||||||
@ -58,7 +58,7 @@ interface Statement
|
|||||||
* using question mark placeholders, this will be the 1-indexed position of the parameter
|
* using question mark placeholders, this will be the 1-indexed position of the parameter
|
||||||
*
|
*
|
||||||
* @param mixed $value The value to bind to the parameter.
|
* @param mixed $value The value to bind to the parameter.
|
||||||
* @param integer $type Explicit data type for the parameter using the Doctrine::PARAM_* constants.
|
* @param integer $type Explicit data type for the parameter using the PDO::PARAM_* constants.
|
||||||
*
|
*
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure.
|
* @return boolean Returns TRUE on success or FALSE on failure.
|
||||||
*/
|
*/
|
||||||
@ -82,9 +82,9 @@ interface Statement
|
|||||||
*
|
*
|
||||||
* @param mixed $variable Name of the PHP variable to bind to the SQL statement parameter.
|
* @param mixed $variable Name of the PHP variable to bind to the SQL statement parameter.
|
||||||
*
|
*
|
||||||
* @param integer $type Explicit data type for the parameter using the Doctrine::PARAM_* constants. To return
|
* @param integer $type Explicit data type for the parameter using the PDO::PARAM_* constants. To return
|
||||||
* an INOUT parameter from a stored procedure, use the bitwise OR operator to set the
|
* an INOUT parameter from a stored procedure, use the bitwise OR operator to set the
|
||||||
* Doctrine::PARAM_INPUT_OUTPUT bits for the data_type parameter.
|
* PDO::PARAM_INPUT_OUTPUT bits for the data_type parameter.
|
||||||
*
|
*
|
||||||
* @param integer $length Length of the data type. To indicate that a parameter is an OUT parameter
|
* @param integer $length Length of the data type. To indicate that a parameter is an OUT parameter
|
||||||
* from a stored procedure, you must explicitly set the length.
|
* from a stored procedure, you must explicitly set the length.
|
||||||
@ -148,32 +148,32 @@ interface Statement
|
|||||||
/**
|
/**
|
||||||
* fetch
|
* fetch
|
||||||
*
|
*
|
||||||
* @see Doctrine::FETCH_* constants
|
* @see Query::HYDRATE_* constants
|
||||||
* @param integer $fetchStyle Controls how the next row will be returned to the caller.
|
* @param integer $fetchStyle Controls how the next row will be returned to the caller.
|
||||||
* This value must be one of the Doctrine::FETCH_* constants,
|
* This value must be one of the Query::HYDRATE_* constants,
|
||||||
* defaulting to Doctrine::FETCH_BOTH
|
* defaulting to Query::HYDRATE_BOTH
|
||||||
*
|
*
|
||||||
* @param integer $cursorOrientation For a PDOStatement object representing a scrollable cursor,
|
* @param integer $cursorOrientation For a PDOStatement object representing a scrollable cursor,
|
||||||
* this value determines which row will be returned to the caller.
|
* this value determines which row will be returned to the caller.
|
||||||
* This value must be one of the Doctrine::FETCH_ORI_* constants, defaulting to
|
* This value must be one of the Query::HYDRATE_ORI_* constants, defaulting to
|
||||||
* Doctrine::FETCH_ORI_NEXT. To request a scrollable cursor for your
|
* Query::HYDRATE_ORI_NEXT. To request a scrollable cursor for your
|
||||||
* Doctrine_Adapter_Statement_Interface object,
|
* Doctrine_Adapter_Statement_Interface object,
|
||||||
* you must set the Doctrine::ATTR_CURSOR attribute to Doctrine::CURSOR_SCROLL when you
|
* you must set the PDO::ATTR_CURSOR attribute to Doctrine::CURSOR_SCROLL when you
|
||||||
* prepare the SQL statement with Doctrine_Adapter_Interface->prepare().
|
* prepare the SQL statement with Doctrine_Adapter_Interface->prepare().
|
||||||
*
|
*
|
||||||
* @param integer $cursorOffset For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for which the
|
* @param integer $cursorOffset For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for which the
|
||||||
* $cursorOrientation parameter is set to Doctrine::FETCH_ORI_ABS, this value specifies
|
* $cursorOrientation parameter is set to Query::HYDRATE_ORI_ABS, this value specifies
|
||||||
* the absolute number of the row in the result set that shall be fetched.
|
* the absolute number of the row in the result set that shall be fetched.
|
||||||
*
|
*
|
||||||
* For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for
|
* For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for
|
||||||
* which the $cursorOrientation parameter is set to Doctrine::FETCH_ORI_REL, this value
|
* which the $cursorOrientation parameter is set to Query::HYDRATE_ORI_REL, this value
|
||||||
* specifies the row to fetch relative to the cursor position before
|
* specifies the row to fetch relative to the cursor position before
|
||||||
* Doctrine_Adapter_Statement_Interface->fetch() was called.
|
* Doctrine_Adapter_Statement_Interface->fetch() was called.
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function fetch($fetchStyle = Doctrine::FETCH_BOTH,
|
public function fetch($fetchStyle = Query::HYDRATE_BOTH,
|
||||||
$cursorOrientation = Doctrine::FETCH_ORI_NEXT,
|
$cursorOrientation = Query::HYDRATE_ORI_NEXT,
|
||||||
$cursorOffset = null);
|
$cursorOffset = null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -181,15 +181,15 @@ interface Statement
|
|||||||
* Returns an array containing all of the result set rows
|
* Returns an array containing all of the result set rows
|
||||||
*
|
*
|
||||||
* @param integer $fetchStyle Controls how the next row will be returned to the caller.
|
* @param integer $fetchStyle Controls how the next row will be returned to the caller.
|
||||||
* This value must be one of the Doctrine::FETCH_* constants,
|
* This value must be one of the Query::HYDRATE_* constants,
|
||||||
* defaulting to Doctrine::FETCH_BOTH
|
* defaulting to Query::HYDRATE_BOTH
|
||||||
*
|
*
|
||||||
* @param integer $columnIndex Returns the indicated 0-indexed column when the value of $fetchStyle is
|
* @param integer $columnIndex Returns the indicated 0-indexed column when the value of $fetchStyle is
|
||||||
* Doctrine::FETCH_COLUMN. Defaults to 0.
|
* Query::HYDRATE_COLUMN. Defaults to 0.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function fetchAll($fetchStyle = Doctrine::FETCH_BOTH);
|
public function fetchAll($fetchStyle = Query::HYDRATE_BOTH);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fetchColumn
|
* fetchColumn
|
||||||
@ -209,7 +209,7 @@ interface Statement
|
|||||||
* Fetches the next row and returns it as an object.
|
* Fetches the next row and returns it as an object.
|
||||||
*
|
*
|
||||||
* Fetches the next row and returns it as an object. This function is an alternative to
|
* Fetches the next row and returns it as an object. This function is an alternative to
|
||||||
* Doctrine_Adapter_Statement_Interface->fetch() with Doctrine::FETCH_CLASS or Doctrine::FETCH_OBJ style.
|
* Doctrine_Adapter_Statement_Interface->fetch() with Query::HYDRATE_CLASS or Query::HYDRATE_OBJ style.
|
||||||
*
|
*
|
||||||
* @param string $className Name of the created class, defaults to stdClass.
|
* @param string $className Name of the created class, defaults to stdClass.
|
||||||
* @param array $args Elements of this array are passed to the constructor.
|
* @param array $args Elements of this array are passed to the constructor.
|
||||||
@ -288,7 +288,7 @@ interface Statement
|
|||||||
* setFetchMode
|
* setFetchMode
|
||||||
* Set the default fetch mode for this statement
|
* Set the default fetch mode for this statement
|
||||||
*
|
*
|
||||||
* @param integer $mode The fetch mode must be one of the Doctrine::FETCH_* constants.
|
* @param integer $mode The fetch mode must be one of the Query::HYDRATE_* constants.
|
||||||
* @return boolean Returns 1 on success or FALSE on failure.
|
* @return boolean Returns 1 on success or FALSE on failure.
|
||||||
*/
|
*/
|
||||||
public function setFetchMode($mode, $arg1);
|
public function setFetchMode($mode, $arg1);
|
||||||
|
@ -88,7 +88,7 @@ class Statement
|
|||||||
* the case of the column, as returned by the driver.
|
* the case of the column, as returned by the driver.
|
||||||
*
|
*
|
||||||
* @param string $param Name of the PHP variable to which the column will be bound.
|
* @param string $param Name of the PHP variable to which the column will be bound.
|
||||||
* @param integer $type Data type of the parameter, specified by the Doctrine::PARAM_* constants.
|
* @param integer $type Data type of the parameter, specified by the PDO::PARAM_* constants.
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure
|
* @return boolean Returns TRUE on success or FALSE on failure
|
||||||
*/
|
*/
|
||||||
public function bindColumn($column, $param, $type = null)
|
public function bindColumn($column, $param, $type = null)
|
||||||
@ -110,7 +110,7 @@ class Statement
|
|||||||
* using question mark placeholders, this will be the 1-indexed position of the parameter
|
* using question mark placeholders, this will be the 1-indexed position of the parameter
|
||||||
*
|
*
|
||||||
* @param mixed $value The value to bind to the parameter.
|
* @param mixed $value The value to bind to the parameter.
|
||||||
* @param integer $type Explicit data type for the parameter using the Doctrine::PARAM_* constants.
|
* @param integer $type Explicit data type for the parameter using the PDO::PARAM_* constants.
|
||||||
*
|
*
|
||||||
* @return boolean Returns TRUE on success or FALSE on failure.
|
* @return boolean Returns TRUE on success or FALSE on failure.
|
||||||
*/
|
*/
|
||||||
@ -140,9 +140,9 @@ class Statement
|
|||||||
*
|
*
|
||||||
* @param mixed $variable Name of the PHP variable to bind to the SQL statement parameter.
|
* @param mixed $variable Name of the PHP variable to bind to the SQL statement parameter.
|
||||||
*
|
*
|
||||||
* @param integer $type Explicit data type for the parameter using the Doctrine::PARAM_* constants. To return
|
* @param integer $type Explicit data type for the parameter using the PDO::PARAM_* constants. To return
|
||||||
* an INOUT parameter from a stored procedure, use the bitwise OR operator to set the
|
* an INOUT parameter from a stored procedure, use the bitwise OR operator to set the
|
||||||
* Doctrine::PARAM_INPUT_OUTPUT bits for the data_type parameter.
|
* PDO::PARAM_INPUT_OUTPUT bits for the data_type parameter.
|
||||||
*
|
*
|
||||||
* @param integer $length Length of the data type. To indicate that a parameter is an OUT parameter
|
* @param integer $length Length of the data type. To indicate that a parameter is an OUT parameter
|
||||||
* from a stored procedure, you must explicitly set the length.
|
* from a stored procedure, you must explicitly set the length.
|
||||||
@ -241,32 +241,32 @@ class Statement
|
|||||||
/**
|
/**
|
||||||
* fetch
|
* fetch
|
||||||
*
|
*
|
||||||
* @see Doctrine::FETCH_* constants
|
* @see Query::HYDRATE_* constants
|
||||||
* @param integer $fetchStyle Controls how the next row will be returned to the caller.
|
* @param integer $fetchStyle Controls how the next row will be returned to the caller.
|
||||||
* This value must be one of the Doctrine::FETCH_* constants,
|
* This value must be one of the Query::HYDRATE_* constants,
|
||||||
* defaulting to Doctrine::FETCH_BOTH
|
* defaulting to Query::HYDRATE_BOTH
|
||||||
*
|
*
|
||||||
* @param integer $cursorOrientation For a PDOStatement object representing a scrollable cursor,
|
* @param integer $cursorOrientation For a PDOStatement object representing a scrollable cursor,
|
||||||
* this value determines which row will be returned to the caller.
|
* this value determines which row will be returned to the caller.
|
||||||
* This value must be one of the Doctrine::FETCH_ORI_* constants, defaulting to
|
* This value must be one of the Query::HYDRATE_ORI_* constants, defaulting to
|
||||||
* Doctrine::FETCH_ORI_NEXT. To request a scrollable cursor for your
|
* Query::HYDRATE_ORI_NEXT. To request a scrollable cursor for your
|
||||||
* Doctrine_Adapter_Statement_Interface object,
|
* Doctrine_Adapter_Statement_Interface object,
|
||||||
* you must set the Doctrine::ATTR_CURSOR attribute to Doctrine::CURSOR_SCROLL when you
|
* you must set the PDO::ATTR_CURSOR attribute to Doctrine::CURSOR_SCROLL when you
|
||||||
* prepare the SQL statement with Doctrine_Adapter_Interface->prepare().
|
* prepare the SQL statement with Doctrine_Adapter_Interface->prepare().
|
||||||
*
|
*
|
||||||
* @param integer $cursorOffset For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for which the
|
* @param integer $cursorOffset For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for which the
|
||||||
* $cursorOrientation parameter is set to Doctrine::FETCH_ORI_ABS, this value specifies
|
* $cursorOrientation parameter is set to Query::HYDRATE_ORI_ABS, this value specifies
|
||||||
* the absolute number of the row in the result set that shall be fetched.
|
* the absolute number of the row in the result set that shall be fetched.
|
||||||
*
|
*
|
||||||
* For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for
|
* For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for
|
||||||
* which the $cursorOrientation parameter is set to Doctrine::FETCH_ORI_REL, this value
|
* which the $cursorOrientation parameter is set to Query::HYDRATE_ORI_REL, this value
|
||||||
* specifies the row to fetch relative to the cursor position before
|
* specifies the row to fetch relative to the cursor position before
|
||||||
* Doctrine_Adapter_Statement_Interface->fetch() was called.
|
* Doctrine_Adapter_Statement_Interface->fetch() was called.
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function fetch($fetchMode = Doctrine::FETCH_BOTH,
|
public function fetch($fetchMode = Query::HYDRATE_BOTH,
|
||||||
$cursorOrientation = Doctrine::FETCH_ORI_NEXT,
|
$cursorOrientation = Query::HYDRATE_ORI_NEXT,
|
||||||
$cursorOffset = null)
|
$cursorOffset = null)
|
||||||
{
|
{
|
||||||
//$event = new Doctrine_Event($this, Doctrine_Event::STMT_FETCH, $this->getQuery());
|
//$event = new Doctrine_Event($this, Doctrine_Event::STMT_FETCH, $this->getQuery());
|
||||||
@ -289,15 +289,15 @@ class Statement
|
|||||||
* Returns an array containing all of the result set rows
|
* Returns an array containing all of the result set rows
|
||||||
*
|
*
|
||||||
* @param integer $fetchMode Controls how the next row will be returned to the caller.
|
* @param integer $fetchMode Controls how the next row will be returned to the caller.
|
||||||
* This value must be one of the Doctrine::FETCH_* constants,
|
* This value must be one of the Query::HYDRATE_* constants,
|
||||||
* defaulting to Doctrine::FETCH_BOTH
|
* defaulting to Query::HYDRATE_BOTH
|
||||||
*
|
*
|
||||||
* @param integer $columnIndex Returns the indicated 0-indexed column when the value of $fetchStyle is
|
* @param integer $columnIndex Returns the indicated 0-indexed column when the value of $fetchStyle is
|
||||||
* Doctrine::FETCH_COLUMN. Defaults to 0.
|
* Query::HYDRATE_COLUMN. Defaults to 0.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function fetchAll($fetchMode = Doctrine::FETCH_BOTH, $columnIndex = null)
|
public function fetchAll($fetchMode = Query::HYDRATE_BOTH, $columnIndex = null)
|
||||||
{
|
{
|
||||||
//$event = new Doctrine_Event($this, Doctrine_Event::STMT_FETCHALL, $this->getQuery());
|
//$event = new Doctrine_Event($this, Doctrine_Event::STMT_FETCHALL, $this->getQuery());
|
||||||
//$event->fetchMode = $fetchMode;
|
//$event->fetchMode = $fetchMode;
|
||||||
@ -337,7 +337,7 @@ class Statement
|
|||||||
* Fetches the next row and returns it as an object.
|
* Fetches the next row and returns it as an object.
|
||||||
*
|
*
|
||||||
* Fetches the next row and returns it as an object. This function is an alternative to
|
* Fetches the next row and returns it as an object. This function is an alternative to
|
||||||
* Doctrine_Adapter_Statement_Interface->fetch() with Doctrine::FETCH_CLASS or Doctrine::FETCH_OBJ style.
|
* Doctrine_Adapter_Statement_Interface->fetch() with Query::HYDRATE_CLASS or Query::HYDRATE_OBJ style.
|
||||||
*
|
*
|
||||||
* @param string $className Name of the created class, defaults to stdClass.
|
* @param string $className Name of the created class, defaults to stdClass.
|
||||||
* @param array $args Elements of this array are passed to the constructor.
|
* @param array $args Elements of this array are passed to the constructor.
|
||||||
@ -428,7 +428,7 @@ class Statement
|
|||||||
/**
|
/**
|
||||||
* Set the default fetch mode for this statement
|
* Set the default fetch mode for this statement
|
||||||
*
|
*
|
||||||
* @param integer $mode The fetch mode must be one of the Doctrine::FETCH_* constants.
|
* @param integer $mode The fetch mode must be one of the Query::HYDRATE_* constants.
|
||||||
* @return boolean Returns 1 on success or FALSE on failure.
|
* @return boolean Returns 1 on success or FALSE on failure.
|
||||||
*/
|
*/
|
||||||
public function setFetchMode($mode, $arg1 = null, $arg2 = null)
|
public function setFetchMode($mode, $arg1 = null, $arg2 = null)
|
||||||
|
@ -1,726 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
#namespace Doctrine::ORM;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The ActiveEntity class adds an ActiveRecord-like interface to Entity classes
|
|
||||||
* that allows the Entities to directly interact with the persistence layer.
|
|
||||||
* This is mostly just a convenient wrapper for people who want it that forwards
|
|
||||||
* most method calls to the EntityManager.
|
|
||||||
*
|
|
||||||
* @since 2.0
|
|
||||||
* @todo Any takers for this one? Needs a rewrite.
|
|
||||||
*/
|
|
||||||
class Doctrine_ORM_ActiveEntity
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The class descriptor.
|
|
||||||
*
|
|
||||||
* @var Doctrine::ORM::ClassMetadata
|
|
||||||
*/
|
|
||||||
private $_class;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The changes that happened to fields of a managed entity.
|
|
||||||
* Keys are field names, values oldValue => newValue tuples.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $_dataChangeSet = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The EntityManager that is responsible for the persistent state of the entity.
|
|
||||||
* Only managed entities have an associated EntityManager.
|
|
||||||
*
|
|
||||||
* @var Doctrine\ORM\EntityManager
|
|
||||||
*/
|
|
||||||
private $_em;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes a new instance of a class derived from ActiveEntity.
|
|
||||||
*/
|
|
||||||
public function __construct() {
|
|
||||||
parent::__construct();
|
|
||||||
$this->_oid = self::$_index++;
|
|
||||||
$this->_em = Doctrine_ORM_EntityManager::getActiveEntityManager();
|
|
||||||
if (is_null($this->_em)) {
|
|
||||||
throw new Doctrine_Exception("No EntityManager found. ActiveEntity instances "
|
|
||||||
. "can only be instantiated within the context of an active EntityManager.");
|
|
||||||
}
|
|
||||||
$this->_class = $this->_em->getClassMetadata($this->_entityName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves the current state of the entity into the database.
|
|
||||||
*
|
|
||||||
* @param Doctrine_Connection $conn optional connection parameter
|
|
||||||
* @return void
|
|
||||||
* @todo ActiveEntity method.
|
|
||||||
*/
|
|
||||||
public function save()
|
|
||||||
{
|
|
||||||
$this->_em->save($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an array representation of the object's data.
|
|
||||||
*
|
|
||||||
* @param boolean $deep - Return also the relations
|
|
||||||
* @return array
|
|
||||||
* @todo ActiveEntity method.
|
|
||||||
* @todo Move implementation to EntityManager.
|
|
||||||
*/
|
|
||||||
public function toArray($deep = true, $prefixKey = false)
|
|
||||||
{
|
|
||||||
$a = array();
|
|
||||||
|
|
||||||
foreach ($this as $column => $value) {
|
|
||||||
if ($value === Doctrine_Null::$INSTANCE || is_object($value)) {
|
|
||||||
$value = null;
|
|
||||||
}
|
|
||||||
$a[$column] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->_class->getIdentifierType() == Doctrine::IDENTIFIER_AUTOINC) {
|
|
||||||
$idFieldNames = $this->_class->getIdentifier();
|
|
||||||
$idFieldName = $idFieldNames[0];
|
|
||||||
|
|
||||||
$ids = $this->identifier();
|
|
||||||
$id = count($ids) > 0 ? array_pop($ids) : null;
|
|
||||||
|
|
||||||
$a[$idFieldName] = $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($deep) {
|
|
||||||
foreach ($this->_references as $key => $relation) {
|
|
||||||
if ( ! $relation instanceof Doctrine_Null) {
|
|
||||||
$a[$key] = $relation->toArray($deep, $prefixKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// [FIX] Prevent mapped Doctrine_Entitys from being displayed fully
|
|
||||||
foreach ($this->_values as $key => $value) {
|
|
||||||
if ($value instanceof Doctrine_ORM_Entity) {
|
|
||||||
$a[$key] = $value->toArray($deep, $prefixKey);
|
|
||||||
} else {
|
|
||||||
$a[$key] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Merges this Entity with an array of values
|
|
||||||
* or with another existing instance of.
|
|
||||||
*
|
|
||||||
* @param mixed $data Data to merge. Either another instance of this model or an array
|
|
||||||
* @param bool $deep Bool value for whether or not to merge the data deep
|
|
||||||
* @return void
|
|
||||||
* @todo ActiveEntity method.
|
|
||||||
* @todo Move implementation to EntityManager.
|
|
||||||
*/
|
|
||||||
public function merge($data, $deep = true)
|
|
||||||
{
|
|
||||||
if ($data instanceof $this) {
|
|
||||||
$array = $data->toArray($deep);
|
|
||||||
} else if (is_array($data)) {
|
|
||||||
$array = $data;
|
|
||||||
} else {
|
|
||||||
$array = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->fromArray($array, $deep);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* fromArray
|
|
||||||
*
|
|
||||||
* @param string $array
|
|
||||||
* @param bool $deep Bool value for whether or not to merge the data deep
|
|
||||||
* @return void
|
|
||||||
* @todo ActiveEntity method.
|
|
||||||
* @todo Move implementation to EntityManager.
|
|
||||||
*/
|
|
||||||
public function fromArray($array, $deep = true)
|
|
||||||
{
|
|
||||||
if (is_array($array)) {
|
|
||||||
foreach ($array as $key => $value) {
|
|
||||||
if ($deep && $this->getTable()->hasRelation($key)) {
|
|
||||||
$this->$key->fromArray($value, $deep);
|
|
||||||
} else if ($this->getTable()->hasField($key)) {
|
|
||||||
$this->set($key, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Synchronizes a Doctrine_Entity and its relations with data from an array
|
|
||||||
*
|
|
||||||
* It expects an array representation of a Doctrine_Entity similar to the return
|
|
||||||
* value of the toArray() method. If the array contains relations it will create
|
|
||||||
* those that don't exist, update the ones that do, and delete the ones missing
|
|
||||||
* on the array but available on the Doctrine_Entity
|
|
||||||
*
|
|
||||||
* @param array $array representation of a Doctrine_Entity
|
|
||||||
* @todo ActiveEntity method.
|
|
||||||
* @todo Move implementation to EntityManager.
|
|
||||||
*/
|
|
||||||
public function synchronizeFromArray(array $array)
|
|
||||||
{
|
|
||||||
foreach ($array as $key => $value) {
|
|
||||||
if ($this->getTable()->hasRelation($key)) {
|
|
||||||
$this->get($key)->synchronizeFromArray($value);
|
|
||||||
} else if ($this->getTable()->hasColumn($key)) {
|
|
||||||
$this->set($key, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// eliminate relationships missing in the $array
|
|
||||||
foreach ($this->_references as $name => $obj) {
|
|
||||||
if ( ! isset($array[$name])) {
|
|
||||||
unset($this->$name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* exportTo
|
|
||||||
*
|
|
||||||
* @param string $type
|
|
||||||
* @param string $deep
|
|
||||||
* @return void
|
|
||||||
* @todo ActiveEntity method.
|
|
||||||
*/
|
|
||||||
public function exportTo($type, $deep = true)
|
|
||||||
{
|
|
||||||
if ($type == 'array') {
|
|
||||||
return $this->toArray($deep);
|
|
||||||
} else {
|
|
||||||
return Doctrine_Parser::dump($this->toArray($deep, true), $type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* importFrom
|
|
||||||
*
|
|
||||||
* @param string $type
|
|
||||||
* @param string $data
|
|
||||||
* @return void
|
|
||||||
* @author Jonathan H. Wage
|
|
||||||
* @todo ActiveEntity method.
|
|
||||||
*/
|
|
||||||
public function importFrom($type, $data)
|
|
||||||
{
|
|
||||||
if ($type == 'array') {
|
|
||||||
return $this->fromArray($data);
|
|
||||||
} else {
|
|
||||||
return $this->fromArray(Doctrine_Parser::load($data, $type));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes the persistent state of the entity.
|
|
||||||
*
|
|
||||||
* @return boolean TRUE on success, FALSE on failure.
|
|
||||||
*/
|
|
||||||
public function delete()
|
|
||||||
{
|
|
||||||
return $this->_em->remove($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a copy of the entity.
|
|
||||||
*
|
|
||||||
* @return Doctrine_Entity
|
|
||||||
* @todo ActiveEntity method. Implementation to EntityManager.
|
|
||||||
*/
|
|
||||||
public function copy($deep = true)
|
|
||||||
{
|
|
||||||
$data = $this->_data;
|
|
||||||
|
|
||||||
if ($this->_class->getIdentifierType() === Doctrine::IDENTIFIER_AUTOINC) {
|
|
||||||
$idFieldNames = (array)$this->_class->getIdentifier();
|
|
||||||
$id = $idFieldNames[0];
|
|
||||||
unset($data[$id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$ret = $this->_em->createEntity($this->_entityName, $data);
|
|
||||||
$modified = array();
|
|
||||||
|
|
||||||
foreach ($data as $key => $val) {
|
|
||||||
if ( ! ($val instanceof Doctrine_Null)) {
|
|
||||||
$ret->_modified[] = $key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($deep) {
|
|
||||||
foreach ($this->_references as $key => $value) {
|
|
||||||
if ($value instanceof Doctrine_Collection) {
|
|
||||||
foreach ($value as $record) {
|
|
||||||
$ret->{$key}[] = $record->copy($deep);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$ret->set($key, $value->copy($deep));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes links from this record to given records
|
|
||||||
* if no ids are given, it removes all links
|
|
||||||
*
|
|
||||||
* @param string $alias related component alias
|
|
||||||
* @param array $ids the identifiers of the related records
|
|
||||||
* @return Doctrine_Entity this object
|
|
||||||
*/
|
|
||||||
public function unlink($alias, $ids = array())
|
|
||||||
{
|
|
||||||
$ids = (array) $ids;
|
|
||||||
|
|
||||||
$q = new Doctrine_Query();
|
|
||||||
|
|
||||||
$rel = $this->getTable()->getRelation($alias);
|
|
||||||
|
|
||||||
if ($rel instanceof Doctrine_Relation_Association) {
|
|
||||||
$q->delete()
|
|
||||||
->from($rel->getAssociationTable()->getComponentName())
|
|
||||||
->where($rel->getLocal() . ' = ?', array_values($this->identifier()));
|
|
||||||
|
|
||||||
if (count($ids) > 0) {
|
|
||||||
$q->whereIn($rel->getForeign(), $ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
$q->execute();
|
|
||||||
|
|
||||||
} else if ($rel instanceof Doctrine_Relation_ForeignKey) {
|
|
||||||
$q->update($rel->getTable()->getComponentName())
|
|
||||||
->set($rel->getForeign(), '?', array(null))
|
|
||||||
->addWhere($rel->getForeign() . ' = ?', array_values($this->identifier()));
|
|
||||||
|
|
||||||
if (count($ids) > 0) {
|
|
||||||
$relTableIdFieldNames = (array)$rel->getTable()->getIdentifier();
|
|
||||||
$q->whereIn($relTableIdFieldNames[0], $ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
$q->execute();
|
|
||||||
}
|
|
||||||
if (isset($this->_references[$alias])) {
|
|
||||||
foreach ($this->_references[$alias] as $k => $record) {
|
|
||||||
|
|
||||||
if (in_array(current($record->identifier()), $ids)) {
|
|
||||||
$this->_references[$alias]->remove($k);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->_references[$alias]->takeSnapshot();
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates links from this record to given records.
|
|
||||||
*
|
|
||||||
* @param string $alias related component alias
|
|
||||||
* @param array $ids the identifiers of the related records
|
|
||||||
* @return Doctrine_Entity this object
|
|
||||||
*/
|
|
||||||
public function link($alias, array $ids)
|
|
||||||
{
|
|
||||||
if ( ! count($ids)) {
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
$identifier = array_values($this->identifier());
|
|
||||||
$identifier = array_shift($identifier);
|
|
||||||
|
|
||||||
$rel = $this->getTable()->getRelation($alias);
|
|
||||||
|
|
||||||
if ($rel instanceof Doctrine_Relation_Association) {
|
|
||||||
$modelClassName = $rel->getAssociationTable()->getComponentName();
|
|
||||||
$localFieldName = $rel->getLocalFieldName();
|
|
||||||
$localFieldDef = $rel->getAssociationTable()->getColumnDefinition($localFieldName);
|
|
||||||
if ($localFieldDef['type'] == 'integer') {
|
|
||||||
$identifier = (integer) $identifier;
|
|
||||||
}
|
|
||||||
$foreignFieldName = $rel->getForeignFieldName();
|
|
||||||
$foreignFieldDef = $rel->getAssociationTable()->getColumnDefinition($foreignFieldName);
|
|
||||||
if ($foreignFieldDef['type'] == 'integer') {
|
|
||||||
for ($i = 0; $i < count($ids); $i++) {
|
|
||||||
$ids[$i] = (integer) $ids[$i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach ($ids as $id) {
|
|
||||||
$record = new $modelClassName;
|
|
||||||
$record[$localFieldName] = $identifier;
|
|
||||||
$record[$foreignFieldName] = $id;
|
|
||||||
$record->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if ($rel instanceof Doctrine_Relation_ForeignKey) {
|
|
||||||
|
|
||||||
$q = new Doctrine_Query();
|
|
||||||
|
|
||||||
$q->update($rel->getTable()->getComponentName())
|
|
||||||
->set($rel->getForeign(), '?', array_values($this->identifier()));
|
|
||||||
|
|
||||||
if (count($ids) > 0) {
|
|
||||||
$relTableIdFieldNames = (array)$rel->getTable()->getIdentifier();
|
|
||||||
$q->whereIn($relTableIdFieldNames[0], $ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
$q->execute();
|
|
||||||
|
|
||||||
} else if ($rel instanceof Doctrine_Relation_LocalKey) {
|
|
||||||
$q = new Doctrine_Query();
|
|
||||||
$q->update($this->getTable()->getComponentName())
|
|
||||||
->set($rel->getLocalFieldName(), '?', $ids);
|
|
||||||
|
|
||||||
if (count($ids) > 0) {
|
|
||||||
$relTableIdFieldNames = (array)$rel->getTable()->getIdentifier();
|
|
||||||
$q->whereIn($relTableIdFieldNames[0], array_values($this->identifier()));
|
|
||||||
}
|
|
||||||
|
|
||||||
$q->execute();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Refresh internal data from the database
|
|
||||||
*
|
|
||||||
* @param bool $deep If true, fetch also current relations. Caution: this deletes
|
|
||||||
* any aggregated values you may have queried beforee
|
|
||||||
*
|
|
||||||
* @throws Doctrine_Record_Exception When the refresh operation fails (when the database row
|
|
||||||
* this record represents does not exist anymore)
|
|
||||||
* @return boolean
|
|
||||||
* @todo Implementation to EntityManager.
|
|
||||||
* @todo Move to ActiveEntity (extends Entity). Implementation to EntityManager.
|
|
||||||
*/
|
|
||||||
public function refresh($deep = false)
|
|
||||||
{
|
|
||||||
$id = $this->identifier();
|
|
||||||
if ( ! is_array($id)) {
|
|
||||||
$id = array($id);
|
|
||||||
}
|
|
||||||
if (empty($id)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$id = array_values($id);
|
|
||||||
|
|
||||||
if ($deep) {
|
|
||||||
$query = $this->_em->createQuery()->from($this->_entityName);
|
|
||||||
foreach (array_keys($this->_references) as $name) {
|
|
||||||
$query->leftJoin(get_class($this) . '.' . $name);
|
|
||||||
}
|
|
||||||
$query->where(implode(' = ? AND ', $this->_class->getIdentifierColumnNames()) . ' = ?');
|
|
||||||
$this->clearRelated();
|
|
||||||
$record = $query->fetchOne($id);
|
|
||||||
} else {
|
|
||||||
// Use FETCH_ARRAY to avoid clearing object relations
|
|
||||||
$record = $this->getRepository()->find($this->identifier(), Doctrine::HYDRATE_ARRAY);
|
|
||||||
if ($record) {
|
|
||||||
$this->hydrate($record);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($record === false) {
|
|
||||||
throw new Doctrine_Record_Exception('Failed to refresh. Record does not exist.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->_modified = array();
|
|
||||||
|
|
||||||
$this->_extractIdentifier();
|
|
||||||
|
|
||||||
$this->_state = Doctrine_ORM_Entity::STATE_CLEAN;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hydrates this object from given array
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
final public function hydrate(array $data)
|
|
||||||
{
|
|
||||||
$this->_data = array_merge($this->_data, $data);
|
|
||||||
$this->_extractIdentifier();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helps freeing the memory occupied by the entity.
|
|
||||||
* Cuts all references the entity has to other entities and removes the entity
|
|
||||||
* from the instance pool.
|
|
||||||
* Note: The entity is no longer useable after free() has been called. Any operations
|
|
||||||
* done with the entity afterwards can lead to unpredictable results.
|
|
||||||
*
|
|
||||||
* @param boolean $deep Whether to cascade the free() call to (loaded) associated entities.
|
|
||||||
*/
|
|
||||||
public function free($deep = false)
|
|
||||||
{
|
|
||||||
if ($this->_state != self::STATE_LOCKED) {
|
|
||||||
if ($this->_state == self::STATE_MANAGED) {
|
|
||||||
$this->_em->detach($this);
|
|
||||||
}
|
|
||||||
if ($deep) {
|
|
||||||
foreach ($this->_data as $name => $value) {
|
|
||||||
if ($value instanceof Doctrine_ORM_Entity || $value instanceof Doctrine_ORM_Collection) {
|
|
||||||
$value->free($deep);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->_data = array();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a string representation of this object.
|
|
||||||
*/
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
return (string)$this->_oid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether the entity is new.
|
|
||||||
*
|
|
||||||
* @return boolean TRUE if the entity is new, FALSE otherwise.
|
|
||||||
*/
|
|
||||||
final public function isNew()
|
|
||||||
{
|
|
||||||
return $this->_state == self::STATE_NEW;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether the entity has been modified since it was last synchronized
|
|
||||||
* with the database.
|
|
||||||
*
|
|
||||||
* @return boolean TRUE if the object has been modified, FALSE otherwise.
|
|
||||||
*/
|
|
||||||
final public function isModified()
|
|
||||||
{
|
|
||||||
return count($this->_dataChangeSet) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the ClassMetadata object that describes the entity class.
|
|
||||||
*
|
|
||||||
* @return Doctrine::ORM::Mapping::ClassMetadata
|
|
||||||
*/
|
|
||||||
final public function getClass()
|
|
||||||
{
|
|
||||||
return $this->_class;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the EntityManager that is responsible for the persistence of
|
|
||||||
* this entity.
|
|
||||||
*
|
|
||||||
* @return Doctrine::ORM::EntityManager
|
|
||||||
*/
|
|
||||||
final public function getEntityManager()
|
|
||||||
{
|
|
||||||
return $this->_em;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the EntityRepository of the Entity.
|
|
||||||
*
|
|
||||||
* @return Doctrine::ORM::EntityRepository
|
|
||||||
*/
|
|
||||||
final public function getRepository()
|
|
||||||
{
|
|
||||||
return $this->_em->getRepository($this->_entityName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether a field is set (not null).
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @return boolean
|
|
||||||
* @override
|
|
||||||
*/
|
|
||||||
final protected function _contains($fieldName)
|
|
||||||
{
|
|
||||||
if (isset($this->_data[$fieldName])) {
|
|
||||||
if ($this->_data[$fieldName] === Doctrine_ORM_Internal_Null::$INSTANCE) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears the value of a field.
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @return void
|
|
||||||
* @override
|
|
||||||
*/
|
|
||||||
final protected function _unset($fieldName)
|
|
||||||
{
|
|
||||||
if (isset($this->_data[$fieldName])) {
|
|
||||||
if ($this->_state == self::STATE_MANAGED && $this->_class->hasAssociation($fieldName)) {
|
|
||||||
$assoc = $this->_class->getAssociationMapping($fieldName);
|
|
||||||
if ($assoc->isOneToOne() && $assoc->shouldDeleteOrphans()) {
|
|
||||||
$this->_em->delete($this->_references[$fieldName]);
|
|
||||||
} else if ($assoc->isOneToMany() && $assoc->shouldDeleteOrphans()) {
|
|
||||||
foreach ($this->_references[$fieldName] as $entity) {
|
|
||||||
$this->_em->delete($entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->_data[$fieldName] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers the entity as dirty with the UnitOfWork.
|
|
||||||
* Note: The Entity is only registered dirty if it is MANAGED and not yet
|
|
||||||
* registered as dirty.
|
|
||||||
*/
|
|
||||||
private function _registerDirty()
|
|
||||||
{
|
|
||||||
if ($this->_state == self::STATE_MANAGED &&
|
|
||||||
! $this->_em->getUnitOfWork()->isRegisteredDirty($this)) {
|
|
||||||
$this->_em->getUnitOfWork()->registerDirty($this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the entity class name.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
final public function getClassName()
|
|
||||||
{
|
|
||||||
return $this->_entityName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the data of the Entity.
|
|
||||||
*
|
|
||||||
* @return array The fields and their values.
|
|
||||||
*/
|
|
||||||
final public function getData()
|
|
||||||
{
|
|
||||||
return $this->_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the value of a field (regular field or reference).
|
|
||||||
*
|
|
||||||
* @param $name Name of the field.
|
|
||||||
* @return mixed Value of the field.
|
|
||||||
* @throws Doctrine::ORM::Exceptions::EntityException If trying to get an unknown field.
|
|
||||||
* @override
|
|
||||||
*/
|
|
||||||
final protected function _get($fieldName)
|
|
||||||
{
|
|
||||||
$nullObj = Doctrine_ORM_Internal_Null::$INSTANCE;
|
|
||||||
if (isset($this->_data[$fieldName])) {
|
|
||||||
return $this->_data[$fieldName] !== $nullObj ?
|
|
||||||
$this->_data[$fieldName] : null;
|
|
||||||
} else {
|
|
||||||
if ($this->_state == self::STATE_MANAGED && $this->_class->hasAssociation($fieldName)) {
|
|
||||||
$rel = $this->_class->getAssociationMapping($fieldName);
|
|
||||||
if ($rel->isLazilyFetched()) {
|
|
||||||
$this->_data[$fieldName] = $rel->lazyLoadFor($this);
|
|
||||||
return $this->_data[$fieldName] !== $nullObj ?
|
|
||||||
$this->_data[$fieldName] : null;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the value of a field (regular field or reference).
|
|
||||||
*
|
|
||||||
* @param $fieldName The name of the field.
|
|
||||||
* @param $value The value of the field.
|
|
||||||
* @return void
|
|
||||||
* @throws Doctrine::ORM::Exceptions::EntityException
|
|
||||||
* @override
|
|
||||||
*/
|
|
||||||
final protected function _set($fieldName, $value)
|
|
||||||
{
|
|
||||||
$old = isset($this->_data[$fieldName]) ? $this->_data[$fieldName] : null;
|
|
||||||
if ( ! is_object($value)) {
|
|
||||||
// NOTE: Common case: $old != $value. Special case: null == 0 (TRUE), which
|
|
||||||
// is addressed by xor.
|
|
||||||
if ($old != $value || (is_null($old) xor is_null($value))) {
|
|
||||||
$this->_data[$fieldName] = $value;
|
|
||||||
$this->_dataChangeSet[$fieldName] = array($old => $value);
|
|
||||||
$this->_registerDirty();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ($old !== $value) {
|
|
||||||
$this->_internalSetReference($fieldName, $value);
|
|
||||||
$this->_dataChangeSet[$fieldName] = array($old => $value);
|
|
||||||
$this->_registerDirty();
|
|
||||||
if ($this->_state == self::STATE_MANAGED) {
|
|
||||||
//TODO: Allow arrays in $value. Wrap them in a Collection transparently.
|
|
||||||
if ($old instanceof Doctrine_ORM_Collection) {
|
|
||||||
$this->_em->getUnitOfWork()->scheduleCollectionDeletion($old);
|
|
||||||
}
|
|
||||||
if ($value instanceof Doctrine_ORM_Collection) {
|
|
||||||
$this->_em->getUnitOfWork()->scheduleCollectionRecreation($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Serializable implementation */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serializes the entity.
|
|
||||||
* This method is automatically called when the entity is serialized.
|
|
||||||
*
|
|
||||||
* Part of the implementation of the Serializable interface.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
* @todo Reimplement
|
|
||||||
*/
|
|
||||||
public function serialize()
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reconstructs the entity from it's serialized form.
|
|
||||||
* This method is automatically called everytime the entity is unserialized.
|
|
||||||
*
|
|
||||||
* @param string $serialized Doctrine_Entity as serialized string
|
|
||||||
* @throws Doctrine_Record_Exception if the cleanData operation fails somehow
|
|
||||||
* @return void
|
|
||||||
* @todo Reimplement.
|
|
||||||
*/
|
|
||||||
public function unserialize($serialized)
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* END of Serializable implementation */
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
@ -149,7 +149,7 @@ class EntityRepository
|
|||||||
*
|
*
|
||||||
* @param string $dql DQL after WHERE clause
|
* @param string $dql DQL after WHERE clause
|
||||||
* @param array $params query parameters
|
* @param array $params query parameters
|
||||||
* @param int $hydrationMode Doctrine::FETCH_ARRAY or Doctrine::FETCH_RECORD
|
* @param int $hydrationMode Query::HYDRATE_ARRAY or Query::HYDRATE_RECORD
|
||||||
* @return Doctrine_Collection
|
* @return Doctrine_Collection
|
||||||
*
|
*
|
||||||
* @todo This actually takes DQL, not SQL, but it requires column names
|
* @todo This actually takes DQL, not SQL, but it requires column names
|
||||||
@ -167,7 +167,7 @@ class EntityRepository
|
|||||||
*
|
*
|
||||||
* @param string $dql DQL after WHERE clause
|
* @param string $dql DQL after WHERE clause
|
||||||
* @param array $params query parameters
|
* @param array $params query parameters
|
||||||
* @param int $hydrationMode Doctrine::FETCH_ARRAY or Doctrine::FETCH_RECORD
|
* @param int $hydrationMode Query::HYDRATE_ARRAY or Query::HYDRATE_RECORD
|
||||||
* @return Doctrine_Collection
|
* @return Doctrine_Collection
|
||||||
*/
|
*/
|
||||||
public function findByDql($dql, array $params = array(), $hydrationMode = null)
|
public function findByDql($dql, array $params = array(), $hydrationMode = null)
|
||||||
|
@ -63,7 +63,7 @@ class Query extends AbstractQuery
|
|||||||
/**
|
/**
|
||||||
* @var Doctrine\ORM\EntityManager The entity manager used by this query object.
|
* @var Doctrine\ORM\EntityManager The entity manager used by this query object.
|
||||||
*/
|
*/
|
||||||
protected $_entityManager;
|
protected $_em;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var integer The hydration mode.
|
* @var integer The hydration mode.
|
||||||
@ -125,7 +125,7 @@ class Query extends AbstractQuery
|
|||||||
*/
|
*/
|
||||||
public function __construct(EntityManager $entityManager)
|
public function __construct(EntityManager $entityManager)
|
||||||
{
|
{
|
||||||
$this->_entityManager = $entityManager;
|
$this->_em = $entityManager;
|
||||||
$this->free();
|
$this->free();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ class Query extends AbstractQuery
|
|||||||
*/
|
*/
|
||||||
public function getEntityManager()
|
public function getEntityManager()
|
||||||
{
|
{
|
||||||
return $this->_entityManager;
|
return $this->_em;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -222,7 +222,7 @@ class Query extends AbstractQuery
|
|||||||
*
|
*
|
||||||
* @param string $params Parameters to be sent to query.
|
* @param string $params Parameters to be sent to query.
|
||||||
* @param integer $hydrationMode Doctrine processing mode to be used during hydration process.
|
* @param integer $hydrationMode Doctrine processing mode to be used during hydration process.
|
||||||
* One of the Doctrine::HYDRATE_* constants.
|
* One of the Query::HYDRATE_* constants.
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function execute($params = array(), $hydrationMode = null)
|
public function execute($params = array(), $hydrationMode = null)
|
||||||
@ -274,7 +274,7 @@ class Query extends AbstractQuery
|
|||||||
protected function _execute(array $params)
|
protected function _execute(array $params)
|
||||||
{
|
{
|
||||||
// If there is a CacheDriver associated to cache queries...
|
// If there is a CacheDriver associated to cache queries...
|
||||||
if ($this->_queryCache || $this->_entityManager->getConnection()->getAttribute(Doctrine::ATTR_QUERY_CACHE)) {
|
if ($this->_queryCache || $this->_em->getConfiguration()->getQueryCacheImpl()) {
|
||||||
$queryCacheDriver = $this->getQueryCacheDriver();
|
$queryCacheDriver = $this->getQueryCacheDriver();
|
||||||
|
|
||||||
// Calculate hash for dql query.
|
// Calculate hash for dql query.
|
||||||
@ -303,13 +303,6 @@ class Query extends AbstractQuery
|
|||||||
// Converting parameters
|
// Converting parameters
|
||||||
$params = $this->_prepareParams($params);
|
$params = $this->_prepareParams($params);
|
||||||
|
|
||||||
// Double the params if we are using limit-subquery algorithm
|
|
||||||
// We always have an instance of Doctrine_ORM_Query_ParserResult on hands...
|
|
||||||
/*if ($this->_parserResult->isLimitSubqueryUsed() &&
|
|
||||||
$this->_entityManager->getConnection()->getAttribute(Doctrine::ATTR_DRIVER_NAME) !== 'mysql') {
|
|
||||||
$params = array_merge($params, $params);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// Executing the query and returning statement
|
// Executing the query and returning statement
|
||||||
return $executor->execute($this->_conn, $params);
|
return $executor->execute($this->_conn, $params);
|
||||||
}
|
}
|
||||||
@ -320,7 +313,7 @@ class Query extends AbstractQuery
|
|||||||
protected function _prepareParams(array $params)
|
protected function _prepareParams(array $params)
|
||||||
{
|
{
|
||||||
// Convert boolean params
|
// Convert boolean params
|
||||||
$params = $this->_entityManager->getConnection()->convertBooleans($params);
|
$params = $this->_em->getConnection()->convertBooleans($params);
|
||||||
|
|
||||||
// Convert enum params
|
// Convert enum params
|
||||||
return $this->convertEnums($params);
|
return $this->convertEnums($params);
|
||||||
@ -354,7 +347,7 @@ class Query extends AbstractQuery
|
|||||||
if ($this->_resultCache instanceof \Doctrine\ORM\Cache\Cache) {
|
if ($this->_resultCache instanceof \Doctrine\ORM\Cache\Cache) {
|
||||||
return $this->_resultCache;
|
return $this->_resultCache;
|
||||||
} else {
|
} else {
|
||||||
return $this->_entityManager->getConnection()->getResultCacheDriver();
|
return $this->_em->getConnection()->getResultCacheDriver();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,7 +430,7 @@ class Query extends AbstractQuery
|
|||||||
if ($this->_queryCache instanceof \Doctrine\ORM\Cache\Cache) {
|
if ($this->_queryCache instanceof \Doctrine\ORM\Cache\Cache) {
|
||||||
return $this->_queryCache;
|
return $this->_queryCache;
|
||||||
} else {
|
} else {
|
||||||
return $this->_entityManager->getConnection()->getQueryCacheDriver();
|
return $this->_em->getConnection()->getQueryCacheDriver();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,7 +488,7 @@ class Query extends AbstractQuery
|
|||||||
* Defines the processing mode to be used during hydration process.
|
* Defines the processing mode to be used during hydration process.
|
||||||
*
|
*
|
||||||
* @param integer $hydrationMode Doctrine processing mode to be used during hydration process.
|
* @param integer $hydrationMode Doctrine processing mode to be used during hydration process.
|
||||||
* One of the Doctrine::HYDRATE_* constants.
|
* One of the Query::HYDRATE_* constants.
|
||||||
* @return Doctrine\ORM\Query
|
* @return Doctrine\ORM\Query
|
||||||
*/
|
*/
|
||||||
public function setHydrationMode($hydrationMode)
|
public function setHydrationMode($hydrationMode)
|
||||||
|
Loading…
Reference in New Issue
Block a user