Commit ce84fe38 authored by elliot's avatar elliot

Removed trailing whitespace

parent c8918b0d
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
require_once("Doctrine/Exception.php"); require_once("Doctrine/Exception.php");
/** /**
* Doctrine * Doctrine
* the base class of Doctrine framework * the base class of Doctrine framework
* *
* @package Doctrine * @package Doctrine
* @author Konsta Vesterinen * @author Konsta Vesterinen
* @license LGPL * @license LGPL
*/ */
final class Doctrine { final class Doctrine {
/** /**
* ERROR MODE CONSTANTS * ERROR MODE CONSTANTS
*/ */
/** /**
* NO PRIMARY KEY COLUMN ERROR * NO PRIMARY KEY COLUMN ERROR
* no primary key column found error code * no primary key column found error code
*/ */
const ERR_NO_PK = 0; const ERR_NO_PK = 0;
/** /**
* PRIMARY KEY MISMATCH ERROR * PRIMARY KEY MISMATCH ERROR
* this error code is used when user uses factory refresh for a * this error code is used when user uses factory refresh for a
* given Doctrine_Record and the old primary key doesn't match the new one * given Doctrine_Record and the old primary key doesn't match the new one
*/ */
const ERR_REFRESH = 1; const ERR_REFRESH = 1;
/** /**
* FIND ERROR * FIND ERROR
* this code used when for example Doctrine_Table::find() is called and * this code used when for example Doctrine_Table::find() is called and
* a Data Access Object is not found * a Data Access Object is not found
*/ */
const ERR_FIND = 2; const ERR_FIND = 2;
/** /**
* TABLE NOT FOUND ERROR * TABLE NOT FOUND ERROR
* this error code is used when user tries to initialize * this error code is used when user tries to initialize
* a table and there is no database table for this factory * a table and there is no database table for this factory
*/ */
const ERR_NOSUCH_TABLE = 3; const ERR_NOSUCH_TABLE = 3;
/** /**
* NAMING ERROR * NAMING ERROR
* this code is used when user defined Doctrine_Table is badly named * this code is used when user defined Doctrine_Table is badly named
*/ */
const ERR_NAMING = 5; const ERR_NAMING = 5;
/** /**
* TABLE INSTANCE ERROR * TABLE INSTANCE ERROR
* this code is used when user tries to initialize * this code is used when user tries to initialize
* a table that is already initialized * a table that is already initialized
*/ */
const ERR_TABLE_INSTANCE = 6; const ERR_TABLE_INSTANCE = 6;
/** /**
* NO OPEN SESSIONS ERROR * NO OPEN SESSIONS ERROR
* error code which is used when user tries to get * error code which is used when user tries to get
* current session are there are no sessions open * current session are there are no sessions open
*/ */
const ERR_NO_SESSIONS = 7; const ERR_NO_SESSIONS = 7;
/** /**
* MAPPING ERROR * MAPPING ERROR
* if there is something wrong with mapping logic * if there is something wrong with mapping logic
* this error code is used * this error code is used
*/ */
const ERR_MAPPING = 8; const ERR_MAPPING = 8;
/** /**
* ATTRIBUTE CONSTANTS * ATTRIBUTE CONSTANTS
*/ */
/** /**
* event listener attribute * event listener attribute
*/ */
const ATTR_LISTENER = 1; const ATTR_LISTENER = 1;
/** /**
* fetchmode attribute * fetchmode attribute
*/ */
const ATTR_FETCHMODE = 2; const ATTR_FETCHMODE = 2;
/** /**
* cache directory attribute * cache directory attribute
*/ */
const ATTR_CACHE_DIR = 3; const ATTR_CACHE_DIR = 3;
/** /**
* cache time to live attribute * cache time to live attribute
*/ */
const ATTR_CACHE_TTL = 4; const ATTR_CACHE_TTL = 4;
/** /**
* cache size attribute * cache size attribute
*/ */
const ATTR_CACHE_SIZE = 5; const ATTR_CACHE_SIZE = 5;
/** /**
* cache slam defense probability * cache slam defense probability
*/ */
const ATTR_CACHE_SLAM = 6; const ATTR_CACHE_SLAM = 6;
/** /**
* cache container attribute * cache container attribute
*/ */
const ATTR_CACHE = 7; const ATTR_CACHE = 7;
/** /**
* batch size attribute * batch size attribute
*/ */
const ATTR_BATCH_SIZE = 8; const ATTR_BATCH_SIZE = 8;
/** /**
* primary key columns attribute * primary key columns attribute
*/ */
const ATTR_PK_COLUMNS = 9; const ATTR_PK_COLUMNS = 9;
/** /**
* primary key type attribute * primary key type attribute
*/ */
const ATTR_PK_TYPE = 10; const ATTR_PK_TYPE = 10;
/** /**
* locking attribute * locking attribute
*/ */
const ATTR_LOCKMODE = 11; const ATTR_LOCKMODE = 11;
/** /**
* validatate attribute * validatate attribute
*/ */
const ATTR_VLD = 12; const ATTR_VLD = 12;
/** /**
* name prefix attribute * name prefix attribute
*/ */
const ATTR_NAME_PREFIX = 13; const ATTR_NAME_PREFIX = 13;
/** /**
* create tables attribute * create tables attribute
*/ */
const ATTR_CREATE_TABLES = 14; const ATTR_CREATE_TABLES = 14;
/** /**
* collection key attribute * collection key attribute
*/ */
const ATTR_COLL_KEY = 15; const ATTR_COLL_KEY = 15;
/** /**
* collection limit attribute * collection limit attribute
*/ */
const ATTR_COLL_LIMIT = 16; const ATTR_COLL_LIMIT = 16;
/** /**
* query limit * query limit
*/ */
const ATTR_QUERY_LIMIT = 17; const ATTR_QUERY_LIMIT = 17;
/** /**
* LIMIT CONSTANTS * LIMIT CONSTANTS
*/ */
/** /**
* constant for row limiting * constant for row limiting
*/ */
const LIMIT_ROWS = 1; const LIMIT_ROWS = 1;
/** /**
* constant for record limiting * constant for record limiting
*/ */
const LIMIT_RECORDS = 2; const LIMIT_RECORDS = 2;
/** /**
* CACHE CONSTANTS * CACHE CONSTANTS
*/ */
/** /**
* sqlite cache constant * sqlite cache constant
*/ */
const CACHE_SQLITE = 0; const CACHE_SQLITE = 0;
/** /**
* constant for disabling the caching * constant for disabling the caching
*/ */
const CACHE_NONE = 1; const CACHE_NONE = 1;
/** /**
* FETCHMODE CONSTANTS * FETCHMODE CONSTANTS
*/ */
/** /**
* IMMEDIATE FETCHING * IMMEDIATE FETCHING
* mode for immediate fetching * mode for immediate fetching
*/ */
const FETCH_IMMEDIATE = 0; const FETCH_IMMEDIATE = 0;
/** /**
* BATCH FETCHING * BATCH FETCHING
* mode for batch fetching * mode for batch fetching
*/ */
const FETCH_BATCH = 1; const FETCH_BATCH = 1;
/** /**
* LAZY FETCHING * LAZY FETCHING
* mode for lazy fetching * mode for lazy fetching
*/ */
const FETCH_LAZY = 2; const FETCH_LAZY = 2;
/** /**
* LAZY FETCHING * LAZY FETCHING
* mode for offset fetching * mode for offset fetching
*/ */
const FETCH_OFFSET = 3; const FETCH_OFFSET = 3;
/** /**
* LAZY OFFSET FETCHING * LAZY OFFSET FETCHING
* mode for lazy offset fetching * mode for lazy offset fetching
*/ */
const FETCH_LAZY_OFFSET = 4; const FETCH_LAZY_OFFSET = 4;
/** /**
* FETCH CONSTANTS * FETCH CONSTANTS
*/ */
/** /**
* FETCH VALUEHOLDER * FETCH VALUEHOLDER
*/ */
const FETCH_VHOLDER = 1; const FETCH_VHOLDER = 1;
/** /**
* FETCH 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.
*/ */
const FETCH_RECORD = 2; const FETCH_RECORD = 2;
/** /**
* FETCH ARRAY * FETCH ARRAY
*/ */
const FETCH_ARRAY = 3; const FETCH_ARRAY = 3;
/** /**
* FETCH COLUMN * FETCH COLUMN
* Specifies that the fetch method shall return only a single * Specifies that the fetch method shall return only a single
* requested column from the next row in the result set. * requested column from the next row in the result set.
* *
*/ */
const FETCH_COLUMN = 4; const FETCH_COLUMN = 4;
/** /**
* FETCH ASSOC * FETCH ASSOC
* *
* Specifies that the fetch method shall return each row as an * Specifies that the fetch method shall return each row as an
* array indexed by column name as returned in the corresponding * array indexed by column name as returned in the corresponding
* result set. If the result set contains multiple columns with * result set. If the result set contains multiple columns with
* the same name, PDO::FETCH_ASSOC returns only a single value per column name. * the same name, PDO::FETCH_ASSOC returns only a single value per column name.
* *
*/ */
const FETCH_ASSOC = 5; const FETCH_ASSOC = 5;
/** /**
* FETCH NAMED * FETCH NAMED
* *
* Specifies that the fetch method shall return each row as an array indexed * Specifies that the fetch method shall return each row as an array indexed
* by column name as returned in the corresponding result set. If the result set * by column name as returned in the corresponding result set. If the result set
* contains multiple columns with the same name, PDO::FETCH_NAMED returns an * contains multiple columns with the same name, PDO::FETCH_NAMED returns an
* array of values per column name. * array of values per column name.
* *
*/ */
const FETCH_NAMED = 6; const FETCH_NAMED = 6;
/** /**
* FETCH NUM * FETCH NUM
* *
* Specifies that the fetch method shall return each row as an array indexed by * Specifies that the fetch method shall return each row as an array indexed by
* column number as returned in the corresponding result set, starting at column 0. * column number as returned in the corresponding result set, starting at column 0.
*/ */
const FETCH_NUM = 7; const FETCH_NUM = 7;
/** /**
* FETCH BOTH * FETCH BOTH
* *
* Specifies that the fetch method shall return each row as an array indexed by both * Specifies that the fetch method shall return each row as an array indexed by both
* column name and number as returned in the corresponding result set, starting at column 0. * column name and number as returned in the corresponding result set, starting at column 0.
*/ */
const FETCH_BOTH = 8; const FETCH_BOTH = 8;
/** /**
* FETCH OBJ * FETCH OBJ
* *
* Specifies that the fetch method shall return each row as an object with property names * Specifies that the fetch method shall return each row as an object with property names
* that correspond to the column names returned in the result set. * that correspond to the column names returned in the result set.
*/ */
const FETCH_OBJ = 9; const FETCH_OBJ = 9;
/** /**
* LOCKMODE CONSTANTS * LOCKMODE CONSTANTS
*/ */
/** /**
* mode for optimistic locking * mode for optimistic locking
*/ */
const LOCK_OPTIMISTIC = 0; const LOCK_OPTIMISTIC = 0;
/** /**
* mode for pessimistic locking * mode for pessimistic locking
*/ */
const LOCK_PESSIMISTIC = 1; const LOCK_PESSIMISTIC = 1;
/** /**
* PRIMARY KEY TYPE CONSTANTS * PRIMARY KEY TYPE CONSTANTS
*/ */
/** /**
* auto-incremented/(sequence updated) primary key * auto-incremented/(sequence updated) primary key
*/ */
const INCREMENT_KEY = 0; const INCREMENT_KEY = 0;
/** /**
* unique key * unique key
*/ */
const UNIQUE_KEY = 1; const UNIQUE_KEY = 1;
/** /**
* constructor * constructor
*/ */
public function __construct() { public function __construct() {
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.');
} }
/** /**
* @var string $path doctrine root directory * @var string $path doctrine root directory
*/ */
private static $path; private static $path;
/** /**
* returns the doctrine root * returns the doctrine root
* *
* @return string * @return string
*/ */
public static function getPath() { public static function getPath() {
if(! self::$path) if(! self::$path)
self::$path = dirname(__FILE__); self::$path = dirname(__FILE__);
return self::$path; return self::$path;
} }
/** /**
* loads all runtime classes * loads all runtime classes
* *
* @return void * @return void
*/ */
public static function loadAll() { public static function loadAll() {
if(! self::$path) if(! self::$path)
self::$path = dirname(__FILE__); self::$path = dirname(__FILE__);
$path = self::$path.DIRECTORY_SEPARATOR."Doctrine"; $path = self::$path.DIRECTORY_SEPARATOR."Doctrine";
$dir = dir($path); $dir = dir($path);
$a = array(); $a = array();
while (false !== ($entry = $dir->read())) { while (false !== ($entry = $dir->read())) {
switch($entry): switch($entry):
case ".": case ".":
case "..": case "..":
break; break;
case "Cache": case "Cache":
case "Record": case "Record":
case "Collection": case "Collection":
case "Table": case "Table":
case "Validator": case "Validator":
case "Exception": case "Exception":
case "EventListener": case "EventListener":
case "Session": case "Session":
case "DQL": case "DQL":
case "Sensei": case "Sensei":
case "Iterator": case "Iterator":
case "View": case "View":
case "Query": case "Query":
$a[] = $path.DIRECTORY_SEPARATOR.$entry; $a[] = $path.DIRECTORY_SEPARATOR.$entry;
break; break;
default: default:
if(is_file($path.DIRECTORY_SEPARATOR.$entry) && substr($entry,-4) == ".php") { if(is_file($path.DIRECTORY_SEPARATOR.$entry) && substr($entry,-4) == ".php") {
require_once($path.DIRECTORY_SEPARATOR.$entry); require_once($path.DIRECTORY_SEPARATOR.$entry);
} }
endswitch; endswitch;
} }
foreach($a as $dirname) { foreach($a as $dirname) {
$dir = dir($dirname); $dir = dir($dirname);
$path = $dirname.DIRECTORY_SEPARATOR; $path = $dirname.DIRECTORY_SEPARATOR;
while (false !== ($entry = $dir->read())) { while (false !== ($entry = $dir->read())) {
if(is_file($path.$entry) && substr($entry,-4) == ".php") { if(is_file($path.$entry) && substr($entry,-4) == ".php") {
require_once($path.$entry); require_once($path.$entry);
} }
} }
} }
} }
/** /**
* method for making a single file of most used doctrine runtime components * method for making a single file of most used doctrine runtime components
* including the compiled file instead of multiple files (in worst * including the compiled file instead of multiple files (in worst
* cases dozens of files) can improve performance by an order of magnitude * cases dozens of files) can improve performance by an order of magnitude
* *
* @throws Doctrine_Exception * @throws Doctrine_Exception
* @return void * @return void
*/ */
public static function compile() { public static function compile() {
if(! self::$path) if(! self::$path)
self::$path = dirname(__FILE__); self::$path = dirname(__FILE__);
$classes = array("Doctrine", $classes = array("Doctrine",
"Configurable", "Configurable",
"Manager", "Manager",
"Session", "Session",
"Table", "Table",
"Iterator", "Iterator",
"Exception", "Exception",
"Access", "Access",
"Null", "Null",
"Record", "Record",
"Record_Iterator", "Record_Iterator",
"Collection", "Collection",
"Validator", "Validator",
"Hydrate", "Hydrate",
"Query", "Query",
"Query_Part", "Query_Part",
"Query_From", "Query_From",
"Query_Orderby", "Query_Orderby",
"Query_Groupby", "Query_Groupby",
"Query_Condition", "Query_Condition",
"Query_Where", "Query_Where",
"Query_Having", "Query_Having",
"RawSql", "RawSql",
"EventListener_Interface", "EventListener_Interface",
"EventListener", "EventListener",
"Relation", "Relation",
"ForeignKey", "ForeignKey",
"LocalKey", "LocalKey",
"Association", "Association",
"DB", "DB",
"DBStatement"); "DBStatement");
$ret = array(); $ret = array();
foreach($classes as $class) { foreach($classes as $class) {
if($class !== 'Doctrine') if($class !== 'Doctrine')
$class = 'Doctrine_'.$class; $class = 'Doctrine_'.$class;
$file = self::$path.DIRECTORY_SEPARATOR.str_replace("_",DIRECTORY_SEPARATOR,$class).".php"; $file = self::$path.DIRECTORY_SEPARATOR.str_replace("_",DIRECTORY_SEPARATOR,$class).".php";
if( ! file_exists($file)) if( ! file_exists($file))
throw new Doctrine_Exception("Couldn't compile $file. File $file does not exists."); throw new Doctrine_Exception("Couldn't compile $file. File $file does not exists.");
self::autoload($class); self::autoload($class);
$refl = new ReflectionClass ( $class ); $refl = new ReflectionClass ( $class );
$lines = file( $file ); $lines = file( $file );
$start = $refl -> getStartLine() - 1; $start = $refl -> getStartLine() - 1;
$end = $refl -> getEndLine(); $end = $refl -> getEndLine();
$ret = array_merge($ret, $ret = array_merge($ret,
array_slice($lines, array_slice($lines,
$start, $start,
($end - $start))); ($end - $start)));
} }
$file = self::$path.DIRECTORY_SEPARATOR.'Doctrine.compiled.php'; $file = self::$path.DIRECTORY_SEPARATOR.'Doctrine.compiled.php';
if (!is_writable($file)) if (!is_writable($file))
throw new Doctrine_Exception("Couldn't write compiled data. $file is not writable"); throw new Doctrine_Exception("Couldn't write compiled data. $file is not writable");
// first write the 'compiled' data to a text file, so // first write the 'compiled' data to a text file, so
// that we can use php_strip_whitespace (which only works on files) // that we can use php_strip_whitespace (which only works on files)
$fp = fopen($file, 'w'); $fp = fopen($file, 'w');
if ($fp === false) if ($fp === false)
throw new Doctrine_Exception("Couldn't write compiled data. Failed to open $file"); throw new Doctrine_Exception("Couldn't write compiled data. Failed to open $file");
fwrite($fp, "<?php". fwrite($fp, "<?php".
" class InvalidKeyException extends Exception { }". " class InvalidKeyException extends Exception { }".
" class DQLException extends Exception { }". " class DQLException extends Exception { }".
implode('', $ret) implode('', $ret)
); );
fclose($fp); fclose($fp);
$stripped = php_strip_whitespace( $file ); $stripped = php_strip_whitespace( $file );
$fp = fopen($file, 'w'); $fp = fopen($file, 'w');
if ($fp === false) if ($fp === false)
throw new Doctrine_Exception("Couldn't write compiled data. Failed to open $file"); throw new Doctrine_Exception("Couldn't write compiled data. Failed to open $file");
fwrite($fp, $stripped); fwrite($fp, $stripped);
fclose($fp); fclose($fp);
} }
/** /**
* simple autoload function * simple autoload function
* returns true if the class was loaded, otherwise false * returns true if the class was loaded, otherwise false
* *
* @param string $classname * @param string $classname
* @return boolean * @return boolean
*/ */
public static function autoload($classname) { public static function autoload($classname) {
if(! self::$path) if(! self::$path)
self::$path = dirname(__FILE__); self::$path = dirname(__FILE__);
if(class_exists($classname)) if(class_exists($classname))
return false; return false;
$class = self::$path.DIRECTORY_SEPARATOR.str_replace("_",DIRECTORY_SEPARATOR,$classname).".php"; $class = self::$path.DIRECTORY_SEPARATOR.str_replace("_",DIRECTORY_SEPARATOR,$classname).".php";
if( ! file_exists($class)) if( ! file_exists($class))
return false; return false;
require_once($class); require_once($class);
return true; return true;
} }
/** /**
* returns table name from class name * returns table name from class name
* *
* @param string $classname * @param string $classname
* @return string * @return string
*/ */
public static function tableize($classname) { public static function tableize($classname) {
return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $classname)); return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $classname));
} }
/** /**
* returns class name from table name * returns class name from table name
* *
* @param string $tablename * @param string $tablename
* @return string * @return string
*/ */
public static function classify($tablename) { public static function classify($tablename) {
return preg_replace('~(_?)(_)([\w])~e', '"$1".strtoupper("$3")', ucfirst($tablename)); return preg_replace('~(_?)(_)([\w])~e', '"$1".strtoupper("$3")', ucfirst($tablename));
} }
} }
?> ?>
\ 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