Ejemplo n.º 1
0
 /**
  *
  * @param string $adapter
  * @param mixed $config
  * @return Taplod_Db_Adapter_Abstract
  */
 public static function factory($adapter, $config = array())
 {
     if ($config instanceof Taplod_Config) {
         $config = $config->toArray();
     }
     if (!is_array($config)) {
         require_once 'Taplod/Db/Exception.php';
         throw new Taplod_Db_Exception('Adapter parameters must be in an array');
     }
     if (!is_string($adapter) || empty($adapter)) {
         /**
          * @see Taplod_Db_Exception
          */
         require_once 'Taplod/Db/Exception.php';
         throw new Taplod_Db_Exception('Adapter name must be specified in a string');
     }
     $adapterNamespace = 'Taplod_Db_Adapter';
     if (isset($config['adapterNamespace'])) {
         $adapterNamespace = $config['adapterNamespace'];
     }
     $adapterName = $adapterNamespace . '_' . $adapter;
     Taplod_Loader::loadClass($adapterName);
     $dbAdapter = new $adapterName($config);
     if (!$dbAdapter instanceof Taplod_Db_Adapter_Abstract) {
         require_once 'Db/Exception.php';
         throw new Taplod_Db_Exception("Adapter Class '{$adapterName}' does not extend Taplod_Db_Adapter_Abstract");
     }
     return $dbAdapter;
 }
Ejemplo n.º 2
0
 public function getHelper($name)
 {
     $name = ucfirst($name);
     $prefix = 'Taplod_Templates_Helper';
     $prefix_path = 'Taplod/Templates/Helper/';
     if (!array_key_exists($name, $this->_helpers)) {
         $file = $prefix . '_' . $name;
         try {
             Taplod_Loader::loadClass($file);
         } catch (Taplod_Exception $exception) {
             require_once 'Taplod/Templates/Exception.php';
             throw new Taplod_Templates_Exception("Cannot load '{$name}' helper.<br/>" . $exception->getMessage());
         }
         $this->_helpers[$name] = new $file();
         if (method_exists($this->_helpers[$name], 'setTemplate')) {
             $this->_helpers[$name]->setTemplate($this);
         }
     }
     return $this->_helpers[$name];
 }