10 defined(
'JPATH_PLATFORM') or die;
29 protected $_adapters = array();
36 protected $_adapterfolder =
'adapters';
42 protected $_classprefix =
'J';
50 protected $_basepath = null;
69 public function __construct($basepath, $classprefix = null, $adapterfolder = null)
71 $this->_basepath = $basepath;
72 $this->_classprefix = $classprefix ? $classprefix :
'J';
73 $this->_adapterfolder = $adapterfolder ? $adapterfolder :
'adapters';
85 public function getDBO()
101 public function setAdapter($name, &$adapter = null, $options = array())
103 if (!is_object($adapter))
105 $fullpath = $this->_basepath .
'/' . $this->_adapterfolder .
'/' . strtolower($name) .
'.php';
107 if (!file_exists($fullpath))
113 require_once $fullpath;
115 $class = $this->_classprefix . ucfirst($name);
117 if (!class_exists($class))
122 $adapter =
new $class($this, $this->_db, $options);
125 $this->_adapters[$name] = &$adapter;
140 public function getAdapter($name, $options = array())
142 if (!array_key_exists($name, $this->_adapters))
144 if (!$this->setAdapter($name, $options))
152 return $this->_adapters[$name];
164 public function loadAllAdapters($options = array())
166 $files =
new DirectoryIterator($this->_basepath .
'/' . $this->_adapterfolder);
168 foreach ($files as $file)
170 $fileName = $file->getFilename();
174 if (!$file->isFile() || substr($fileName, strrpos($fileName,
'.') + 1) !=
'php')
180 require_once $this->_basepath .
'/' . $this->_adapterfolder .
'/' . $fileName;
183 $name = str_ireplace(
'.php',
'', ucfirst(trim($fileName)));
184 $class = $this->_classprefix . ucfirst($name);
186 if (!class_exists($class))
192 $adapter =
new $class($this, $this->_db, $options);
193 $this->_adapters[$name] = clone $adapter;