Commit 344ab02d authored by romanb's avatar romanb

reverting the reorganization done in 3455-3456 in order to make merging my...

reverting the reorganization done in 3455-3456 in order to make merging my experimental branch to trunk easier.
parent 60c92176
...@@ -33,25 +33,6 @@ ...@@ -33,25 +33,6 @@
*/ */
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
*/ */
...@@ -100,9 +81,9 @@ final class Doctrine ...@@ -100,9 +81,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;
...@@ -182,6 +163,7 @@ final class Doctrine ...@@ -182,6 +163,7 @@ 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;
...@@ -193,10 +175,12 @@ final class Doctrine ...@@ -193,10 +175,12 @@ 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;
...@@ -209,28 +193,20 @@ final class Doctrine ...@@ -209,28 +193,20 @@ 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;
/** /**
* QUERY_LIMIT CONSTANTS * LIMIT CONSTANTS
*/ */
/** /**
* QUERY_LIMIT_ROWS
*
* constant for row limiting * constant for row limiting
*
* @see self::ATTR_QUERY_LIMIT
*/ */
const QUERY_LIMIT_ROWS = 1; const LIMIT_ROWS = 1;
/** /**
* constant for record limiting * constant for record limiting
* @see self::ATTR_QUERY_LIMIT
*/ */
const QUERY_LIMIT_RECORDS = 2; const LIMIT_RECORDS = 2;
/** /**
* FETCHMODE CONSTANTS * FETCHMODE CONSTANTS
...@@ -239,163 +215,117 @@ final class Doctrine ...@@ -239,163 +215,117 @@ final class Doctrine
/** /**
* IMMEDIATE FETCHING * IMMEDIATE FETCHING
* mode for immediate fetching * mode for immediate fetching
* @see self::ATTR_FETCHMODE
*/ */
const FETCHMODE_IMMEDIATE = 0; const FETCH_IMMEDIATE = 0;
/** /**
* FETCHMODE_BATCH * BATCH FETCHING
*
* mode for batch fetching * mode for batch fetching
*
* @see self::ATTR_FETCHMODE
*/ */
const FETCHMODE_BATCH = 1; const FETCH_BATCH = 1;
/** /**
* FETCHMODE_OFFSET * LAZY FETCHING
*
* mode for offset fetching * mode for offset fetching
*
* @see self::ATTR_FETCHMODE
*/ */
const FETCHMODE_OFFSET = 3; const FETCH_OFFSET = 3;
/** /**
* FETCHMODE_LAZY_OFFSET * LAZY OFFSET FETCHING
*
* mode for lazy offset fetching * mode for lazy offset fetching
*
* @see self::ATTR_FETCHMODE
*/ */
const FETCHMODE_LAZY_OFFSET = 4; const FETCH_LAZY_OFFSET = 4;
/** /**
* FETCHMODE CONSTANTS * FETCH CONSTANTS
*/ */
/** /**
* FETCHMODE_VHOLDER * FETCH VALUEHOLDER
*
* @see self::ATTR_FETCHMODE
*/ */
const FETCHMODE_VHOLDER = 1; const FETCH_VHOLDER = 1;
/** /**
* FETCHMODE_RECORD * FETCH 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 FETCHMODE_RECORD = 2; const FETCH_RECORD = 2;
/** /**
* FETCHMODE_ARRAY * FETCH ARRAY
*
* @see self::ATTR_FETCHMODE
*/ */
const FETCHMODE_ARRAY = 3; const FETCH_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;
/** /**
* LOCK CONSTANTS * LOCKMODE 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;
...@@ -405,96 +335,66 @@ final class Doctrine ...@@ -405,96 +335,66 @@ 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;
/** /**
* HYDRATE CONSTANTS * HYDRATION 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;
/** /**
* VALIDATE CONSTANTS * VALIDATION 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;
...@@ -502,8 +402,6 @@ final class Doctrine ...@@ -502,8 +402,6 @@ 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;
...@@ -511,8 +409,6 @@ final class Doctrine ...@@ -511,8 +409,6 @@ 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;
...@@ -520,8 +416,6 @@ final class Doctrine ...@@ -520,8 +416,6 @@ 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;
...@@ -529,7 +423,6 @@ final class Doctrine ...@@ -529,7 +423,6 @@ 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;
...@@ -538,8 +431,6 @@ final class Doctrine ...@@ -538,8 +431,6 @@ 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;
...@@ -549,8 +440,6 @@ final class Doctrine ...@@ -549,8 +440,6 @@ 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;
...@@ -561,6 +450,15 @@ final class Doctrine ...@@ -561,6 +450,15 @@ final class Doctrine
*/ */
private static $_path; private static $_path;
/**
* Debug
*
* Bool true/false
*
* @var boolean $_debug
*/
private static $_debug = false;
/** /**
* _loadedModelFiles * _loadedModelFiles
* *
...@@ -570,6 +468,14 @@ final class Doctrine ...@@ -570,6 +468,14 @@ 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
* *
...@@ -581,6 +487,21 @@ final class Doctrine ...@@ -581,6 +487,21 @@ 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
...@@ -618,7 +539,7 @@ final class Doctrine ...@@ -618,7 +539,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 {
...@@ -652,12 +573,15 @@ final class Doctrine ...@@ -652,12 +573,15 @@ 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() public static function getLoadedModels($classes = null)
{ {
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);
} }
...@@ -767,7 +691,7 @@ final class Doctrine ...@@ -767,7 +691,7 @@ final class Doctrine
*/ */
public static function generateYamlFromDb($yamlPath) public static function generateYamlFromDb($yamlPath)
{ {
$directory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tmp_doctrine_models'; $directory = '/tmp/tmp_doctrine_models';
Doctrine::generateModelsFromDb($directory); Doctrine::generateModelsFromDb($directory);
...@@ -937,7 +861,7 @@ final class Doctrine ...@@ -937,7 +861,7 @@ final class Doctrine
} }
try { try {
$connection->export->dropDatabase($connection->getDatabaseName()); $connection->export->dropDatabase($name);
$results[$name] = true; $results[$name] = true;
} catch (Exception $e) { } catch (Exception $e) {
...@@ -1056,6 +980,34 @@ final class Doctrine ...@@ -1056,6 +980,34 @@ 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
* *
...@@ -1067,7 +1019,7 @@ final class Doctrine ...@@ -1067,7 +1019,7 @@ final class Doctrine
*/ */
public static function autoload($className) public static function autoload($className)
{ {
if ( substr($className, 0, 9) != 'Doctrine_' || class_exists($className, false) || interface_exists($className, false)) { if (class_exists($className, false) || interface_exists($className, false)) {
return false; return false;
} }
...@@ -1075,9 +1027,9 @@ final class Doctrine ...@@ -1075,9 +1027,9 @@ final class Doctrine
self::$_path = dirname(__FILE__); self::$_path = dirname(__FILE__);
} }
$class = self::locate($className . '.php'); $class = self::$_path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
if ($class && file_exists($class)) { if (file_exists($class)) {
require $class; require $class;
return true; return true;
...@@ -1094,19 +1046,6 @@ final class Doctrine ...@@ -1094,19 +1046,6 @@ final class Doctrine
return false; return false;
} }
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;
}
}
/** /**
* dump * dump
* *
...@@ -1170,4 +1109,17 @@ final class Doctrine ...@@ -1170,4 +1109,17 @@ 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);
}
} }
...@@ -329,7 +329,7 @@ class Doctrine_Lib ...@@ -329,7 +329,7 @@ class Doctrine_Lib
{ {
$validators = array(); $validators = array();
$dir = Doctrine::locate('Doctrine_Validator'); $dir = Doctrine::getPath() . DIRECTORY_SEPARATOR . 'Doctrine' . DIRECTORY_SEPARATOR . 'Validator';
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY); $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($files as $file) { foreach ($files as $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