2007-11-14 16:13:23 +03:00
|
|
|
<?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
|
2008-01-23 01:52:53 +03:00
|
|
|
* <http://www.phpdoctrine.org>.
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2008-02-22 21:11:35 +03:00
|
|
|
* @link www.phpdoctrine.org
|
2007-11-14 16:13:23 +03:00
|
|
|
* @since 1.0
|
|
|
|
* @version $Revision$
|
2008-06-05 23:01:58 +04:00
|
|
|
* @todo Remove all the constants, attributes to the new attribute system,
|
|
|
|
* All methods to separate classes.
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
final class Doctrine
|
|
|
|
{
|
2008-01-06 12:47:00 +03:00
|
|
|
/**
|
|
|
|
* DEPRECATED ATTRIBUTE CONSTANT NAMES AND VALUES
|
|
|
|
*
|
|
|
|
* REMOVE BEFORE 1.0
|
|
|
|
* These were deprecated either because they are not used anymore or because they didn't follow the naming pattern required
|
|
|
|
* by Doctrine attributes
|
|
|
|
*
|
|
|
|
* Attribute names must be ATTR_{ATTR_NAME} and the values must be {ATTR_NAME}_NAME_OF_VALUE
|
|
|
|
*/
|
|
|
|
const LIMIT_ROWS = 1;
|
|
|
|
const LIMIT_RECORDS = 2;
|
|
|
|
const FETCH_IMMEDIATE = 0;
|
|
|
|
const FETCH_BATCH = 1;
|
|
|
|
const FETCH_OFFSET = 3;
|
|
|
|
const FETCH_LAZY_OFFSET = 4;
|
|
|
|
const FETCH_VHOLDER = 1;
|
|
|
|
const FETCH_RECORD = 2;
|
|
|
|
const FETCH_ARRAY = 3;
|
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
/**
|
|
|
|
* VERSION
|
|
|
|
*/
|
2008-03-17 16:26:34 +03:00
|
|
|
const VERSION = '2.0.0';
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
/**
|
|
|
|
* ERROR CONSTANTS
|
|
|
|
*/
|
|
|
|
const ERR = -1;
|
|
|
|
const ERR_SYNTAX = -2;
|
|
|
|
const ERR_CONSTRAINT = -3;
|
|
|
|
const ERR_NOT_FOUND = -4;
|
|
|
|
const ERR_ALREADY_EXISTS = -5;
|
|
|
|
const ERR_UNSUPPORTED = -6;
|
|
|
|
const ERR_MISMATCH = -7;
|
|
|
|
const ERR_INVALID = -8;
|
|
|
|
const ERR_NOT_CAPABLE = -9;
|
|
|
|
const ERR_TRUNCATED = -10;
|
|
|
|
const ERR_INVALID_NUMBER = -11;
|
|
|
|
const ERR_INVALID_DATE = -12;
|
|
|
|
const ERR_DIVZERO = -13;
|
|
|
|
const ERR_NODBSELECTED = -14;
|
|
|
|
const ERR_CANNOT_CREATE = -15;
|
|
|
|
const ERR_CANNOT_DELETE = -16;
|
|
|
|
const ERR_CANNOT_DROP = -17;
|
|
|
|
const ERR_NOSUCHTABLE = -18;
|
|
|
|
const ERR_NOSUCHFIELD = -19;
|
|
|
|
const ERR_NEED_MORE_DATA = -20;
|
|
|
|
const ERR_NOT_LOCKED = -21;
|
|
|
|
const ERR_VALUE_COUNT_ON_ROW = -22;
|
|
|
|
const ERR_INVALID_DSN = -23;
|
|
|
|
const ERR_CONNECT_FAILED = -24;
|
|
|
|
const ERR_EXTENSION_NOT_FOUND = -25;
|
|
|
|
const ERR_NOSUCHDB = -26;
|
|
|
|
const ERR_ACCESS_VIOLATION = -27;
|
|
|
|
const ERR_CANNOT_REPLACE = -28;
|
|
|
|
const ERR_CONSTRAINT_NOT_NULL = -29;
|
|
|
|
const ERR_DEADLOCK = -30;
|
|
|
|
const ERR_CANNOT_ALTER = -31;
|
|
|
|
const ERR_MANAGER = -32;
|
|
|
|
const ERR_MANAGER_PARSE = -33;
|
|
|
|
const ERR_LOADMODULE = -34;
|
|
|
|
const ERR_INSUFFICIENT_DATA = -35;
|
|
|
|
const ERR_CLASS_NAME = -36;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PDO derived constants
|
|
|
|
*/
|
2008-01-06 12:47:00 +03:00
|
|
|
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;
|
2007-11-14 16:13:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ATTRIBUTE CONSTANTS
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PDO derived attributes
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Doctrine constants
|
|
|
|
*/
|
2008-01-06 12:47:00 +03:00
|
|
|
const ATTR_LISTENER = 100;
|
2008-03-17 16:26:34 +03:00
|
|
|
const ATTR_QUOTE_IDENTIFIER = 101; // manager/session attribute
|
|
|
|
const ATTR_FIELD_CASE = 102; // manager/session attribute
|
|
|
|
const ATTR_IDXNAME_FORMAT = 103; // manager/session attribute
|
|
|
|
const ATTR_SEQNAME_FORMAT = 104; // manager/session attribute
|
|
|
|
const ATTR_SEQCOL_NAME = 105; // class attribute
|
|
|
|
const ATTR_CMPNAME_FORMAT = 118; // ??
|
|
|
|
const ATTR_DBNAME_FORMAT = 117; // manager/session attribute
|
|
|
|
const ATTR_TBLCLASS_FORMAT = 119; // manager/session attribute
|
|
|
|
const ATTR_TBLNAME_FORMAT = 120; // manager/session attribute
|
|
|
|
const ATTR_EXPORT = 140; // manager/session attribute
|
|
|
|
const ATTR_DECIMAL_PLACES = 141; // manager/session attribute
|
|
|
|
const ATTR_PORTABILITY = 106; // manager/session attribute
|
|
|
|
const ATTR_COLL_KEY = 108; // class attribute
|
|
|
|
const ATTR_QUERY_LIMIT = 109; // manager/session attribute
|
|
|
|
const ATTR_DEFAULT_TABLE_TYPE = 112; // manager/session attribute
|
|
|
|
const ATTR_DEF_TEXT_LENGTH = 113; // manager/session attribute
|
|
|
|
const ATTR_DEF_VARCHAR_LENGTH = 114; // manager/session attribute
|
|
|
|
const ATTR_DEF_TABLESPACE = 115; // manager/session attribute
|
|
|
|
const ATTR_EMULATE_DATABASE = 116; // manager/session attribute
|
|
|
|
const ATTR_USE_NATIVE_ENUM = 117; // manager/session attribute
|
|
|
|
const ATTR_DEFAULT_SEQUENCE = 133; // ??
|
2008-03-19 21:33:14 +03:00
|
|
|
const ATTR_FETCHMODE = 118; // deprecated? might use them again for associations
|
2008-03-17 16:26:34 +03:00
|
|
|
const ATTR_NAME_PREFIX = 121; // ??
|
|
|
|
const ATTR_CREATE_TABLES = 122; // manager/session attribute
|
|
|
|
const ATTR_COLL_LIMIT = 123; // manager/session attribute
|
|
|
|
const ATTR_RESULT_CACHE = 150; // manager/session attribute
|
|
|
|
const ATTR_RESULT_CACHE_LIFESPAN = 151; // manager/session attribute
|
|
|
|
const ATTR_LOAD_REFERENCES = 153; // class attribute
|
2007-11-14 16:13:23 +03:00
|
|
|
const ATTR_RECORD_LISTENER = 154;
|
2008-03-17 16:26:34 +03:00
|
|
|
const ATTR_THROW_EXCEPTIONS = 155; // manager/session attribute
|
|
|
|
const ATTR_DEFAULT_PARAM_NAMESPACE = 156; // ??
|
|
|
|
const ATTR_QUERY_CACHE = 157; // manager/session attribute
|
|
|
|
const ATTR_QUERY_CACHE_LIFESPAN = 158; // manager/session attribute
|
|
|
|
const ATTR_MODEL_LOADING = 161; // manager/session attribute
|
|
|
|
const ATTR_HYDRATE = 163; // ??
|
|
|
|
const ATTR_IDENTIFIER = 164; // ??
|
|
|
|
const ATTR_METADATA_CACHE = 165; // manager/session attribute
|
|
|
|
const ATTR_METADATA_CACHE_LIFESPAN = 166; // manager/session attribute
|
2008-01-05 22:55:56 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* QUERY_LIMIT CONSTANTS
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* QUERY_LIMIT_ROWS
|
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* constant for row limiting
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_QUERY_LIMIT
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
2008-01-06 12:47:00 +03:00
|
|
|
const QUERY_LIMIT_ROWS = 1;
|
2007-11-14 16:13:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* constant for record limiting
|
2008-01-06 12:47:00 +03:00
|
|
|
* @see self::ATTR_QUERY_LIMIT
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
2008-01-06 12:47:00 +03:00
|
|
|
const QUERY_LIMIT_RECORDS = 2;
|
2007-11-14 16:13:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* FETCHMODE CONSTANTS
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IMMEDIATE FETCHING
|
|
|
|
* mode for immediate fetching
|
2008-01-06 12:47:00 +03:00
|
|
|
* @see self::ATTR_FETCHMODE
|
2008-02-13 13:53:07 +03:00
|
|
|
* @deprecated???
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
2008-01-06 12:47:00 +03:00
|
|
|
const FETCHMODE_IMMEDIATE = 0;
|
2007-11-14 16:13:23 +03:00
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* FETCHMODE_BATCH
|
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* mode for batch fetching
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_FETCHMODE
|
2008-02-13 13:53:07 +03:00
|
|
|
* @deprecated???
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
2008-01-06 12:47:00 +03:00
|
|
|
const FETCHMODE_BATCH = 1;
|
2007-11-14 16:13:23 +03:00
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* FETCHMODE_OFFSET
|
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* mode for offset fetching
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_FETCHMODE
|
2008-02-13 13:53:07 +03:00
|
|
|
* @deprecated???
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
2008-01-06 12:47:00 +03:00
|
|
|
const FETCHMODE_OFFSET = 3;
|
2007-11-14 16:13:23 +03:00
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* FETCHMODE_LAZY_OFFSET
|
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* mode for lazy offset fetching
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_FETCHMODE
|
2008-02-13 13:53:07 +03:00
|
|
|
* @deprecated???
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
2008-01-06 12:47:00 +03:00
|
|
|
const FETCHMODE_LAZY_OFFSET = 4;
|
2007-11-14 16:13:23 +03:00
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* FETCHMODE CONSTANTS
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* FETCHMODE_VHOLDER
|
|
|
|
*
|
|
|
|
* @see self::ATTR_FETCHMODE
|
2008-03-17 16:26:34 +03:00
|
|
|
* @deprecated???
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
2008-01-06 12:47:00 +03:00
|
|
|
const FETCHMODE_VHOLDER = 1;
|
2007-11-14 16:13:23 +03:00
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* FETCHMODE_RECORD
|
2007-11-14 16:13:23 +03:00
|
|
|
*
|
2008-05-14 01:20:34 +04:00
|
|
|
* Specifies that the fetch method shall return Doctrine_Entity
|
2007-11-14 16:13:23 +03:00
|
|
|
* objects as the elements of the result set.
|
|
|
|
*
|
|
|
|
* This is the default fetchmode.
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_FETCHMODE
|
2008-03-17 16:26:34 +03:00
|
|
|
* @deprecated???
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
2008-01-06 12:47:00 +03:00
|
|
|
const FETCHMODE_RECORD = 2;
|
2007-11-14 16:13:23 +03:00
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* FETCHMODE_ARRAY
|
|
|
|
*
|
|
|
|
* @see self::ATTR_FETCHMODE
|
2008-03-17 16:26:34 +03:00
|
|
|
* @deprecated???
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
2008-01-06 12:47:00 +03:00
|
|
|
const FETCHMODE_ARRAY = 3;
|
2007-11-14 16:13:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* PORTABILITY CONSTANTS
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* PORTABILITY_NONE
|
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* Portability: turn off all portability features.
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* @see self::ATTR_PORTABILITY
|
|
|
|
*/
|
|
|
|
const PORTABILITY_NONE = 0;
|
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* PORTABILITY_FIX_CASE
|
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* Portability: convert names of tables and fields to case defined in the
|
|
|
|
* "field_case" option when using the query*(), fetch*() methods.
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* @see self::ATTR_PORTABILITY
|
|
|
|
*/
|
|
|
|
const PORTABILITY_FIX_CASE = 1;
|
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* PORTABILITY_RTRIM
|
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* Portability: right trim the data output by query*() and fetch*().
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* @see self::ATTR_PORTABILITY
|
|
|
|
*/
|
|
|
|
const PORTABILITY_RTRIM = 2;
|
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* PORTABILITY_DELETE_COUNT
|
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* Portability: force reporting the number of rows deleted.
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* @see self::ATTR_PORTABILITY
|
|
|
|
*/
|
|
|
|
const PORTABILITY_DELETE_COUNT = 4;
|
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* PORTABILITY_EMPTY_TO_NULL
|
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* Portability: convert empty values to null strings in data output by
|
|
|
|
* query*() and fetch*().
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* @see self::ATTR_PORTABILITY
|
|
|
|
*/
|
|
|
|
const PORTABILITY_EMPTY_TO_NULL = 8;
|
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* PORTABILITY_FIX_ASSOC_FIELD_NAMES
|
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* Portability: removes database/table qualifiers from associative indexes
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* @see self::ATTR_PORTABILITY
|
|
|
|
*/
|
|
|
|
const PORTABILITY_FIX_ASSOC_FIELD_NAMES = 16;
|
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* PORTABILITY_EXPR
|
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* Portability: makes Doctrine_Expression throw exception for unportable RDBMS expressions
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* @see self::ATTR_PORTABILITY
|
|
|
|
*/
|
|
|
|
const PORTABILITY_EXPR = 32;
|
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* PORTABILITY_ALL
|
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* Portability: turn on all portability features.
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* @see self::ATTR_PORTABILITY
|
|
|
|
*/
|
|
|
|
const PORTABILITY_ALL = 63;
|
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* LOCK CONSTANTS
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* LOCK_OPTIMISTIC
|
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* mode for optimistic locking
|
2008-01-06 12:47:00 +03:00
|
|
|
* @see self::ATTR_LOCK
|
2008-02-13 13:53:07 +03:00
|
|
|
* @deprecated???
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const LOCK_OPTIMISTIC = 0;
|
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* LOCK_PESSIMISTIC
|
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* mode for pessimistic locking
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_LOCK
|
2008-02-13 13:53:07 +03:00
|
|
|
* @deprecated???
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const LOCK_PESSIMISTIC = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* EXPORT CONSTANTS
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* EXPORT_NONE
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_EXPORT
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const EXPORT_NONE = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* EXPORT_TABLES
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_EXPORT
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const EXPORT_TABLES = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* EXPORT_CONSTRAINTS
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_EXPORT
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const EXPORT_CONSTRAINTS = 2;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* EXPORT_PLUGINS
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_EXPORT
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const EXPORT_PLUGINS = 4;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* EXPORT_ALL
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_EXPORT
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const EXPORT_ALL = 7;
|
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* HYDRATE CONSTANTS
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HYDRATE_RECORD
|
|
|
|
*
|
|
|
|
* @see self::ATTR_HYDRATE
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const HYDRATE_RECORD = 2;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HYDRATE_ARRAY
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_HYDRATE
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const HYDRATE_ARRAY = 3;
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
/**
|
|
|
|
* HYDRATE_NONE
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_HYDRATE
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const HYDRATE_NONE = 4;
|
2008-05-14 01:20:34 +04:00
|
|
|
|
|
|
|
/* new hydration modes. move to Query class when it's time. */
|
2008-05-18 00:04:56 +04:00
|
|
|
const HYDRATE_IDENTITY_OBJECT = 2; // default, auto-adds PKs, produces object graphs
|
|
|
|
const HYDRATE_IDENTITY_ARRAY = 3; // auto-adds PKs, produces array graphs
|
|
|
|
const HYDRATE_SCALAR = 5; // produces flat result list with scalar values
|
|
|
|
const HYDRATE_SINGLE_SCALAR = 6; // produces a single scalar value
|
|
|
|
//const HYDRATE_NONE = 4; // produces a result set as it's returned by the db
|
2008-05-14 01:20:34 +04:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
|
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* VALIDATE CONSTANTS
|
|
|
|
*
|
|
|
|
* @see self::ATTR_VALIDATE
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const VALIDATE_NONE = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* VALIDATE_LENGTHS
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_VALIDATE
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const VALIDATE_LENGTHS = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* VALIDATE_TYPES
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_VALIDATE
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const VALIDATE_TYPES = 2;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* VALIDATE_CONSTRAINTS
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_VALIDATE
|
2008-03-17 16:26:34 +03:00
|
|
|
* Not used? Purpose?
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const VALIDATE_CONSTRAINTS = 4;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* VALIDATE_ALL
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_VALIDATE
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const VALIDATE_ALL = 7;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IDENTIFIER_AUTOINC
|
|
|
|
*
|
|
|
|
* constant for auto_increment identifier
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_IDENTIFIER
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const IDENTIFIER_AUTOINC = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IDENTIFIER_SEQUENCE
|
|
|
|
*
|
|
|
|
* constant for sequence identifier
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_IDENTIFIER
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const IDENTIFIER_SEQUENCE = 2;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IDENTIFIER_NATURAL
|
|
|
|
*
|
|
|
|
* constant for normal identifier
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_IDENTIFIER
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const IDENTIFIER_NATURAL = 3;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IDENTIFIER_COMPOSITE
|
|
|
|
*
|
|
|
|
* constant for composite identifier
|
2008-01-06 12:47:00 +03:00
|
|
|
* @see self::ATTR_IDENTIFIER
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
|
|
|
const IDENTIFIER_COMPOSITE = 4;
|
|
|
|
|
2007-12-20 01:41:11 +03:00
|
|
|
/**
|
2007-12-20 06:09:57 +03:00
|
|
|
* MODEL_LOADING_AGGRESSIVE
|
2007-12-20 01:41:11 +03:00
|
|
|
*
|
|
|
|
* Constant for agressive model loading
|
|
|
|
* Will require_once() all found model files
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_MODEL_LOADING
|
2007-12-20 01:41:11 +03:00
|
|
|
*/
|
2007-12-20 06:09:57 +03:00
|
|
|
const MODEL_LOADING_AGGRESSIVE = 1;
|
2007-12-20 01:41:11 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* MODEL_LOADING_CONSERVATIVE
|
|
|
|
*
|
|
|
|
* Constant for conservative model loading
|
|
|
|
* Will not require_once() found model files inititally instead it will build an array
|
|
|
|
* and reference it in autoload() when a class is needed it will require_once() it
|
2008-01-06 12:47:00 +03:00
|
|
|
*
|
|
|
|
* @see self::ATTR_MODEL_LOADING
|
2007-12-20 01:41:11 +03:00
|
|
|
*/
|
2008-03-17 16:26:34 +03:00
|
|
|
const MODEL_LOADING_CONSERVATIVE = 2;
|
2008-01-05 22:14:35 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* INHERITANCE TYPE CONSTANTS.
|
|
|
|
*/
|
2008-03-23 14:30:29 +03:00
|
|
|
const INHERITANCE_TYPE_NONE = 0;
|
|
|
|
|
2008-01-06 12:47:00 +03:00
|
|
|
/**
|
|
|
|
* Constant for Single Table Inheritance.
|
2007-11-14 16:13:23 +03:00
|
|
|
*
|
2008-01-06 12:47:00 +03:00
|
|
|
* @see http://martinfowler.com/eaaCatalog/singleTableInheritance.html
|
|
|
|
*/
|
2008-03-23 14:30:29 +03:00
|
|
|
const INHERITANCE_TYPE_SINGLE_TABLE = 1;
|
2008-01-06 12:47:00 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constant for Class Table Inheritance.
|
|
|
|
*
|
|
|
|
* @see http://martinfowler.com/eaaCatalog/classTableInheritance.html
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
2008-03-23 14:30:29 +03:00
|
|
|
const INHERITANCE_TYPE_JOINED = 2;
|
2008-01-06 12:47:00 +03:00
|
|
|
|
2008-01-05 22:14:35 +03:00
|
|
|
/**
|
2008-01-06 12:47:00 +03:00
|
|
|
* Constant for Concrete Table Inheritance.
|
2008-01-05 22:14:35 +03:00
|
|
|
*
|
2008-01-06 12:47:00 +03:00
|
|
|
* @see http://martinfowler.com/eaaCatalog/concreteTableInheritance.html
|
|
|
|
*/
|
2008-03-23 14:30:29 +03:00
|
|
|
const INHERITANCE_TYPE_TABLE_PER_CLASS = 3;
|
2008-03-17 16:26:34 +03:00
|
|
|
|
2008-01-06 12:47:00 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Path
|
2008-01-05 22:14:35 +03:00
|
|
|
*
|
2008-01-06 12:47:00 +03:00
|
|
|
* @var string $path doctrine root directory
|
2008-01-05 22:14:35 +03:00
|
|
|
*/
|
2008-01-06 12:47:00 +03:00
|
|
|
private static $_path;
|
2008-01-05 22:14:35 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
/**
|
2007-11-27 21:23:13 +03:00
|
|
|
* _loadedModelFiles
|
2007-11-22 16:40:22 +03:00
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* Array of all the loaded models and the path to each one for autoloading
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2007-11-27 21:23:13 +03:00
|
|
|
private static $_loadedModelFiles = array();
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2008-01-25 06:18:51 +03:00
|
|
|
private static $_pathModels = array();
|
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
/**
|
|
|
|
* __construct
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @throws Doctrine_Exception
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
throw new Doctrine_Exception('Doctrine is static class. No instances can be created.');
|
|
|
|
}
|
2008-01-25 06:18:51 +03:00
|
|
|
|
|
|
|
public static function getLoadedModelFiles()
|
|
|
|
{
|
|
|
|
return self::$_loadedModelFiles;
|
|
|
|
}
|
2008-01-06 12:47:00 +03:00
|
|
|
|
2008-01-25 06:18:51 +03:00
|
|
|
public static function getPathModels()
|
|
|
|
{
|
|
|
|
return self::$_pathModels;
|
|
|
|
}
|
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
/**
|
|
|
|
* getPath
|
|
|
|
* returns the doctrine root
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getPath()
|
|
|
|
{
|
|
|
|
if ( ! self::$_path) {
|
|
|
|
self::$_path = dirname(__FILE__);
|
|
|
|
}
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
return self::$_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* loadModels
|
|
|
|
*
|
|
|
|
* Recursively load all models from a directory or array of directories
|
2007-11-22 16:40:22 +03:00
|
|
|
*
|
|
|
|
* @param string $directory Path to directory of models or array of directory paths
|
2007-11-14 16:13:23 +03:00
|
|
|
* @return array $loadedModels
|
|
|
|
*/
|
2008-01-03 23:14:50 +03:00
|
|
|
public static function loadModels($directory)
|
2007-11-14 16:13:23 +03:00
|
|
|
{
|
2007-12-20 01:41:11 +03:00
|
|
|
$loadedModels = array();
|
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
if ($directory !== null) {
|
|
|
|
$manager = Doctrine_Manager::getInstance();
|
2007-12-20 01:41:11 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
foreach ((array) $directory as $dir) {
|
|
|
|
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir),
|
|
|
|
RecursiveIteratorIterator::LEAVES_ONLY);
|
|
|
|
foreach ($it as $file) {
|
|
|
|
$e = explode('.', $file->getFileName());
|
|
|
|
if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) {
|
2007-12-20 01:41:11 +03:00
|
|
|
|
2008-01-06 12:47:00 +03:00
|
|
|
if ($manager->getAttribute(Doctrine::ATTR_MODEL_LOADING) === Doctrine::MODEL_LOADING_CONSERVATIVE) {
|
2007-12-20 01:41:11 +03:00
|
|
|
self::$_loadedModelFiles[$e[0]] = $file->getPathName();
|
2008-01-25 06:18:51 +03:00
|
|
|
self::$_pathModels[$file->getPathName()][$e[0]] = $e[0];
|
|
|
|
|
2007-12-20 01:41:11 +03:00
|
|
|
$loadedModels[] = $e[0];
|
|
|
|
} else {
|
|
|
|
$declaredBefore = get_declared_classes();
|
|
|
|
require_once($file->getPathName());
|
|
|
|
|
|
|
|
$declaredAfter = get_declared_classes();
|
|
|
|
// Using array_slice because array_diff is broken is some PHP versions
|
|
|
|
$foundClasses = array_slice($declaredAfter, count($declaredBefore) - 1);
|
|
|
|
if ($foundClasses) {
|
|
|
|
foreach ($foundClasses as $className) {
|
|
|
|
if (self::isValidModelClass($className) && !in_array($className, $loadedModels)) {
|
|
|
|
$loadedModels[] = $className;
|
2008-01-25 06:18:51 +03:00
|
|
|
|
|
|
|
self::$_pathModels[$file->getPathName()][$className] = $className;
|
2007-12-20 01:41:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-11-27 21:23:13 +03:00
|
|
|
}
|
2007-11-14 16:13:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-19 03:24:32 +03:00
|
|
|
// We do not want to filter invalid models when using conservative model loading
|
|
|
|
// The filtering requires that the class be loaded and inflected in order to determine if it is
|
|
|
|
// a valid class.
|
|
|
|
if ($manager->getAttribute(Doctrine::ATTR_MODEL_LOADING) == Doctrine::MODEL_LOADING_CONSERVATIVE) {
|
|
|
|
return $loadedModels;
|
|
|
|
} else {
|
|
|
|
return self::filterInvalidModels($loadedModels);
|
|
|
|
}
|
2007-11-14 16:13:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getLoadedModels
|
|
|
|
*
|
|
|
|
* Get all the loaded models, you can provide an array of classes or it will use get_declared_classes()
|
2007-11-22 16:40:22 +03:00
|
|
|
*
|
2008-05-14 01:20:34 +04:00
|
|
|
* Will filter through an array of classes and return the Doctrine_Entitys out of them.
|
|
|
|
* If you do not specify $classes it will return all of the currently loaded Doctrine_Entitys
|
2007-11-14 16:13:23 +03:00
|
|
|
*
|
2007-11-22 16:40:22 +03:00
|
|
|
* @return array $loadedModels
|
2007-11-14 16:13:23 +03:00
|
|
|
*/
|
2008-01-06 12:47:00 +03:00
|
|
|
public static function getLoadedModels()
|
2007-11-14 16:13:23 +03:00
|
|
|
{
|
2008-01-06 12:47:00 +03:00
|
|
|
$classes = get_declared_classes();
|
|
|
|
$classes = array_merge($classes, array_keys(self::$_loadedModelFiles));
|
2007-12-20 01:41:11 +03:00
|
|
|
|
2007-11-27 21:23:13 +03:00
|
|
|
return self::filterInvalidModels($classes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* filterInvalidModels
|
|
|
|
*
|
|
|
|
* Filter through an array of classes and return all the classes that are valid models
|
2008-02-19 03:24:32 +03:00
|
|
|
* This will inflect the class, causing it to be loaded in to memory.
|
2007-11-27 21:23:13 +03:00
|
|
|
*
|
|
|
|
* @param classes Array of classes to filter through, otherwise uses get_declared_classes()
|
|
|
|
* @return array $loadedModels
|
|
|
|
*/
|
|
|
|
public static function filterInvalidModels($classes)
|
|
|
|
{
|
|
|
|
$validModels = array();
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
foreach ((array) $classes as $name) {
|
2007-11-27 21:23:13 +03:00
|
|
|
if (self::isValidModelClass($name) && !in_array($name, $validModels)) {
|
|
|
|
$validModels[] = $name;
|
2007-11-22 16:40:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-27 21:23:13 +03:00
|
|
|
return $validModels;
|
|
|
|
}
|
2007-11-22 16:40:22 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* isValidModelClass
|
|
|
|
*
|
2008-05-14 01:20:34 +04:00
|
|
|
* Checks if what is passed is a valid Doctrine_Entity
|
2008-02-19 03:24:32 +03:00
|
|
|
* Will load class in to memory in order to inflect it and find out information about the class
|
2007-11-22 16:40:22 +03:00
|
|
|
*
|
2007-11-27 21:23:13 +03:00
|
|
|
* @param mixed $class Can be a string named after the class, an instance of the class, or an instance of the class reflected
|
|
|
|
* @return boolean
|
2007-11-22 16:40:22 +03:00
|
|
|
*/
|
|
|
|
public static function isValidModelClass($class)
|
|
|
|
{
|
2008-05-14 01:20:34 +04:00
|
|
|
if ($class instanceof Doctrine_Entity) {
|
2007-11-27 21:23:13 +03:00
|
|
|
$class = get_class($class);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_string($class) && class_exists($class)) {
|
|
|
|
$class = new ReflectionClass($class);
|
|
|
|
}
|
|
|
|
|
2007-11-22 16:40:22 +03:00
|
|
|
if ($class instanceof ReflectionClass) {
|
2007-11-14 16:13:23 +03:00
|
|
|
// Skip the following classes
|
|
|
|
// - abstract classes
|
2008-05-14 01:20:34 +04:00
|
|
|
// - not a subclass of Doctrine_Entity
|
2007-11-14 16:13:23 +03:00
|
|
|
// - don't have a setTableDefinition method
|
2007-11-22 16:40:22 +03:00
|
|
|
if (!$class->isAbstract() &&
|
2008-05-14 01:20:34 +04:00
|
|
|
$class->isSubClassOf('Doctrine_Entity')) {
|
2007-11-27 21:23:13 +03:00
|
|
|
|
2007-11-22 16:40:22 +03:00
|
|
|
return true;
|
2007-11-14 16:13:23 +03:00
|
|
|
}
|
|
|
|
}
|
2007-11-27 21:23:13 +03:00
|
|
|
|
2007-11-22 16:40:22 +03:00
|
|
|
return false;
|
2007-11-14 16:13:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getConnectionByTableName
|
|
|
|
*
|
|
|
|
* Get the connection object for a table by the actual table name
|
2007-11-22 16:40:22 +03:00
|
|
|
*
|
|
|
|
* @param string $tableName
|
2007-11-14 16:13:23 +03:00
|
|
|
* @return object Doctrine_Connection
|
|
|
|
*/
|
|
|
|
public static function getConnectionByTableName($tableName)
|
|
|
|
{
|
|
|
|
$loadedModels = self::getLoadedModels();
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
foreach ($loadedModels as $name) {
|
|
|
|
$model = new $name();
|
|
|
|
$table = $model->getTable();
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
if ($table->getTableName() == $tableName) {
|
2007-11-22 16:40:22 +03:00
|
|
|
return $table->getConnection();
|
2007-11-14 16:13:23 +03:00
|
|
|
}
|
|
|
|
}
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
return Doctrine_Manager::connection();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* generateModelsFromDb
|
|
|
|
*
|
2008-05-14 01:20:34 +04:00
|
|
|
* method for importing existing schema to Doctrine_Entity classes
|
2007-11-14 16:13:23 +03:00
|
|
|
*
|
|
|
|
* @param string $directory Directory to write your models to
|
|
|
|
* @param array $databases Array of databases to generate models for
|
|
|
|
* @return boolean
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public static function generateModelsFromDb($directory, array $databases = array())
|
|
|
|
{
|
|
|
|
return Doctrine_Manager::connection()->import->importSchema($directory, $databases);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* generateYamlFromDb
|
|
|
|
*
|
|
|
|
* Generates models from database to temporary location then uses those models to generate a yaml schema file.
|
|
|
|
* This should probably be fixed. We should write something to generate a yaml schema file directly from the database.
|
|
|
|
*
|
|
|
|
* @param string $yamlPath Path to write oyur yaml schema file to
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function generateYamlFromDb($yamlPath)
|
|
|
|
{
|
2008-01-06 12:47:00 +03:00
|
|
|
$directory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tmp_doctrine_models';
|
2007-11-14 16:13:23 +03:00
|
|
|
|
|
|
|
Doctrine::generateModelsFromDb($directory);
|
|
|
|
|
|
|
|
$export = new Doctrine_Export_Schema();
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
$result = $export->exportSchema($yamlPath, 'yml', $directory);
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-12-08 01:48:28 +03:00
|
|
|
Doctrine_Lib::removeDirectories($directory);
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* generateModelsFromYaml
|
|
|
|
*
|
|
|
|
* Generate a yaml schema file from an existing directory of models
|
|
|
|
*
|
|
|
|
* @param string $yamlPath Path to your yaml schema files
|
|
|
|
* @param string $directory Directory to generate your models in
|
|
|
|
* @param array $options Array of options to pass to the schema importer
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function generateModelsFromYaml($yamlPath, $directory, $options = array())
|
|
|
|
{
|
|
|
|
$import = new Doctrine_Import_Schema();
|
|
|
|
$import->setOptions($options);
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
return $import->importSchema($yamlPath, 'yml', $directory);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* createTablesFromModels
|
|
|
|
*
|
|
|
|
* Creates database tables for the models in the specified directory
|
|
|
|
*
|
|
|
|
* @param string $directory Directory containing your models
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function createTablesFromModels($directory = null)
|
|
|
|
{
|
|
|
|
return Doctrine_Manager::connection()->export->exportSchema($directory);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* createTablesFromArray
|
|
|
|
*
|
|
|
|
* Creates database tables for the models in the supplied array
|
|
|
|
*
|
|
|
|
* @param array $array An array of models to be exported
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function createTablesFromArray($array)
|
|
|
|
{
|
|
|
|
return Doctrine_Manager::connection()->export->exportClasses($array);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* generateSqlFromModels
|
|
|
|
*
|
2007-11-22 16:40:22 +03:00
|
|
|
* @param string $directory
|
2007-11-14 16:13:23 +03:00
|
|
|
* @return string $build String of sql queries. One query per line
|
|
|
|
*/
|
|
|
|
public static function generateSqlFromModels($directory = null)
|
|
|
|
{
|
|
|
|
$sql = Doctrine_Manager::connection()->export->exportSql($directory);
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
$build = '';
|
|
|
|
foreach ($sql as $query) {
|
|
|
|
$build .= $query.";\n";
|
|
|
|
}
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
return $build;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* generateYamlFromModels
|
|
|
|
*
|
|
|
|
* Generate yaml schema file for the models in the specified directory
|
|
|
|
*
|
|
|
|
* @param string $yamlPath Path to your yaml schema files
|
|
|
|
* @param string $directory Directory to generate your models in
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function generateYamlFromModels($yamlPath, $directory)
|
|
|
|
{
|
|
|
|
$export = new Doctrine_Export_Schema();
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
return $export->exportSchema($yamlPath, 'yml', $directory);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* createDatabases
|
|
|
|
*
|
|
|
|
* Creates databases for connections
|
|
|
|
*
|
|
|
|
* @param string $specifiedConnections Array of connections you wish to create the database for
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function createDatabases($specifiedConnections = array())
|
|
|
|
{
|
2008-01-23 00:42:17 +03:00
|
|
|
return Doctrine_Manager::getInstance()->createDatabases($specifiedConnections);
|
2007-11-14 16:13:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dropDatabases
|
|
|
|
*
|
|
|
|
* Drops databases for connections
|
|
|
|
*
|
|
|
|
* @param string $specifiedConnections Array of connections you wish to drop the database for
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function dropDatabases($specifiedConnections = array())
|
|
|
|
{
|
2008-01-23 00:42:17 +03:00
|
|
|
return Doctrine_Manager::getInstance()->dropDatabases($specifiedConnections);
|
2007-11-14 16:13:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dumpData
|
|
|
|
*
|
|
|
|
* Dump data to a yaml fixtures file
|
|
|
|
*
|
|
|
|
* @param string $yamlPath Path to write the yaml data fixtures to
|
|
|
|
* @param string $individualFiles Whether or not to dump data to individual fixtures files
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function dumpData($yamlPath, $individualFiles = false)
|
|
|
|
{
|
|
|
|
$data = new Doctrine_Data();
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
return $data->exportData($yamlPath, 'yml', array(), $individualFiles);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* loadData
|
|
|
|
*
|
|
|
|
* Load data from a yaml fixtures file.
|
|
|
|
* The output of dumpData can be fed to loadData
|
|
|
|
*
|
|
|
|
* @param string $yamlPath Path to your yaml data fixtures
|
|
|
|
* @param string $append Whether or not to append the data
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function loadData($yamlPath, $append = false)
|
|
|
|
{
|
|
|
|
$data = new Doctrine_Data();
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
if ( ! $append) {
|
|
|
|
$data->purge();
|
|
|
|
}
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
return $data->importData($yamlPath, 'yml');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* migrate
|
2007-11-22 16:40:22 +03:00
|
|
|
*
|
2007-11-14 16:13:23 +03:00
|
|
|
* Migrate database to specified $to version. Migrates from current to latest if you do not specify.
|
|
|
|
*
|
|
|
|
* @param string $migrationsPath Path to migrations directory which contains your migration classes
|
|
|
|
* @param string $to Version you wish to migrate to.
|
|
|
|
* @return bool true
|
|
|
|
* @throws new Doctrine_Migration_Exception
|
|
|
|
*/
|
|
|
|
public static function migrate($migrationsPath, $to = null)
|
|
|
|
{
|
|
|
|
$migration = new Doctrine_Migration($migrationsPath);
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
return $migration->migrate($to);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* generateMigrationClass
|
|
|
|
*
|
|
|
|
* Generate new migration class skeleton
|
|
|
|
*
|
|
|
|
* @param string $className Name of the Migration class to generate
|
|
|
|
* @param string $migrationsPath Path to directory which contains your migration classes
|
|
|
|
*/
|
|
|
|
public static function generateMigrationClass($className, $migrationsPath)
|
|
|
|
{
|
2008-01-23 19:47:58 +03:00
|
|
|
$builder = new Doctrine_Builder_Migration($migrationsPath);
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
return $builder->generateMigrationClass($className);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* generateMigrationsFromDb
|
|
|
|
*
|
2007-11-22 16:40:22 +03:00
|
|
|
* @param string $migrationsPath
|
2007-11-14 16:13:23 +03:00
|
|
|
* @return void
|
|
|
|
* @throws new Doctrine_Migration_Exception
|
|
|
|
*/
|
|
|
|
public static function generateMigrationsFromDb($migrationsPath)
|
|
|
|
{
|
2008-01-23 19:47:58 +03:00
|
|
|
$builder = new Doctrine_Builder_Migration($migrationsPath);
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
return $builder->generateMigrationsFromDb();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* generateMigrationsFromModels
|
|
|
|
*
|
2007-11-22 16:40:22 +03:00
|
|
|
* @param string $migrationsPath
|
|
|
|
* @param string $modelsPath
|
2007-11-14 16:13:23 +03:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function generateMigrationsFromModels($migrationsPath, $modelsPath = null)
|
|
|
|
{
|
2008-01-23 19:47:58 +03:00
|
|
|
$builder = new Doctrine_Builder_Migration($migrationsPath);
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
return $builder->generateMigrationsFromModels($modelsPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getTable
|
|
|
|
*
|
2007-11-22 16:40:22 +03:00
|
|
|
* @param string $tableName
|
2007-11-14 16:13:23 +03:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function getTable($tableName)
|
|
|
|
{
|
|
|
|
return Doctrine_Manager::table($tableName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* autoload
|
|
|
|
*
|
|
|
|
* simple autoload function
|
|
|
|
* returns true if the class was loaded, otherwise false
|
|
|
|
*
|
|
|
|
* @param string $classname
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static function autoload($className)
|
|
|
|
{
|
2008-01-05 22:14:35 +03:00
|
|
|
if (class_exists($className, false) || interface_exists($className, false)) {
|
2007-11-14 16:13:23 +03:00
|
|
|
return false;
|
|
|
|
}
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
if ( ! self::$_path) {
|
|
|
|
self::$_path = dirname(__FILE__);
|
|
|
|
}
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2008-01-05 22:14:35 +03:00
|
|
|
$class = self::$_path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
|
2008-01-06 12:47:00 +03:00
|
|
|
|
2008-01-05 22:14:35 +03:00
|
|
|
if (file_exists($class)) {
|
2007-12-05 12:50:47 +03:00
|
|
|
require $class;
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
return true;
|
|
|
|
}
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2008-04-16 02:19:22 +04:00
|
|
|
/* TODO: Move the following code out of here. A generic Doctrine_Autoloader
|
|
|
|
class that can be configured in various ways might be a good idea.
|
|
|
|
Same goes for locate().*/
|
2007-11-27 21:23:13 +03:00
|
|
|
$loadedModels = self::$_loadedModelFiles;
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
if (isset($loadedModels[$className]) && file_exists($loadedModels[$className])) {
|
2007-12-05 12:50:47 +03:00
|
|
|
require_once $loadedModels[$className];
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-06 12:47:00 +03:00
|
|
|
|
|
|
|
public static function locate($name)
|
|
|
|
{
|
|
|
|
$findPattern = self::$_path . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, str_replace('Doctrine_', '', $name));
|
|
|
|
|
|
|
|
$matches = glob($findPattern);
|
|
|
|
|
|
|
|
if ( isset($matches[0])) {
|
|
|
|
return $matches[0];
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2007-11-14 16:13:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* dump
|
|
|
|
*
|
|
|
|
* dumps a given variable
|
|
|
|
*
|
|
|
|
* @param mixed $var a variable of any type
|
|
|
|
* @param boolean $output whether to output the content
|
|
|
|
* @param string $indent indention string
|
|
|
|
* @return void|string
|
|
|
|
*/
|
|
|
|
public static function dump($var, $output = true, $indent = "")
|
|
|
|
{
|
|
|
|
$ret = array();
|
|
|
|
switch (gettype($var)) {
|
|
|
|
case 'array':
|
|
|
|
$ret[] = 'Array(';
|
|
|
|
$indent .= " ";
|
|
|
|
foreach ($var as $k => $v) {
|
2007-11-22 16:40:22 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
$ret[] = $indent . $k . ' : ' . self::dump($v, false, $indent);
|
|
|
|
}
|
|
|
|
$indent = substr($indent,0, -4);
|
|
|
|
$ret[] = $indent . ")";
|
|
|
|
break;
|
|
|
|
case 'object':
|
|
|
|
$ret[] = 'Object(' . get_class($var) . ')';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$ret[] = var_export($var, true);
|
|
|
|
}
|
2007-11-28 05:21:42 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
if ($output) {
|
|
|
|
print implode("\n", $ret);
|
|
|
|
}
|
2007-11-28 05:21:42 +03:00
|
|
|
|
2007-11-14 16:13:23 +03:00
|
|
|
return implode("\n", $ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tableize
|
|
|
|
*
|
|
|
|
* returns table name from class name
|
|
|
|
*
|
|
|
|
* @param string $classname
|
|
|
|
* @return string
|
|
|
|
*/
|
2007-11-28 05:21:42 +03:00
|
|
|
public static function tableize($className)
|
2007-11-14 16:13:23 +03:00
|
|
|
{
|
2008-09-12 14:50:20 +04:00
|
|
|
return Doctrine_TODO_Inflector::tableize($className);
|
2007-11-14 16:13:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* classify
|
|
|
|
*
|
|
|
|
* returns class name from table name
|
|
|
|
*
|
|
|
|
* @param string $tablename
|
|
|
|
* @return string
|
|
|
|
*/
|
2007-11-27 06:45:30 +03:00
|
|
|
public static function classify($tableName)
|
2007-11-14 16:13:23 +03:00
|
|
|
{
|
2008-09-12 14:50:20 +04:00
|
|
|
return Doctrine_TODO_Inflector::classify($tableName);
|
2007-11-14 16:13:23 +03:00
|
|
|
}
|
2008-01-06 12:47:00 +03:00
|
|
|
}
|