Ejemplo n.º 1
0
 /**
  * Create adapter
  *
  * @param string $adapterName database adapter name
  * @param array $dbInfos database connection info
  * @param bool $connect
  * @return Piwik_Db_Adapter_Interface
  */
 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);
     Piwik_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;
 }
Ejemplo n.º 2
0
	/**
	 * Create adapter
	 *
	 * @param string $adapterName database adapter name
	 * @param array $dbInfos database connection info
	 * @param bool $connect
	 * @return mixed (Piwik_Db_Adapter_Mysqli, Piwik_Db_Adapter_Pdo_Mysql, etc)
	 */
	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);
		Piwik_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;
	}
Ejemplo 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_ImageGraph_StaticGraph
  */
 public static function factory($graphType)
 {
     if (isset(self::$availableStaticGraphTypes[$graphType])) {
         $className = self::$availableStaticGraphTypes[$graphType];
         Piwik_Loader::loadClass($className);
         return new $className();
     } else {
         throw new Exception(Piwik_TranslateException('General_ExceptionInvalidStaticGraphType', array($graphType, implode(', ', self::getAvailableStaticGraphTypes()))));
     }
 }
Ejemplo n.º 4
0
 /**
  * Return the SMSProvider associated to the provider name $providerName
  *
  * @throws exception If the provider is unknown
  * @param string $providerName
  * @return Piwik_MobileMessaging_SMSProvider
  */
 public static function factory($providerName)
 {
     $name = ucfirst(strtolower($providerName));
     $className = 'Piwik_MobileMessaging_SMSProvider_' . $name;
     try {
         Piwik_Loader::loadClass($className);
         return new $className();
     } catch (Exception $e) {
         throw new Exception(Piwik_TranslateException('MobileMessaging_Exception_UnknownProvider', array($name, implode(', ', array_keys(self::$availableSMSProviders)))));
     }
 }
Ejemplo n.º 5
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 {
         Piwik_Loader::loadClass($className);
         return new $className();
     } catch (Exception $e) {
         @header('Content-Type: text/html; charset=utf-8');
         throw new Exception(Piwik_TranslateException('General_ExceptionInvalidReportRendererFormat', array($name, implode(', ', self::$availableReportRenderers))));
     }
 }
Ejemplo n.º 6
0
	function __autoload($class)
	{
		Piwik_Loader::autoload($class);
	}
Ejemplo n.º 7
0
	/**
	 * Returns the DataTable associated to the output format $name
	 * 
	 * @throws exception If the renderer is unknown
	 * @return Piwik_DataTable_Renderer
	 */
	static public function factory( $name )
	{
		$name = ucfirst(strtolower($name));
		$className = 'Piwik_DataTable_Renderer_' . $name;
		
		try {
			Piwik_Loader::loadClass($className);
			return new $className;			
		} catch(Exception $e) {
			$availableRenderers = implode(', ', self::getRenderers());
			self::renderHeader();
			throw new Exception(Piwik_TranslateException('General_ExceptionInvalidRendererFormat', array($name, $availableRenderers)));
		}		
	}