Commit 44820ec1 authored by Jonathan.Wage's avatar Jonathan.Wage

Preparation for new organization of code in to sub packages. Changed...

Preparation for new organization of code in to sub packages. Changed autoload() to work with new structure.
parent 33223b5b
...@@ -33,6 +33,25 @@ ...@@ -33,6 +33,25 @@
*/ */
final class Doctrine final class Doctrine
{ {
/**
* 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;
/** /**
* VERSION * VERSION
*/ */
...@@ -81,9 +100,9 @@ final class Doctrine ...@@ -81,9 +100,9 @@ final class Doctrine
/** /**
* PDO derived constants * PDO derived constants
*/ */
const CASE_LOWER = 2;
const CASE_NATURAL = 0; const CASE_NATURAL = 0;
const CASE_UPPER = 1; const CASE_UPPER = 1;
const CASE_LOWER = 2;
const CURSOR_FWDONLY = 0; const CURSOR_FWDONLY = 0;
const CURSOR_SCROLL = 1; const CURSOR_SCROLL = 1;
const ERRMODE_EXCEPTION = 2; const ERRMODE_EXCEPTION = 2;
...@@ -163,7 +182,6 @@ final class Doctrine ...@@ -163,7 +182,6 @@ final class Doctrine
const ATTR_TBLNAME_FORMAT = 120; const ATTR_TBLNAME_FORMAT = 120;
const ATTR_EXPORT = 140; const ATTR_EXPORT = 140;
const ATTR_DECIMAL_PLACES = 141; const ATTR_DECIMAL_PLACES = 141;
const ATTR_PORTABILITY = 106; const ATTR_PORTABILITY = 106;
const ATTR_VALIDATE = 107; const ATTR_VALIDATE = 107;
const ATTR_COLL_KEY = 108; const ATTR_COLL_KEY = 108;
...@@ -175,12 +193,10 @@ final class Doctrine ...@@ -175,12 +193,10 @@ final class Doctrine
const ATTR_EMULATE_DATABASE = 116; const ATTR_EMULATE_DATABASE = 116;
const ATTR_USE_NATIVE_ENUM = 117; const ATTR_USE_NATIVE_ENUM = 117;
const ATTR_DEFAULT_SEQUENCE = 133; const ATTR_DEFAULT_SEQUENCE = 133;
const ATTR_FETCHMODE = 118; const ATTR_FETCHMODE = 118;
const ATTR_NAME_PREFIX = 121; const ATTR_NAME_PREFIX = 121;
const ATTR_CREATE_TABLES = 122; const ATTR_CREATE_TABLES = 122;
const ATTR_COLL_LIMIT = 123; const ATTR_COLL_LIMIT = 123;
const ATTR_CACHE = 150; const ATTR_CACHE = 150;
const ATTR_RESULT_CACHE = 150; const ATTR_RESULT_CACHE = 150;
const ATTR_CACHE_LIFESPAN = 151; const ATTR_CACHE_LIFESPAN = 151;
...@@ -193,20 +209,28 @@ final class Doctrine ...@@ -193,20 +209,28 @@ final class Doctrine
const ATTR_QUERY_CACHE_LIFESPAN = 158; const ATTR_QUERY_CACHE_LIFESPAN = 158;
const ATTR_AUTOLOAD_TABLE_CLASSES = 160; const ATTR_AUTOLOAD_TABLE_CLASSES = 160;
const ATTR_MODEL_LOADING = 161; const ATTR_MODEL_LOADING = 161;
const ATTR_LOCK = 162;
const ATTR_HYDRATE = 163;
const ATTR_IDENTIFIER = 164;
/** /**
* LIMIT CONSTANTS * QUERY_LIMIT CONSTANTS
*/ */
/** /**
* QUERY_LIMIT_ROWS
*
* constant for row limiting * constant for row limiting
*
* @see self::ATTR_QUERY_LIMIT
*/ */
const LIMIT_ROWS = 1; const QUERY_LIMIT_ROWS = 1;
/** /**
* constant for record limiting * constant for record limiting
* @see self::ATTR_QUERY_LIMIT
*/ */
const LIMIT_RECORDS = 2; const QUERY_LIMIT_RECORDS = 2;
/** /**
* FETCHMODE CONSTANTS * FETCHMODE CONSTANTS
...@@ -215,117 +239,163 @@ final class Doctrine ...@@ -215,117 +239,163 @@ final class Doctrine
/** /**
* IMMEDIATE FETCHING * IMMEDIATE FETCHING
* mode for immediate fetching * mode for immediate fetching
* @see self::ATTR_FETCHMODE
*/ */
const FETCH_IMMEDIATE = 0; const FETCHMODE_IMMEDIATE = 0;
/** /**
* BATCH FETCHING * FETCHMODE_BATCH
*
* mode for batch fetching * mode for batch fetching
*
* @see self::ATTR_FETCHMODE
*/ */
const FETCH_BATCH = 1; const FETCHMODE_BATCH = 1;
/** /**
* LAZY FETCHING * FETCHMODE_OFFSET
*
* mode for offset fetching * mode for offset fetching
*
* @see self::ATTR_FETCHMODE
*/ */
const FETCH_OFFSET = 3; const FETCHMODE_OFFSET = 3;
/** /**
* LAZY OFFSET FETCHING * FETCHMODE_LAZY_OFFSET
*
* mode for lazy offset fetching * mode for lazy offset fetching
*
* @see self::ATTR_FETCHMODE
*/ */
const FETCH_LAZY_OFFSET = 4; const FETCHMODE_LAZY_OFFSET = 4;
/** /**
* FETCH CONSTANTS * FETCHMODE CONSTANTS
*/ */
/** /**
* FETCH VALUEHOLDER * FETCHMODE_VHOLDER
*
* @see self::ATTR_FETCHMODE
*/ */
const FETCH_VHOLDER = 1; const FETCHMODE_VHOLDER = 1;
/** /**
* FETCH RECORD * FETCHMODE_RECORD
* *
* Specifies that the fetch method shall return Doctrine_Record * Specifies that the fetch method shall return Doctrine_Record
* objects as the elements of the result set. * objects as the elements of the result set.
* *
* This is the default fetchmode. * This is the default fetchmode.
*
* @see self::ATTR_FETCHMODE
*/ */
const FETCH_RECORD = 2; const FETCHMODE_RECORD = 2;
/** /**
* FETCH ARRAY * FETCHMODE_ARRAY
*
* @see self::ATTR_FETCHMODE
*/ */
const FETCH_ARRAY = 3; const FETCHMODE_ARRAY = 3;
/** /**
* PORTABILITY CONSTANTS * PORTABILITY CONSTANTS
*/ */
/** /**
* PORTABILITY_NONE
*
* Portability: turn off all portability features. * Portability: turn off all portability features.
*
* @see self::ATTR_PORTABILITY * @see self::ATTR_PORTABILITY
*/ */
const PORTABILITY_NONE = 0; const PORTABILITY_NONE = 0;
/** /**
* PORTABILITY_FIX_CASE
*
* Portability: convert names of tables and fields to case defined in the * Portability: convert names of tables and fields to case defined in the
* "field_case" option when using the query*(), fetch*() methods. * "field_case" option when using the query*(), fetch*() methods.
*
* @see self::ATTR_PORTABILITY * @see self::ATTR_PORTABILITY
*/ */
const PORTABILITY_FIX_CASE = 1; const PORTABILITY_FIX_CASE = 1;
/** /**
* PORTABILITY_RTRIM
*
* Portability: right trim the data output by query*() and fetch*(). * Portability: right trim the data output by query*() and fetch*().
*
* @see self::ATTR_PORTABILITY * @see self::ATTR_PORTABILITY
*/ */
const PORTABILITY_RTRIM = 2; const PORTABILITY_RTRIM = 2;
/** /**
* PORTABILITY_DELETE_COUNT
*
* Portability: force reporting the number of rows deleted. * Portability: force reporting the number of rows deleted.
*
* @see self::ATTR_PORTABILITY * @see self::ATTR_PORTABILITY
*/ */
const PORTABILITY_DELETE_COUNT = 4; const PORTABILITY_DELETE_COUNT = 4;
/** /**
* PORTABILITY_EMPTY_TO_NULL
*
* Portability: convert empty values to null strings in data output by * Portability: convert empty values to null strings in data output by
* query*() and fetch*(). * query*() and fetch*().
*
* @see self::ATTR_PORTABILITY * @see self::ATTR_PORTABILITY
*/ */
const PORTABILITY_EMPTY_TO_NULL = 8; const PORTABILITY_EMPTY_TO_NULL = 8;
/** /**
* PORTABILITY_FIX_ASSOC_FIELD_NAMES
*
* Portability: removes database/table qualifiers from associative indexes * Portability: removes database/table qualifiers from associative indexes
*
* @see self::ATTR_PORTABILITY * @see self::ATTR_PORTABILITY
*/ */
const PORTABILITY_FIX_ASSOC_FIELD_NAMES = 16; const PORTABILITY_FIX_ASSOC_FIELD_NAMES = 16;
/** /**
* PORTABILITY_EXPR
*
* Portability: makes Doctrine_Expression throw exception for unportable RDBMS expressions * Portability: makes Doctrine_Expression throw exception for unportable RDBMS expressions
*
* @see self::ATTR_PORTABILITY * @see self::ATTR_PORTABILITY
*/ */
const PORTABILITY_EXPR = 32; const PORTABILITY_EXPR = 32;
/** /**
* PORTABILITY_ALL
*
* Portability: turn on all portability features. * Portability: turn on all portability features.
*
* @see self::ATTR_PORTABILITY * @see self::ATTR_PORTABILITY
*/ */
const PORTABILITY_ALL = 63; const PORTABILITY_ALL = 63;
/** /**
* LOCKMODE CONSTANTS * LOCK CONSTANTS
*/ */
/** /**
* LOCK_OPTIMISTIC
*
* mode for optimistic locking * mode for optimistic locking
* @see self::ATTR_LOCK
*/ */
const LOCK_OPTIMISTIC = 0; const LOCK_OPTIMISTIC = 0;
/** /**
* LOCK_PESSIMISTIC
*
* mode for pessimistic locking * mode for pessimistic locking
*
* @see self::ATTR_LOCK
*/ */
const LOCK_PESSIMISTIC = 1; const LOCK_PESSIMISTIC = 1;
...@@ -335,66 +405,96 @@ final class Doctrine ...@@ -335,66 +405,96 @@ final class Doctrine
/** /**
* EXPORT_NONE * EXPORT_NONE
*
* @see self::ATTR_EXPORT
*/ */
const EXPORT_NONE = 0; const EXPORT_NONE = 0;
/** /**
* EXPORT_TABLES * EXPORT_TABLES
*
* @see self::ATTR_EXPORT
*/ */
const EXPORT_TABLES = 1; const EXPORT_TABLES = 1;
/** /**
* EXPORT_CONSTRAINTS * EXPORT_CONSTRAINTS
*
* @see self::ATTR_EXPORT
*/ */
const EXPORT_CONSTRAINTS = 2; const EXPORT_CONSTRAINTS = 2;
/** /**
* EXPORT_PLUGINS * EXPORT_PLUGINS
*
* @see self::ATTR_EXPORT
*/ */
const EXPORT_PLUGINS = 4; const EXPORT_PLUGINS = 4;
/** /**
* EXPORT_ALL * EXPORT_ALL
*
* @see self::ATTR_EXPORT
*/ */
const EXPORT_ALL = 7; const EXPORT_ALL = 7;
/** /**
* HYDRATION CONSTANTS * HYDRATE CONSTANTS
*/
/**
* HYDRATE_RECORD
*
* @see self::ATTR_HYDRATE
*/ */
const HYDRATE_RECORD = 2; const HYDRATE_RECORD = 2;
/** /**
* HYDRATE_ARRAY * HYDRATE_ARRAY
*
* @see self::ATTR_HYDRATE
*/ */
const HYDRATE_ARRAY = 3; const HYDRATE_ARRAY = 3;
/** /**
* HYDRATE_NONE * HYDRATE_NONE
*
* @see self::ATTR_HYDRATE
*/ */
const HYDRATE_NONE = 4; const HYDRATE_NONE = 4;
/** /**
* VALIDATION CONSTANTS * VALIDATE CONSTANTS
*
* @see self::ATTR_VALIDATE
*/ */
const VALIDATE_NONE = 0; const VALIDATE_NONE = 0;
/** /**
* VALIDATE_LENGTHS * VALIDATE_LENGTHS
*
* @see self::ATTR_VALIDATE
*/ */
const VALIDATE_LENGTHS = 1; const VALIDATE_LENGTHS = 1;
/** /**
* VALIDATE_TYPES * VALIDATE_TYPES
*
* @see self::ATTR_VALIDATE
*/ */
const VALIDATE_TYPES = 2; const VALIDATE_TYPES = 2;
/** /**
* VALIDATE_CONSTRAINTS * VALIDATE_CONSTRAINTS
*
* @see self::ATTR_VALIDATE
*/ */
const VALIDATE_CONSTRAINTS = 4; const VALIDATE_CONSTRAINTS = 4;
/** /**
* VALIDATE_ALL * VALIDATE_ALL
*
* @see self::ATTR_VALIDATE
*/ */
const VALIDATE_ALL = 7; const VALIDATE_ALL = 7;
...@@ -402,6 +502,8 @@ final class Doctrine ...@@ -402,6 +502,8 @@ final class Doctrine
* IDENTIFIER_AUTOINC * IDENTIFIER_AUTOINC
* *
* constant for auto_increment identifier * constant for auto_increment identifier
*
* @see self::ATTR_IDENTIFIER
*/ */
const IDENTIFIER_AUTOINC = 1; const IDENTIFIER_AUTOINC = 1;
...@@ -409,6 +511,8 @@ final class Doctrine ...@@ -409,6 +511,8 @@ final class Doctrine
* IDENTIFIER_SEQUENCE * IDENTIFIER_SEQUENCE
* *
* constant for sequence identifier * constant for sequence identifier
*
* @see self::ATTR_IDENTIFIER
*/ */
const IDENTIFIER_SEQUENCE = 2; const IDENTIFIER_SEQUENCE = 2;
...@@ -416,6 +520,8 @@ final class Doctrine ...@@ -416,6 +520,8 @@ final class Doctrine
* IDENTIFIER_NATURAL * IDENTIFIER_NATURAL
* *
* constant for normal identifier * constant for normal identifier
*
* @see self::ATTR_IDENTIFIER
*/ */
const IDENTIFIER_NATURAL = 3; const IDENTIFIER_NATURAL = 3;
...@@ -423,6 +529,7 @@ final class Doctrine ...@@ -423,6 +529,7 @@ final class Doctrine
* IDENTIFIER_COMPOSITE * IDENTIFIER_COMPOSITE
* *
* constant for composite identifier * constant for composite identifier
* @see self::ATTR_IDENTIFIER
*/ */
const IDENTIFIER_COMPOSITE = 4; const IDENTIFIER_COMPOSITE = 4;
...@@ -431,6 +538,8 @@ final class Doctrine ...@@ -431,6 +538,8 @@ final class Doctrine
* *
* Constant for agressive model loading * Constant for agressive model loading
* Will require_once() all found model files * Will require_once() all found model files
*
* @see self::ATTR_MODEL_LOADING
*/ */
const MODEL_LOADING_AGGRESSIVE = 1; const MODEL_LOADING_AGGRESSIVE = 1;
...@@ -440,6 +549,8 @@ final class Doctrine ...@@ -440,6 +549,8 @@ final class Doctrine
* Constant for conservative model loading * Constant for conservative model loading
* Will not require_once() found model files inititally instead it will build an array * 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 * and reference it in autoload() when a class is needed it will require_once() it
*
* @see self::ATTR_MODEL_LOADING
*/ */
const MODEL_LOADING_CONSERVATIVE= 2; const MODEL_LOADING_CONSERVATIVE= 2;
...@@ -450,15 +561,6 @@ final class Doctrine ...@@ -450,15 +561,6 @@ final class Doctrine
*/ */
private static $_path; private static $_path;
/**
* Debug
*
* Bool true/false
*
* @var boolean $_debug
*/
private static $_debug = false;
/** /**
* _loadedModelFiles * _loadedModelFiles
* *
...@@ -468,14 +570,6 @@ final class Doctrine ...@@ -468,14 +570,6 @@ final class Doctrine
*/ */
private static $_loadedModelFiles = array(); private static $_loadedModelFiles = array();
/**
* _validators
*
* Array of all the loaded validators
* @var array
*/
private static $_validators = array();
/** /**
* __construct * __construct
* *
...@@ -487,21 +581,6 @@ final class Doctrine ...@@ -487,21 +581,6 @@ final class Doctrine
throw new Doctrine_Exception('Doctrine is static class. No instances can be created.'); throw new Doctrine_Exception('Doctrine is static class. No instances can be created.');
} }
/**
* debug
*
* @param string $bool
* @return void
*/
public static function debug($bool = null)
{
if ($bool !== null) {
self::$_debug = (bool) $bool;
}
return self::$_debug;
}
/** /**
* getPath * getPath
* returns the doctrine root * returns the doctrine root
...@@ -539,7 +618,7 @@ final class Doctrine ...@@ -539,7 +618,7 @@ final class Doctrine
$e = explode('.', $file->getFileName()); $e = explode('.', $file->getFileName());
if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) { if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) {
if ($manager->getAttribute(Doctrine::ATTR_MODEL_LOADING) == Doctrine::MODEL_LOADING_CONSERVATIVE) { if ($manager->getAttribute(Doctrine::ATTR_MODEL_LOADING) === Doctrine::MODEL_LOADING_CONSERVATIVE) {
self::$_loadedModelFiles[$e[0]] = $file->getPathName(); self::$_loadedModelFiles[$e[0]] = $file->getPathName();
$loadedModels[] = $e[0]; $loadedModels[] = $e[0];
} else { } else {
...@@ -573,15 +652,12 @@ final class Doctrine ...@@ -573,15 +652,12 @@ final class Doctrine
* Will filter through an array of classes and return the Doctrine_Records out of them. * Will filter through an array of classes and return the Doctrine_Records out of them.
* If you do not specify $classes it will return all of the currently loaded Doctrine_Records * If you do not specify $classes it will return all of the currently loaded Doctrine_Records
* *
* @param classes Array of classes to filter through, otherwise uses get_declared_classes()
* @return array $loadedModels * @return array $loadedModels
*/ */
public static function getLoadedModels($classes = null) public static function getLoadedModels()
{ {
if ($classes === null) {
$classes = get_declared_classes(); $classes = get_declared_classes();
$classes = array_merge($classes, array_keys(self::$_loadedModelFiles)); $classes = array_merge($classes, array_keys(self::$_loadedModelFiles));
}
return self::filterInvalidModels($classes); return self::filterInvalidModels($classes);
} }
...@@ -691,7 +767,7 @@ final class Doctrine ...@@ -691,7 +767,7 @@ final class Doctrine
*/ */
public static function generateYamlFromDb($yamlPath) public static function generateYamlFromDb($yamlPath)
{ {
$directory = '/tmp/tmp_doctrine_models'; $directory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tmp_doctrine_models';
Doctrine::generateModelsFromDb($directory); Doctrine::generateModelsFromDb($directory);
...@@ -861,7 +937,7 @@ final class Doctrine ...@@ -861,7 +937,7 @@ final class Doctrine
} }
try { try {
$connection->export->dropDatabase($name); $connection->export->dropDatabase($connection->getDatabaseName());
$results[$name] = true; $results[$name] = true;
} catch (Exception $e) { } catch (Exception $e) {
...@@ -980,34 +1056,6 @@ final class Doctrine ...@@ -980,34 +1056,6 @@ final class Doctrine
return Doctrine_Manager::table($tableName); return Doctrine_Manager::table($tableName);
} }
/**
* fileFinder
*
* @param string $type
* @return void
*/
public static function fileFinder($type)
{
return Doctrine_FileFinder::type($type);
}
/**
* compile
*
* method for making a single file of most used doctrine runtime components
* including the compiled file instead of multiple files (in worst
* cases dozens of files) can improve performance by an order of magnitude
*
* @param string $target
* @param array $includedDrivers
* @throws Doctrine_Exception
* @return void
*/
public static function compile($target = null, $includedDrivers = array())
{
return Doctrine_Compiler::compile($target, $includedDrivers);
}
/** /**
* autoload * autoload
* *
...@@ -1019,7 +1067,7 @@ final class Doctrine ...@@ -1019,7 +1067,7 @@ final class Doctrine
*/ */
public static function autoload($className) public static function autoload($className)
{ {
if (class_exists($className, false) || interface_exists($className, false)) { if ( substr($className, 0, 9) != 'Doctrine_' || class_exists($className, false) || interface_exists($className, false)) {
return false; return false;
} }
...@@ -1027,7 +1075,15 @@ final class Doctrine ...@@ -1027,7 +1075,15 @@ final class Doctrine
self::$_path = dirname(__FILE__); self::$_path = dirname(__FILE__);
} }
$class = self::$_path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; $findPattern = self::$_path . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, str_replace('Doctrine_', '', $className)) . '.php';
$matches = glob($findPattern);
if ( ! isset($matches[0])) {
return false;
}
$class = $matches[0];
if (file_exists($class)) { if (file_exists($class)) {
require $class; require $class;
...@@ -1109,17 +1165,4 @@ final class Doctrine ...@@ -1109,17 +1165,4 @@ final class Doctrine
{ {
return Doctrine_Inflector::classify($tableName); return Doctrine_Inflector::classify($tableName);
} }
/**
* isValidClassName
*
* checks for valid class name (uses camel case and underscores)
*
* @param string $classname
* @return boolean
*/
public static function isValidClassname($className)
{
return Doctrine_Lib::isValidClassName($className);
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment