CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 1.2 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 1.2
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Classes

  • AclBase
  • AclBehavior
  • AclComponent
  • AclNode
  • AclShell
  • Aco
  • AcoAction
  • AjaxHelper
  • ApcEngine
  • ApiShell
  • App
  • AppController
  • AppHelper
  • AppModel
  • Aro
  • AuthComponent
  • BakeShell
  • BehaviorCollection
  • Cache
  • CacheEngine
  • CacheHelper
  • CakeErrorController
  • CakeLog
  • CakeSchema
  • CakeSession
  • CakeSocket
  • ClassRegistry
  • Component
  • Configure
  • ConnectionManager
  • ConsoleShell
  • ContainableBehavior
  • Controller
  • ControllerTask
  • CookieComponent
  • DataSource
  • DbAcl
  • DbAclSchema
  • DbConfigTask
  • DboAdodb
  • DboDb2
  • DboFirebird
  • DboMssql
  • DboMysql
  • DboMysqlBase
  • DboMysqli
  • DboOdbc
  • DboOracle
  • DboPostgres
  • DboSource
  • DboSqlite
  • DboSybase
  • Debugger
  • EmailComponent
  • ErrorHandler
  • ExtractTask
  • File
  • FileEngine
  • Flay
  • Folder
  • FormHelper
  • Helper
  • HtmlHelper
  • HttpSocket
  • I18n
  • I18nModel
  • i18nSchema
  • I18nShell
  • Inflector
  • IniAcl
  • JavascriptHelper
  • JsHelper
  • JsHelperObject
  • L10n
  • MagicDb
  • MagicFileResource
  • MediaView
  • MemcacheEngine
  • Model
  • ModelBehavior
  • ModelTask
  • Multibyte
  • NumberHelper
  • Object
  • Overloadable
  • Overloadable2
  • PagesController
  • PaginatorHelper
  • Permission
  • PluginTask
  • ProjectTask
  • RequestHandlerComponent
  • Router
  • RssHelper
  • Sanitize
  • Scaffold
  • ScaffoldView
  • SchemaShell
  • Security
  • SecurityComponent
  • SessionComponent
  • SessionHelper
  • SessionsSchema
  • Set
  • Shell
  • String
  • TestSuiteShell
  • TestTask
  • TextHelper
  • ThemeView
  • TimeHelper
  • TranslateBehavior
  • TreeBehavior
  • Validation
  • View
  • ViewTask
  • XcacheEngine
  • Xml
  • XmlElement
  • XmlHelper
  • XmlManager
  • XmlNode
  • XmlTextNode

Functions

  • __enclose
  • make_clean_css
  • mb_encode_mimeheader
  • mb_stripos
  • mb_stristr
  • mb_strlen
  • mb_strpos
  • mb_strrchr
  • mb_strrichr
  • mb_strripos
  • mb_strrpos
  • mb_strstr
  • mb_strtolower
  • mb_strtoupper
  • mb_substr
  • mb_substr_count
  • write_css_cache
  1: <?php
  2: /* SVN FILE: $Id$ */
  3: /**
  4:  * Datasource connection manager
  5:  *
  6:  * Provides an interface for loading and enumerating connections defined in app/config/database.php
  7:  *
  8:  * PHP versions 4 and 5
  9:  *
 10:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 11:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 12:  *
 13:  * Licensed under The MIT License
 14:  * Redistributions of files must retain the above copyright notice.
 15:  *
 16:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 17:  * @link          http://cakephp.org CakePHP(tm) Project
 18:  * @package       cake
 19:  * @subpackage    cake.cake.libs.model
 20:  * @since         CakePHP(tm) v 0.10.x.1402
 21:  * @version       $Revision$
 22:  * @modifiedby    $LastChangedBy$
 23:  * @lastmodified  $Date$
 24:  * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 25:  */
 26: uses ('model' . DS . 'datasources' . DS . 'datasource');
 27: config('database');
 28: 
 29: /**
 30:  * Manages loaded instances of DataSource objects
 31:  *
 32:  * Long description for file
 33:  *
 34:  * @package       cake
 35:  * @subpackage    cake.cake.libs.model
 36:  */
 37: class ConnectionManager extends Object {
 38: /**
 39:  * Holds a loaded instance of the Connections object
 40:  *
 41:  * @var DATABASE_CONFIG
 42:  * @access public
 43:  */
 44:     var $config = null;
 45: /**
 46:  * Holds instances DataSource objects
 47:  *
 48:  * @var array
 49:  * @access protected
 50:  */
 51:     var $_dataSources = array();
 52: /**
 53:  * Contains a list of all file and class names used in Connection settings
 54:  *
 55:  * @var array
 56:  * @access protected
 57:  */
 58:     var $_connectionsEnum = array();
 59: /**
 60:  * Constructor.
 61:  *
 62:  */
 63:     function __construct() {
 64:         if (class_exists('DATABASE_CONFIG')) {
 65:             $this->config =& new DATABASE_CONFIG();
 66:         }
 67:     }
 68: /**
 69:  * Gets a reference to the ConnectionManger object instance
 70:  *
 71:  * @return object Instance
 72:  * @access public
 73:  * @static
 74:  */
 75:     function &getInstance() {
 76:         static $instance = array();
 77: 
 78:         if (!$instance) {
 79:             $instance[0] =& new ConnectionManager();
 80:         }
 81: 
 82:         return $instance[0];
 83:     }
 84: /**
 85:  * Gets a reference to a DataSource object
 86:  *
 87:  * @param string $name The name of the DataSource, as defined in app/config/database.php
 88:  * @return object Instance
 89:  * @access public
 90:  * @static
 91:  */
 92:     function &getDataSource($name) {
 93:         $_this =& ConnectionManager::getInstance();
 94: 
 95:         if (!empty($_this->_dataSources[$name])) {
 96:             $return =& $_this->_dataSources[$name];
 97:             return $return;
 98:         }
 99: 
100:         $connections = $_this->enumConnectionObjects();
101:         if (!empty($connections[$name])) {
102:             $conn = $connections[$name];
103:             $class = $conn['classname'];
104:             $_this->loadDataSource($name);
105:             $_this->_dataSources[$name] =& new $class($_this->config->{$name});
106:             $_this->_dataSources[$name]->configKeyName = $name;
107:         } else {
108:             trigger_error(sprintf(__("ConnectionManager::getDataSource - Non-existent data source %s", true), $name), E_USER_ERROR);
109:             return null;
110:         }
111: 
112:         $return =& $_this->_dataSources[$name];
113:         return $return;
114:     }
115: /**
116:  * Gets the list of available DataSource connections
117:  *
118:  * @return array List of available connections
119:  * @access public
120:  * @static
121:  */
122:     function sourceList() {
123:         $_this =& ConnectionManager::getInstance();
124:         return array_keys($_this->_dataSources);
125:     }
126: /**
127:  * Gets a DataSource name from an object reference
128:  *
129:  * @param object $source DataSource object
130:  * @return string Datasource name
131:  * @access public
132:  * @static
133:  */
134:     function getSourceName(&$source) {
135:         $_this =& ConnectionManager::getInstance();
136:         $names = array_keys($_this->_dataSources);
137:         for ($i = 0, $count = count($names); $i < $count; $i++) {
138:             if ($_this->_dataSources[$names[$i]] === $source) {
139:                 return $names[$i];
140:             }
141:         }
142:         return null;
143:     }
144: /**
145:  * Loads the DataSource class for the given connection name
146:  *
147:  * @param mixed $connName A string name of the connection, as defined in app/config/database.php,
148:  *                        or an array containing the filename (without extension) and class name of the object,
149:  *                        to be found in app/models/datasources/ or cake/libs/model/datasources/.
150:  * @return boolean True on success, null on failure or false if the class is already loaded
151:  * @access public
152:  * @static
153:  */
154:     function loadDataSource($connName) {
155:         $_this =& ConnectionManager::getInstance();
156: 
157:         if (is_array($connName)) {
158:             $conn = $connName;
159:         } else {
160:             $connections = $_this->enumConnectionObjects();
161:             $conn = $connections[$connName];
162:         }
163: 
164:         if (!empty($conn['parent'])) {
165:             $_this->loadDataSource($conn['parent']);
166:         }
167: 
168:         if (class_exists($conn['classname'])) {
169:             return false;
170:         }
171: 
172:         if (file_exists(MODELS . 'datasources' . DS . $conn['filename'] . '.php')) {
173:             require (MODELS . 'datasources' . DS . $conn['filename'] . '.php');
174:         } elseif (fileExistsInPath(LIBS . 'model' . DS . 'datasources' . DS . $conn['filename'] . '.php')) {
175:             require (LIBS . 'model' . DS . 'datasources' . DS . $conn['filename'] . '.php');
176:         } else {
177:             $error = __('Unable to load DataSource file %s.php', true);
178:             trigger_error(sprintf($error, $conn['filename']), E_USER_ERROR);
179:             return null;
180:         }
181: 
182:         return true;
183:     }
184: /**
185:  * Gets a list of class and file names associated with the user-defined DataSource connections
186:  *
187:  * @return array An associative array of elements where the key is the connection name
188:  *               (as defined in Connections), and the value is an array with keys 'filename' and 'classname'.
189:  * @access public
190:  * @static
191:  */
192:     function enumConnectionObjects() {
193:         $_this =& ConnectionManager::getInstance();
194: 
195:         if (!empty($_this->_connectionsEnum)) {
196:             return $_this->_connectionsEnum;
197:         }
198:         $connections = get_object_vars($_this->config);
199: 
200:         if ($connections != null) {
201:             foreach ($connections as $name => $config) {
202:                 $_this->_connectionsEnum[$name] = $_this->__getDriver($config);
203:             }
204:             return $_this->_connectionsEnum;
205:         } else {
206:             $_this->cakeError('missingConnection', array(array('className' => 'ConnectionManager')));
207:         }
208:     }
209: /**
210:  * Dynamically creates a DataSource object at runtime, with the given name and settings
211:  *
212:  * @param string $name The DataSource name
213:  * @param array $config The DataSource configuration settings
214:  * @return object A reference to the DataSource object, or null if creation failed
215:  * @access public
216:  * @static
217:  */
218:     function &create($name = '', $config = array()) {
219:         $_this =& ConnectionManager::getInstance();
220: 
221:         if (empty($name) || empty($config) || array_key_exists($name, $_this->_connectionsEnum)) {
222:             $null = null;
223:             return $null;
224:         }
225: 
226:         $_this->config->{$name} = $config;
227:         $_this->_connectionsEnum[$name] = $_this->__getDriver($config);
228:         $return =& $_this->getDataSource($name);
229:         return $return;
230:     }
231: /**
232:  * Returns the file, class name, and parent for the given driver.
233:  *
234:  * @return array An indexed array with: filename, classname, and parent
235:  * @access private
236:  */
237:     function __getDriver($config) {
238:         if (!isset($config['datasource'])) {
239:             $config['datasource'] = 'dbo';
240:         }
241: 
242:         if (isset($config['driver']) && $config['driver'] != null && !empty($config['driver'])) {
243:             $filename = $config['datasource'] . DS . $config['datasource'] . '_' . $config['driver'];
244:             $classname = Inflector::camelize(strtolower($config['datasource'] . '_' . $config['driver']));
245:             $parent = $this->__getDriver(array('datasource' => $config['datasource']));
246:         } else {
247:             $filename = $config['datasource'] . '_source';
248:             $classname = Inflector::camelize(strtolower($config['datasource'] . '_source'));
249:             $parent = null;
250:         }
251:         return array('filename'  => $filename, 'classname' => $classname, 'parent' => $parent);
252:     }
253: /**
254:  * Destructor.
255:  *
256:  * @access private
257:  */
258:     function __destruct() {
259:         if (Configure::read('Session.save') == 'database' && function_exists('session_write_close')) {
260:             session_write_close();
261:         }
262:     }
263: }
264: ?>
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs