Exemplo n.º 1
0
 /**
  * Create adapter
  *
  * @param string $adapterName database adapter name
  * @param array $dbInfos database connection info
  * @param bool $connect
  * @return AdapterInterface
  */
 public static function factory($adapterName, &$dbInfos, $connect = true)
 {
     if ($connect) {
         if ($dbInfos['port'][0] == '/') {
             $dbInfos['unix_socket'] = $dbInfos['port'];
             unset($dbInfos['host']);
             unset($dbInfos['port']);
         }
         // not used by Zend Framework
         unset($dbInfos['tables_prefix']);
         unset($dbInfos['adapter']);
         unset($dbInfos['schema']);
     }
     $className = self::getAdapterClassName($adapterName);
     Loader::loadClass($className);
     /*
      * 5.2.1 fixes various bugs with references that caused PDO_MYSQL getConnection()
      * to clobber $dbInfos. (#33282, #35106, #39944)
      */
     if (version_compare(PHP_VERSION, '5.2.1') < 0) {
         $adapter = new $className(array_map('trim', $dbInfos));
     } else {
         $adapter = new $className($dbInfos);
     }
     if ($connect) {
         $adapter->getConnection();
         Zend_Db_Table::setDefaultAdapter($adapter);
         // we don't want the connection information to appear in the logs
         $adapter->resetConfig();
     }
     return $adapter;
 }
Exemplo n.º 2
0
 /**
  * Return the SMSProvider associated to the provider name $providerName
  *
  * @throws Exception If the provider is unknown
  * @param string $providerName
  * @return \Piwik\Plugins\MobileMessaging\SMSProvider
  */
 public static function factory($providerName)
 {
     $className = __NAMESPACE__ . '\\SMSProvider\\' . $providerName;
     try {
         Loader::loadClass($className);
         return new $className();
     } catch (Exception $e) {
         throw new Exception(Piwik::translate('MobileMessaging_Exception_UnknownProvider', array($providerName, implode(', ', array_keys(self::$availableSMSProviders)))));
     }
 }
Exemplo n.º 3
0
 /**
  * Return the StaticGraph according to the static graph type $graphType
  *
  * @throws Exception If the static graph type is unknown
  * @param string $graphType
  * @return \Piwik\Plugins\ImageGraph\StaticGraph
  */
 public static function factory($graphType)
 {
     if (isset(self::$availableStaticGraphTypes[$graphType])) {
         $className = self::$availableStaticGraphTypes[$graphType];
         $className = __NAMESPACE__ . "\\StaticGraph\\" . $className;
         Loader::loadClass($className);
         return new $className();
     } else {
         throw new Exception(Piwik::translate('General_ExceptionInvalidStaticGraphType', array($graphType, implode(', ', self::getAvailableStaticGraphTypes()))));
     }
 }
Exemplo n.º 4
0
 /**
  * Return the ReportRenderer associated to the renderer type $rendererType
  *
  * @throws exception If the renderer is unknown
  * @param string $rendererType
  * @return \Piwik\ReportRenderer
  */
 public static function factory($rendererType)
 {
     $name = ucfirst(strtolower($rendererType));
     $className = 'Piwik\\ReportRenderer\\' . $name;
     try {
         Loader::loadClass($className);
         return new $className();
     } catch (Exception $e) {
         @header('Content-Type: text/html; charset=utf-8');
         throw new Exception(Piwik::translate('General_ExceptionInvalidReportRendererFormat', array($name, implode(', ', self::$availableReportRenderers))));
     }
 }
Exemplo n.º 5
0
 /**
  * Create adapter
  *
  * @param string $adapterName database adapter name
  * @param array $dbInfos database connection info
  * @param bool $connect
  * @return AdapterInterface
  */
 public static function factory($adapterName, &$dbInfos, $connect = true)
 {
     if ($connect) {
         if ($dbInfos['port'][0] == '/') {
             $dbInfos['unix_socket'] = $dbInfos['port'];
             unset($dbInfos['host']);
             unset($dbInfos['port']);
         }
         // not used by Zend Framework
         unset($dbInfos['tables_prefix']);
         unset($dbInfos['adapter']);
         unset($dbInfos['schema']);
     }
     $className = self::getAdapterClassName($adapterName);
     Loader::loadClass($className);
     $adapter = new $className($dbInfos);
     if ($connect) {
         $adapter->getConnection();
         Zend_Db_Table::setDefaultAdapter($adapter);
         // we don't want the connection information to appear in the logs
         $adapter->resetConfig();
     }
     return $adapter;
 }