Exemplo n.º 1
0
    /**
     * Plugin starts
     *
     * @param array $config
     */
    public static function start($config)
    {
    	self::$config = array_merge(self::$config, $config);

		// automatic connection
		if (self::$config['dsn'] !== false) {
			$dsn = self::$config['dsn'];
			$username = self::$config['username'];
			$password = self::$config['password'];
			
			$instance = Atomik_Db::createInstance('default', $dsn, $username, $password);
			$instance->setTablePrefix(self::$config['table_prefix']);
			$instance->enableQueryCache(self::$config['query_cache']);
			$instance->enableResultCache(self::$config['result_cache']);
		}
		
		// adds models directories to php's include path
		$includes = explode(PATH_SEPARATOR, get_include_path());
		foreach (Atomik::path(self::$config['model_dirs'], true) as $dir) {
			if (!in_array($dir, $includes)) {
				array_unshift($includes, $dir);
			}
		}
		set_include_path(implode(PATH_SEPARATOR, $includes));
		
		// registers the db selector namespace
		Atomik::registerSelector('db', array('DbPlugin', 'selector'));
		
		if (Atomik::isPluginLoaded('Console')) {
			ConsolePlugin::register('db-create', array('DbPlugin', 'dbCreateCommand'));
			ConsolePlugin::register('db-create-sql', array('DbPlugin', 'dbCreateSqlCommand'));
		}
    }