Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../var/softacul.../modx
File: xpdo.class.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
* OpenExpedio ("xPDO") is an ultra-light, PHP 5.2+ compatible ORB (Object-
[2] Fix | Delete
* Relational Bridge) library based around PDO (http://php.net/pdo/).
[3] Fix | Delete
*
[4] Fix | Delete
* Copyright 2010-2014 by MODX, LLC.
[5] Fix | Delete
*
[6] Fix | Delete
* This file is part of xPDO.
[7] Fix | Delete
*
[8] Fix | Delete
* xPDO is free software; you can redistribute it and/or modify it under the
[9] Fix | Delete
* terms of the GNU General Public License as published by the Free Software
[10] Fix | Delete
* Foundation; either version 2 of the License, or (at your option) any later
[11] Fix | Delete
* version.
[12] Fix | Delete
*
[13] Fix | Delete
* xPDO is distributed in the hope that it will be useful, but WITHOUT ANY
[14] Fix | Delete
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
[15] Fix | Delete
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
[16] Fix | Delete
*
[17] Fix | Delete
* You should have received a copy of the GNU General Public License along with
[18] Fix | Delete
* xPDO; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
[19] Fix | Delete
* Suite 330, Boston, MA 02111-1307 USA
[20] Fix | Delete
*/
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* This is the main file to include in your scripts to use xPDO.
[24] Fix | Delete
*
[25] Fix | Delete
* @author Jason Coward <xpdo@opengeek.com>
[26] Fix | Delete
* @copyright Copyright (C) 2006-2014, Jason Coward
[27] Fix | Delete
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License v2
[28] Fix | Delete
* @package xpdo
[29] Fix | Delete
*/
[30] Fix | Delete
[31] Fix | Delete
if (!defined('XPDO_PHP_VERSION')) {
[32] Fix | Delete
/**
[33] Fix | Delete
* Defines the PHP version string xPDO is running under.
[34] Fix | Delete
*/
[35] Fix | Delete
define('XPDO_PHP_VERSION', phpversion());
[36] Fix | Delete
}
[37] Fix | Delete
if (!defined('XPDO_CLI_MODE')) {
[38] Fix | Delete
if (php_sapi_name() == 'cli') {
[39] Fix | Delete
/**
[40] Fix | Delete
* This constant defines if xPDO is operating from the CLI.
[41] Fix | Delete
*/
[42] Fix | Delete
define('XPDO_CLI_MODE', true);
[43] Fix | Delete
} else {
[44] Fix | Delete
/** @ignore */
[45] Fix | Delete
define('XPDO_CLI_MODE', false);
[46] Fix | Delete
}
[47] Fix | Delete
}
[48] Fix | Delete
if (!defined('XPDO_CORE_PATH')) {
[49] Fix | Delete
/**
[50] Fix | Delete
* @internal This global variable is only used to set the {@link
[51] Fix | Delete
* XPDO_CORE_PATH} value upon initial include of this file. Not meant for
[52] Fix | Delete
* external use.
[53] Fix | Delete
* @var string
[54] Fix | Delete
* @access private
[55] Fix | Delete
*/
[56] Fix | Delete
$xpdo_core_path= strtr(realpath(dirname(__FILE__)), '\\', '/') . '/';
[57] Fix | Delete
/**
[58] Fix | Delete
* @var string The full path to the xPDO root directory.
[59] Fix | Delete
*
[60] Fix | Delete
* Use of this constant is recommended for use when building any path in
[61] Fix | Delete
* your xPDO code.
[62] Fix | Delete
*
[63] Fix | Delete
* @access public
[64] Fix | Delete
*/
[65] Fix | Delete
define('XPDO_CORE_PATH', $xpdo_core_path);
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
if (!class_exists('PDO')) {
[69] Fix | Delete
//@todo Handle PDO configuration errors here.
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
/**
[73] Fix | Delete
* A wrapper for PDO that powers an object-relational data model.
[74] Fix | Delete
*
[75] Fix | Delete
* xPDO provides centralized data access via a simple object-oriented API, to
[76] Fix | Delete
* a defined data structure. It provides the de facto methods for connecting
[77] Fix | Delete
* to a data source, getting persistence metadata for any class extended from
[78] Fix | Delete
* the {@link xPDOObject} class (core or custom), loading data source managers
[79] Fix | Delete
* when needed to manage table structures, and retrieving instances (or rows) of
[80] Fix | Delete
* any object in the model.
[81] Fix | Delete
*
[82] Fix | Delete
* Through various extensions, you can also reverse and forward engineer classes
[83] Fix | Delete
* and metadata maps for xPDO, have classes, models, and properties maintain
[84] Fix | Delete
* their own containers (databases, tables, columns, etc.) or changes to them,
[85] Fix | Delete
* and much more.
[86] Fix | Delete
*
[87] Fix | Delete
* @package xpdo
[88] Fix | Delete
*/
[89] Fix | Delete
class xPDO {
[90] Fix | Delete
/**#@+
[91] Fix | Delete
* Constants
[92] Fix | Delete
*/
[93] Fix | Delete
const OPT_AUTO_CREATE_TABLES = 'auto_create_tables';
[94] Fix | Delete
const OPT_BASE_CLASSES = 'base_classes';
[95] Fix | Delete
const OPT_BASE_PACKAGES = 'base_packages';
[96] Fix | Delete
const OPT_CACHE_COMPRESS = 'cache_compress';
[97] Fix | Delete
const OPT_CACHE_DB = 'cache_db';
[98] Fix | Delete
const OPT_CACHE_DB_COLLECTIONS = 'cache_db_collections';
[99] Fix | Delete
const OPT_CACHE_DB_OBJECTS_BY_PK = 'cache_db_objects_by_pk';
[100] Fix | Delete
const OPT_CACHE_DB_EXPIRES = 'cache_db_expires';
[101] Fix | Delete
const OPT_CACHE_DB_HANDLER = 'cache_db_handler';
[102] Fix | Delete
const OPT_CACHE_DB_SIG_CLASS = 'cache_db_sig_class';
[103] Fix | Delete
const OPT_CACHE_DB_SIG_GRAPH = 'cache_db_sig_graph';
[104] Fix | Delete
const OPT_CACHE_EXPIRES = 'cache_expires';
[105] Fix | Delete
const OPT_CACHE_FORMAT = 'cache_format';
[106] Fix | Delete
const OPT_CACHE_HANDLER = 'cache_handler';
[107] Fix | Delete
const OPT_CACHE_KEY = 'cache_key';
[108] Fix | Delete
const OPT_CACHE_PATH = 'cache_path';
[109] Fix | Delete
const OPT_CACHE_PREFIX = 'cache_prefix';
[110] Fix | Delete
const OPT_CACHE_ATTEMPTS = 'cache_attempts';
[111] Fix | Delete
const OPT_CACHE_ATTEMPT_DELAY = 'cache_attempt_delay';
[112] Fix | Delete
const OPT_CALLBACK_ON_REMOVE = 'callback_on_remove';
[113] Fix | Delete
const OPT_CALLBACK_ON_SAVE = 'callback_on_save';
[114] Fix | Delete
const OPT_CONNECTIONS = 'connections';
[115] Fix | Delete
const OPT_CONN_INIT = 'connection_init';
[116] Fix | Delete
const OPT_CONN_MUTABLE = 'connection_mutable';
[117] Fix | Delete
const OPT_HYDRATE_FIELDS = 'hydrate_fields';
[118] Fix | Delete
const OPT_HYDRATE_ADHOC_FIELDS = 'hydrate_adhoc_fields';
[119] Fix | Delete
const OPT_HYDRATE_RELATED_OBJECTS = 'hydrate_related_objects';
[120] Fix | Delete
const OPT_LOCKFILE_EXTENSION = 'lockfile_extension';
[121] Fix | Delete
const OPT_USE_FLOCK = 'use_flock';
[122] Fix | Delete
/**
[123] Fix | Delete
* @deprecated
[124] Fix | Delete
* @see call()
[125] Fix | Delete
*/
[126] Fix | Delete
const OPT_LOADER_CLASSES = 'loader_classes';
[127] Fix | Delete
const OPT_ON_SET_STRIPSLASHES = 'on_set_stripslashes';
[128] Fix | Delete
const OPT_SETUP = 'setup';
[129] Fix | Delete
const OPT_TABLE_PREFIX = 'table_prefix';
[130] Fix | Delete
const OPT_VALIDATE_ON_SAVE = 'validate_on_save';
[131] Fix | Delete
const OPT_VALIDATOR_CLASS = 'validator_class';
[132] Fix | Delete
[133] Fix | Delete
const LOG_LEVEL_FATAL = 0;
[134] Fix | Delete
const LOG_LEVEL_ERROR = 1;
[135] Fix | Delete
const LOG_LEVEL_WARN = 2;
[136] Fix | Delete
const LOG_LEVEL_INFO = 3;
[137] Fix | Delete
const LOG_LEVEL_DEBUG = 4;
[138] Fix | Delete
[139] Fix | Delete
const SCHEMA_VERSION = '1.1';
[140] Fix | Delete
[141] Fix | Delete
/**
[142] Fix | Delete
* @var PDO A reference to the PDO instance used by the current xPDOConnection.
[143] Fix | Delete
*/
[144] Fix | Delete
public $pdo= null;
[145] Fix | Delete
/**
[146] Fix | Delete
* @var array Configuration options for the xPDO instance.
[147] Fix | Delete
*/
[148] Fix | Delete
public $config= null;
[149] Fix | Delete
/**
[150] Fix | Delete
* @var xPDODriver An xPDODriver instance for the xPDOConnection instances to use.
[151] Fix | Delete
*/
[152] Fix | Delete
public $driver= null;
[153] Fix | Delete
/**
[154] Fix | Delete
* A map of data source meta data for all loaded classes.
[155] Fix | Delete
* @var array
[156] Fix | Delete
* @access public
[157] Fix | Delete
*/
[158] Fix | Delete
public $map= array ();
[159] Fix | Delete
/**
[160] Fix | Delete
* A default package for specifying classes by name.
[161] Fix | Delete
* @var string
[162] Fix | Delete
* @access public
[163] Fix | Delete
*/
[164] Fix | Delete
public $package= '';
[165] Fix | Delete
/**
[166] Fix | Delete
* An array storing packages and package-specific information.
[167] Fix | Delete
* @var array
[168] Fix | Delete
* @access public
[169] Fix | Delete
*/
[170] Fix | Delete
public $packages= array ();
[171] Fix | Delete
/**
[172] Fix | Delete
* {@link xPDOManager} instance, loaded only if needed to manage datasource
[173] Fix | Delete
* containers, data structures, etc.
[174] Fix | Delete
* @var xPDOManager
[175] Fix | Delete
* @access public
[176] Fix | Delete
*/
[177] Fix | Delete
public $manager= null;
[178] Fix | Delete
/**
[179] Fix | Delete
* @var xPDOCacheManager The cache service provider registered for this xPDO
[180] Fix | Delete
* instance.
[181] Fix | Delete
*/
[182] Fix | Delete
public $cacheManager= null;
[183] Fix | Delete
/**
[184] Fix | Delete
* @var string A root path for file-based caching services to use.
[185] Fix | Delete
*/
[186] Fix | Delete
private $cachePath= null;
[187] Fix | Delete
/**
[188] Fix | Delete
* @var array An array of supplemental service classes for this xPDO instance.
[189] Fix | Delete
*/
[190] Fix | Delete
public $services= array ();
[191] Fix | Delete
/**
[192] Fix | Delete
* @var float Start time of the request, initialized when the constructor is
[193] Fix | Delete
* called.
[194] Fix | Delete
*/
[195] Fix | Delete
public $startTime= 0;
[196] Fix | Delete
/**
[197] Fix | Delete
* @var int The number of direct DB queries executed during a request.
[198] Fix | Delete
*/
[199] Fix | Delete
public $executedQueries= 0;
[200] Fix | Delete
/**
[201] Fix | Delete
* @var int The amount of request handling time spent with DB queries.
[202] Fix | Delete
*/
[203] Fix | Delete
public $queryTime= 0;
[204] Fix | Delete
[205] Fix | Delete
public $classMap = array();
[206] Fix | Delete
[207] Fix | Delete
/**
[208] Fix | Delete
* @var xPDOConnection The current xPDOConnection for this xPDO instance.
[209] Fix | Delete
*/
[210] Fix | Delete
public $connection = null;
[211] Fix | Delete
/**
[212] Fix | Delete
* @var array PDO connections managed by this xPDO instance.
[213] Fix | Delete
*/
[214] Fix | Delete
private $_connections = array();
[215] Fix | Delete
[216] Fix | Delete
/**
[217] Fix | Delete
* @var integer The logging level for the xPDO instance.
[218] Fix | Delete
*/
[219] Fix | Delete
protected $logLevel= xPDO::LOG_LEVEL_FATAL;
[220] Fix | Delete
[221] Fix | Delete
/**
[222] Fix | Delete
* @var string The default logging target for the xPDO instance.
[223] Fix | Delete
*/
[224] Fix | Delete
protected $logTarget= 'ECHO';
[225] Fix | Delete
[226] Fix | Delete
/**
[227] Fix | Delete
* Indicates the debug state of this instance.
[228] Fix | Delete
* @var boolean Default is false.
[229] Fix | Delete
* @access protected
[230] Fix | Delete
*/
[231] Fix | Delete
protected $_debug= false;
[232] Fix | Delete
/**
[233] Fix | Delete
* A global cache flag that can be used to enable/disable all xPDO caching.
[234] Fix | Delete
* @var boolean All caching is disabled by default.
[235] Fix | Delete
* @access public
[236] Fix | Delete
*/
[237] Fix | Delete
public $_cacheEnabled= false;
[238] Fix | Delete
/**
[239] Fix | Delete
* Indicates the opening escape character used for a particular database engine.
[240] Fix | Delete
* @var string
[241] Fix | Delete
* @access public
[242] Fix | Delete
*/
[243] Fix | Delete
public $_escapeCharOpen= '';
[244] Fix | Delete
/**
[245] Fix | Delete
* Indicates the closing escape character used for a particular database engine.
[246] Fix | Delete
* @var string
[247] Fix | Delete
* @access public
[248] Fix | Delete
*/
[249] Fix | Delete
public $_escapeCharClose= '';
[250] Fix | Delete
[251] Fix | Delete
/**
[252] Fix | Delete
* Represents the character used for quoting strings for a particular driver.
[253] Fix | Delete
* @var string
[254] Fix | Delete
*/
[255] Fix | Delete
public $_quoteChar= "'";
[256] Fix | Delete
[257] Fix | Delete
/**
[258] Fix | Delete
* @var array A static collection of xPDO instances.
[259] Fix | Delete
*/
[260] Fix | Delete
protected static $instances = array();
[261] Fix | Delete
[262] Fix | Delete
/**
[263] Fix | Delete
* Create, retrieve, or update specific xPDO instances.
[264] Fix | Delete
*
[265] Fix | Delete
* @static
[266] Fix | Delete
* @param string|int|null $id An optional identifier for the instance. If not set
[267] Fix | Delete
* a uniqid will be generated and used as the key for the instance.
[268] Fix | Delete
* @param array|null $config An optional array of config data for the instance.
[269] Fix | Delete
* @param bool $forceNew If true a new instance will be created even if an instance
[270] Fix | Delete
* with the provided $id already exists in xPDO::$instances.
[271] Fix | Delete
* @throws xPDOException If a valid instance is not retrieved.
[272] Fix | Delete
* @return xPDO An instance of xPDO.
[273] Fix | Delete
*/
[274] Fix | Delete
public static function getInstance($id = null, $config = null, $forceNew = false) {
[275] Fix | Delete
$instances =& self::$instances;
[276] Fix | Delete
if (is_null($id)) {
[277] Fix | Delete
if (!is_null($config) || $forceNew || empty($instances)) {
[278] Fix | Delete
$id = uniqid(__CLASS__);
[279] Fix | Delete
} else {
[280] Fix | Delete
$id = key($instances);
[281] Fix | Delete
}
[282] Fix | Delete
}
[283] Fix | Delete
if ($forceNew || !array_key_exists($id, $instances) || !($instances[$id] instanceof xPDO)) {
[284] Fix | Delete
$instances[$id] = new xPDO(null, null, null, $config);
[285] Fix | Delete
} elseif ($instances[$id] instanceof xPDO && is_array($config)) {
[286] Fix | Delete
$instances[$id]->config = array_merge($instances[$id]->config, $config);
[287] Fix | Delete
}
[288] Fix | Delete
if (!($instances[$id] instanceof xPDO)) {
[289] Fix | Delete
throw new xPDOException("Error getting " . __CLASS__ . " instance, id = {$id}");
[290] Fix | Delete
}
[291] Fix | Delete
return $instances[$id];
[292] Fix | Delete
}
[293] Fix | Delete
[294] Fix | Delete
/**
[295] Fix | Delete
* The xPDO Constructor.
[296] Fix | Delete
*
[297] Fix | Delete
* This method is used to create a new xPDO object with a connection to a
[298] Fix | Delete
* specific database container.
[299] Fix | Delete
*
[300] Fix | Delete
* @param mixed $dsn A valid DSN connection string.
[301] Fix | Delete
* @param string $username The database username with proper permissions.
[302] Fix | Delete
* @param string $password The password for the database user.
[303] Fix | Delete
* @param array|string $options An array of xPDO options. For compatibility with previous
[304] Fix | Delete
* releases, this can also be a single string representing a prefix to be applied to all
[305] Fix | Delete
* database container (i. e. table) names, to isolate multiple installations or conflicting
[306] Fix | Delete
* table names that might need to coexist in a single database container. It is preferrable to
[307] Fix | Delete
* include the table_prefix option in the array for future compatibility.
[308] Fix | Delete
* @param array|null $driverOptions Driver-specific PDO options.
[309] Fix | Delete
* @throws xPDOException If an error occurs creating the instance.
[310] Fix | Delete
* @return xPDO A unique xPDO instance.
[311] Fix | Delete
*/
[312] Fix | Delete
public function __construct($dsn, $username= '', $password= '', $options= array(), $driverOptions= null) {
[313] Fix | Delete
try {
[314] Fix | Delete
$this->config = $this->initConfig($options);
[315] Fix | Delete
$this->setLogLevel($this->getOption('log_level', null, xPDO::LOG_LEVEL_FATAL, true));
[316] Fix | Delete
$this->setLogTarget($this->getOption('log_target', null, XPDO_CLI_MODE ? 'ECHO' : 'HTML', true));
[317] Fix | Delete
if (!empty($dsn)) {
[318] Fix | Delete
$this->addConnection($dsn, $username, $password, $this->config, $driverOptions);
[319] Fix | Delete
}
[320] Fix | Delete
if (isset($this->config[xPDO::OPT_CONNECTIONS])) {
[321] Fix | Delete
$connections = $this->config[xPDO::OPT_CONNECTIONS];
[322] Fix | Delete
if (is_string($connections)) {
[323] Fix | Delete
$connections = $this->fromJSON($connections);
[324] Fix | Delete
}
[325] Fix | Delete
if (is_array($connections)) {
[326] Fix | Delete
foreach ($connections as $connection) {
[327] Fix | Delete
$this->addConnection(
[328] Fix | Delete
$connection['dsn'],
[329] Fix | Delete
$connection['username'],
[330] Fix | Delete
$connection['password'],
[331] Fix | Delete
$connection['options'],
[332] Fix | Delete
$connection['driverOptions']
[333] Fix | Delete
);
[334] Fix | Delete
}
[335] Fix | Delete
}
[336] Fix | Delete
}
[337] Fix | Delete
$initOptions = $this->getOption(xPDO::OPT_CONN_INIT, null, array());
[338] Fix | Delete
$this->config = array_merge($this->config, $this->getConnection($initOptions)->config);
[339] Fix | Delete
$this->getDriver();
[340] Fix | Delete
$this->setPackage('om', XPDO_CORE_PATH, $this->config[xPDO::OPT_TABLE_PREFIX]);
[341] Fix | Delete
if (isset($this->config[xPDO::OPT_BASE_PACKAGES]) && !empty($this->config[xPDO::OPT_BASE_PACKAGES])) {
[342] Fix | Delete
$basePackages= explode(',', $this->config[xPDO::OPT_BASE_PACKAGES]);
[343] Fix | Delete
foreach ($basePackages as $basePackage) {
[344] Fix | Delete
$exploded= explode(':', $basePackage, 2);
[345] Fix | Delete
if ($exploded) {
[346] Fix | Delete
$path= $exploded[1];
[347] Fix | Delete
$prefix= null;
[348] Fix | Delete
if (strpos($path, ';')) {
[349] Fix | Delete
$details= explode(';', $path);
[350] Fix | Delete
if ($details && count($details) == 2) {
[351] Fix | Delete
$path= $details[0];
[352] Fix | Delete
$prefix = $details[1];
[353] Fix | Delete
}
[354] Fix | Delete
}
[355] Fix | Delete
$this->addPackage($exploded[0], $path, $prefix);
[356] Fix | Delete
}
[357] Fix | Delete
}
[358] Fix | Delete
}
[359] Fix | Delete
$this->loadClass('xPDOObject');
[360] Fix | Delete
$this->loadClass('xPDOSimpleObject');
[361] Fix | Delete
if (isset($this->config[xPDO::OPT_BASE_CLASSES])) {
[362] Fix | Delete
foreach (array_keys($this->config[xPDO::OPT_BASE_CLASSES]) as $baseClass) {
[363] Fix | Delete
$this->loadClass($baseClass);
[364] Fix | Delete
}
[365] Fix | Delete
}
[366] Fix | Delete
if (isset($this->config[xPDO::OPT_CACHE_PATH])) {
[367] Fix | Delete
$this->cachePath = $this->config[xPDO::OPT_CACHE_PATH];
[368] Fix | Delete
}
[369] Fix | Delete
} catch (Exception $e) {
[370] Fix | Delete
throw new xPDOException("Could not instantiate xPDO: " . $e->getMessage());
[371] Fix | Delete
}
[372] Fix | Delete
}
[373] Fix | Delete
[374] Fix | Delete
/**
[375] Fix | Delete
* Initialize an xPDO config array.
[376] Fix | Delete
*
[377] Fix | Delete
* @param string|array $data The config input source. Currently accepts a PHP array,
[378] Fix | Delete
* or a PHP string representing xPDO::OPT_TABLE_PREFIX (deprecated).
[379] Fix | Delete
* @return array An array of xPDO config data.
[380] Fix | Delete
*/
[381] Fix | Delete
protected function initConfig($data) {
[382] Fix | Delete
if (is_string($data)) {
[383] Fix | Delete
$data= array(xPDO::OPT_TABLE_PREFIX => $data);
[384] Fix | Delete
} elseif (!is_array($data)) {
[385] Fix | Delete
$data= array(xPDO::OPT_TABLE_PREFIX => '');
[386] Fix | Delete
}
[387] Fix | Delete
return $data;
[388] Fix | Delete
}
[389] Fix | Delete
[390] Fix | Delete
/**
[391] Fix | Delete
* Add an xPDOConnection instance to the xPDO connection pool.
[392] Fix | Delete
*
[393] Fix | Delete
* @param string $dsn A PDO DSN representing the connection details.
[394] Fix | Delete
* @param string $username The username credentials for the connection.
[395] Fix | Delete
* @param string $password The password credentials for the connection.
[396] Fix | Delete
* @param array $options An array of options for the connection.
[397] Fix | Delete
* @param null $driverOptions An array of PDO driver options for the connection.
[398] Fix | Delete
* @return boolean True if a valid connection was added.
[399] Fix | Delete
*/
[400] Fix | Delete
public function addConnection($dsn, $username= '', $password= '', array $options= array(), $driverOptions= null) {
[401] Fix | Delete
$added = false;
[402] Fix | Delete
$connection= new xPDOConnection($this, $dsn, $username, $password, $options, $driverOptions);
[403] Fix | Delete
if ($connection instanceof xPDOConnection) {
[404] Fix | Delete
$this->_connections[]= $connection;
[405] Fix | Delete
$added= true;
[406] Fix | Delete
}
[407] Fix | Delete
return $added;
[408] Fix | Delete
}
[409] Fix | Delete
[410] Fix | Delete
/**
[411] Fix | Delete
* Get an xPDOConnection from the xPDO connection pool.
[412] Fix | Delete
*
[413] Fix | Delete
* @param array $options An array of options for getting the connection.
[414] Fix | Delete
* @return xPDOConnection|null An xPDOConnection instance or null if no connection could be retrieved.
[415] Fix | Delete
*/
[416] Fix | Delete
public function &getConnection(array $options = array()) {
[417] Fix | Delete
$conn =& $this->connection;
[418] Fix | Delete
$mutable = $this->getOption(xPDO::OPT_CONN_MUTABLE, $options, null);
[419] Fix | Delete
if (!($conn instanceof xPDOConnection) || ($mutable !== null && (($mutable == true && !$conn->isMutable()) || ($mutable == false && $conn->isMutable())))) {
[420] Fix | Delete
if (!empty($this->_connections)) {
[421] Fix | Delete
shuffle($this->_connections);
[422] Fix | Delete
$conn = reset($this->_connections);
[423] Fix | Delete
while ($conn) {
[424] Fix | Delete
if ($mutable !== null && (($mutable == true && !$conn->isMutable()) || ($mutable == false && $conn->isMutable()))) {
[425] Fix | Delete
$conn = next($this->_connections);
[426] Fix | Delete
continue;
[427] Fix | Delete
}
[428] Fix | Delete
$this->connection =& $conn;
[429] Fix | Delete
break;
[430] Fix | Delete
}
[431] Fix | Delete
} else {
[432] Fix | Delete
$this->log(xPDO::LOG_LEVEL_ERROR, "Could not get a valid xPDOConnection", '', __METHOD__, __FILE__, __LINE__);
[433] Fix | Delete
}
[434] Fix | Delete
}
[435] Fix | Delete
return $this->connection;
[436] Fix | Delete
}
[437] Fix | Delete
[438] Fix | Delete
/**
[439] Fix | Delete
* Get or create a PDO connection to a database specified in the configuration.
[440] Fix | Delete
*
[441] Fix | Delete
* @param array $driverOptions An optional array of driver options to use
[442] Fix | Delete
* when creating the connection.
[443] Fix | Delete
* @param array $options An array of xPDO options for the connection.
[444] Fix | Delete
* @return boolean Returns true if the PDO connection was created successfully.
[445] Fix | Delete
*/
[446] Fix | Delete
public function connect($driverOptions= array (), array $options= array()) {
[447] Fix | Delete
$connected = false;
[448] Fix | Delete
$this->getConnection($options);
[449] Fix | Delete
if ($this->connection instanceof xPDOConnection) {
[450] Fix | Delete
$connected = $this->connection->connect($driverOptions);
[451] Fix | Delete
if ($connected) {
[452] Fix | Delete
$this->pdo =& $this->connection->pdo;
[453] Fix | Delete
}
[454] Fix | Delete
}
[455] Fix | Delete
return $connected;
[456] Fix | Delete
}
[457] Fix | Delete
[458] Fix | Delete
/**
[459] Fix | Delete
* Sets a specific model package to use when looking up classes.
[460] Fix | Delete
*
[461] Fix | Delete
* This package is of the form package.subpackage.subsubpackage and will be
[462] Fix | Delete
* added to the beginning of every xPDOObject class that is referenced in
[463] Fix | Delete
* xPDO methods such as {@link xPDO::loadClass()}, {@link xPDO::getObject()},
[464] Fix | Delete
* {@link xPDO::getCollection()}, {@link xPDOObject::getOne()}, {@link
[465] Fix | Delete
* xPDOObject::addOne()}, etc.
[466] Fix | Delete
*
[467] Fix | Delete
* @param string $pkg A package name to use when looking up classes in xPDO.
[468] Fix | Delete
* @param string $path The root path for looking up classes in this package.
[469] Fix | Delete
* @param string|null $prefix Provide a string to define a package-specific table_prefix.
[470] Fix | Delete
* @return bool
[471] Fix | Delete
*/
[472] Fix | Delete
public function setPackage($pkg= '', $path= '', $prefix= null) {
[473] Fix | Delete
if (empty($path) && isset($this->packages[$pkg])) {
[474] Fix | Delete
$path= $this->packages[$pkg]['path'];
[475] Fix | Delete
$prefix= !is_string($prefix) && array_key_exists('prefix', $this->packages[$pkg]) ? $this->packages[$pkg]['prefix'] : $prefix;
[476] Fix | Delete
}
[477] Fix | Delete
$set= $this->addPackage($pkg, $path, $prefix);
[478] Fix | Delete
$this->package= $set == true ? $pkg : $this->package;
[479] Fix | Delete
if ($set && is_string($prefix)) $this->config[xPDO::OPT_TABLE_PREFIX]= $prefix;
[480] Fix | Delete
return $set;
[481] Fix | Delete
}
[482] Fix | Delete
[483] Fix | Delete
/**
[484] Fix | Delete
* Adds a model package and base class path for including classes and/or maps from.
[485] Fix | Delete
*
[486] Fix | Delete
* @param string $pkg A package name to use when looking up classes/maps in xPDO.
[487] Fix | Delete
* @param string $path The root path for looking up classes in this package.
[488] Fix | Delete
* @param string|null $prefix Provide a string to define a package-specific table_prefix.
[489] Fix | Delete
* @return bool
[490] Fix | Delete
*/
[491] Fix | Delete
public function addPackage($pkg= '', $path= '', $prefix= null) {
[492] Fix | Delete
$added= false;
[493] Fix | Delete
if (is_string($pkg) && !empty($pkg)) {
[494] Fix | Delete
if (!is_string($path) || empty($path)) {
[495] Fix | Delete
$this->log(xPDO::LOG_LEVEL_ERROR, "Invalid path specified for package: {$pkg}; using default xpdo model path: " . XPDO_CORE_PATH . 'om/');
[496] Fix | Delete
$path= XPDO_CORE_PATH . 'om/';
[497] Fix | Delete
}
[498] Fix | Delete
if (!is_dir($path)) {
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function