Exemple #1
0
 /**
  * @param string $key
  * @return mixed
  */
 public static function get($scope)
 {
     if (!isset(self::$settings[$scope])) {
         self::$instance->load($scope);
     }
     return self::$settings[$scope];
 }
Exemple #2
0
 /**
  * Init
  *
  * Loads in the config and sets the variables
  *
  * @access	public
  * @return	void
  */
 public static function _init()
 {
     \Config::load('breadcrumb', 'breadcrumb');
     if (\Config::get('breadcrumb.auto_render', static::$auto_render) === true) {
         static::initialise();
     }
 }
Exemple #3
0
 public static function install($package = null)
 {
     // Make sure something is set
     if ($package === null) {
         static::help();
         return;
     }
     $config = \Config::load('package');
     $version = \Cli::option('version', 'master');
     // Check to see if this package is already installed
     if (is_dir(PKGPATH . $package)) {
         throw new Exception('Package "' . $package . '" is already installed.');
         return;
     }
     foreach ($config['sources'] as $source) {
         $packages = array('fuel-' . $package, $package);
         foreach ($packages as $package) {
             $zip_url = 'http://' . rtrim($source, '/') . '/' . $package . '/zipball/' . $version;
             if ($fp = @fopen($zip_url, 'r')) {
                 // We don't actually need this, just checking the file is there
                 fclose($fp);
                 // Now, lets get this package
                 // If a direct download is requested, or git is unavailable, download it!
                 if (\Cli::option('direct') or static::_use_git() === false) {
                     static::_download_package_zip($zip_url, $package, $version);
                     exit;
                 } else {
                     static::_clone_package_repo($source, $package, $version);
                     exit;
                 }
             }
         }
     }
     throw new Exception('Could not find package "' . $package . '".');
 }
Exemple #4
0
 /**
  * Get a instance.
  *
  * @return \Jobqueue\Context
  */
 public static function instance()
 {
     if (is_null(static::$instance)) {
         static::$instance = new static(\Fuel::$env, \Config::load('jobqueue', 'jobqueue'));
     }
     return static::$instance;
 }
Exemple #5
0
 /**
  * Loads in the config and sets the variables
  */
 public static function _init()
 {
     // Prevent multiple initializations
     if (static::$initialized) {
         return;
     }
     \Config::load('casset', true);
     $paths = \Config::get('casset.paths', static::$asset_paths);
     foreach ($paths as $key => $path) {
         static::add_path($key, $path);
     }
     static::$asset_url = \Config::get('casset.url', \Config::get('base_url'));
     static::$default_folders = array('css' => \Config::get('casset.css_dir', static::$default_folders['css']), 'js' => \Config::get('casset.js_dir', static::$default_folders['js']), 'img' => \Config::get('casset.img_dir', static::$default_folders['img']));
     static::$cache_path = \Config::get('casset.cache_path', static::$cache_path);
     static::$min_default = \Config::get('casset.min', static::$min_default);
     static::$combine_default = \Config::get('casset.combine', static::$combine_default);
     $group_sets = \Config::get('casset.groups', array());
     foreach ($group_sets as $group_type => $groups) {
         foreach ($groups as $group_name => $group) {
             $enabled = array_key_exists('enabled', $group) ? $group['enabled'] : true;
             $combine = array_key_exists('combine', $group) ? $group['combine'] : null;
             $min = array_key_exists('min', $group) ? $group['min'] : null;
             static::add_group($group_type, $group_name, $enabled, $combine, $min);
             foreach ($group['files'] as $files) {
                 if (!is_array($files)) {
                     $files = array($files, false);
                 }
                 static::add_asset($group_type, $files[0], $files[1], $group_name);
             }
         }
     }
     static::$show_files = \Config::get('casset.show_files', static::$show_files);
     static::$show_files_inline = \Config::get('casset.show_files_inline', static::$show_files_inline);
     static::$initialized = true;
 }
Exemple #6
0
 protected function load($menu = null)
 {
     $menu = $menu ?: $this->menu;
     $data = \Config::load('menu/' . $menu, true, true, true);
     $this->meta = array('name' => \Arr::get($data, 'name'), 'identifier' => \Arr::get($data, 'slug'), 'num_items' => $this->count($data['children']));
     return $data;
 }
Exemple #7
0
	/**
	 * Sets the initial Ftp filename and local data.
	 *
	 * @param   string  Ftp filename
	 * @param   array   array of values
	 * @return  void
	 */
	public function __construct($config = 'default')
	{
		\Config::load('ftp', true);

		// If it is a string we're looking at a predefined config group
		if (is_string($config))
		{
			$config_arr = \Config::get('ftp.'.$config);

			// Check that it exists
			if ( ! is_array($config_arr) or $config_arr === array())
			{
				throw new \Exception('You have specified an invalid ftp connection group: '.$config);
			}

			$config = $config_arr;
		}

		// Prep the hostname
		$this->_hostname = preg_replace('|.+?://|', '', $config['hostname']);
		$this->_username = $config['username'];
		$this->_password = $config['password'];
		$this->_port = ! empty($config['port']) ? (int) $config['port'] : 21;
		$this->_passive = (bool) $config['passive'];
		$this->_ssl_mode = (bool) $config['ssl_mode'];
		$this->_debug = (bool) $config['debug'];

		static::$initialized = true;
	}
 /**
  * Initialize
  */
 public static function _init()
 {
     $config = \Config::load('sentry', true);
     static::$config = $config[\Fuel::$env];
     // create instance for PHP
     static::$client = new \Raven_Client(static::$config['php']['dsn']);
 }
 public function run()
 {
     $url = 'http://' . (getenv('WEB_HOST') ? getenv('WEB_HOST') : 'localhost');
     $output = APPPATH . '/cache/benchmark-results.json';
     \Config::load('orms', true);
     $orms = \Config::get('orms.list');
     $data = [];
     $errors = [];
     foreach ($orms as $orm) {
         echo 'Benchmarking ' . $orm . ' ...';
         try {
             $time = 0;
             $memory = 0;
             for ($i = 0; $i < 100; $i++) {
                 $result = file_get_contents($url . '/orm/' . $orm . '/get_one');
                 $tmp = explode("\n", $result);
                 //                var_dump($tmp);
                 $time += (double) trim($tmp[2], ' sec');
                 $memory += (double) trim($tmp[3], ' KB');
             }
             $time = $time / $i * 1000;
             $memory = $memory / $i;
             echo "\t" . substr($time, 0, 9) . 'ms ' . "\t" . $memory . 'KB' . PHP_EOL;
             $data[$orm] = array('time' => $time, 'memory' => $memory);
         } catch (\Exception $e) {
             $errors[$orm] = (string) $e;
             echo "\tfailed!\n";
         }
     }
     foreach ($errors as $orm => $error) {
         echo "\n{$orm} failed with exception:\n{$error}\n";
     }
     file_put_contents($output, json_encode($data));
 }
Exemple #10
0
 function __construct($app_name)
 {
     $config = \Config::load('google', true);
     $this->_client = new \apiClient();
     if ($app_name != null && $app_name != "") {
         $this->_client->setApplicationName($app_name);
     }
     foreach ($config as $key => $value) {
         if ($value != null && $value != "") {
             switch ($key) {
                 case "client_id":
                     $this->_client->setClientId($value);
                     break;
                 case "client_secret":
                     $this->_client->setClientSecret($value);
                     break;
                 case "redirect_uri":
                     $this->_client->setRedirectUri($value);
                     break;
                 case "developer_key":
                     $this->_client->setDeveloperKey($value);
                     break;
             }
         }
     }
 }
 public static function _init()
 {
     \Config::load('complexauth', true, true, true);
     if (\Config::get('complexauth.remember_me.enabled', false)) {
         static::$remember_me = \Session::forge(array('driver' => 'cookie', 'cookie' => array('cookie_name' => \Config::get('complexauth.remember_me.cookie_name', 'rmcookie')), 'encrypt_cookie' => true, 'expire_on_close' => false, 'expiration_time' => \Config::get('complexauth.remember_me.expiration', 86400 * 31)));
     }
 }
Exemple #12
0
 /**
  * Setting the display of pages
  *
  * @uses  Arr::merge
  * @uses  Config::load
  * @uses  Message::success
  */
 public function action_settings()
 {
     $this->title = __('Page Settings');
     $post = Config::load('page');
     $action = Route::get('admin/page')->uri(array('action' => 'settings'));
     $vocabs = array(__('none'));
     $view = View::factory('admin/page/settings')->set('vocabs', $vocabs)->set('post', $post)->set('action', $action);
     $vocabs = Arr::merge($vocabs, ORM::factory('term')->where('lft', '=', 1)->where('type', '=', 'page')->find_all()->as_array('id', 'name'));
     if ($this->valid_post('page_settings')) {
         unset($_POST['page_settings'], $_POST['_token'], $_POST['_action']);
         $cats = $post->get('category', array());
         foreach ($_POST as $key => $value) {
             if ($key == 'category') {
                 $terms = array_diff($cats, $value);
                 if ($terms) {
                     DB::delete('posts_terms')->where('parent_id', 'IN', array_values($terms))->execute();
                 }
             }
             $post->set($key, $value);
         }
         Log::info('Page Settings updated.');
         Message::success(__('Page Settings updated!'));
         $this->request->redirect(Route::get('admin/page')->uri(array('action' => 'settings')), 200);
     }
     $this->response->body($view);
 }
 public function action_main($params = array())
 {
     $config = $this->config;
     $gConfig = \Config::load('novius_social_widget::config', true);
     if (Arr::get($gConfig, 'embed_js', true)) {
         if (!empty($config['js'])) {
             foreach ($config['js'] as $script) {
                 Nos::main_controller()->addJavascript($script);
             }
         }
     }
     $chrome = array();
     $typeList = array('chrome');
     foreach ($params as $param => $value) {
         if ($value) {
             foreach ($typeList as $type) {
                 $typePrefix = "{$type}-";
                 if ($value && \Str::starts_with($param, $typePrefix)) {
                     array_push(${$type}, \Str::sub($param, \Str::length($typePrefix)));
                 }
             }
         }
     }
     return \View::forge('novius_social_widget::front/enhancer/twitter', array('widgetId' => $params['widget-id'], 'chrome' => $chrome, 'limit' => \Arr::get($params, 'limit'), 'width' => \Arr::get($params, 'width'), 'height' => \Arr::get($params, 'height')), false);
 }
Exemple #14
0
 /**
  * Construct
  * 
  * Called when the class is initialised
  * 
  * @access	protected
  * @return	PDF\PDF
  */
 protected function __construct($driver = null)
 {
     // Load Config
     \Config::load('pdf', true);
     // Default Driver
     if ($driver == null) {
         $driver = \Config::get('pdf.default_driver');
     }
     // Set the lib path
     $this->set_lib_path(PKGPATH . 'pdf' . DS . 'lib' . DS);
     $drivers = \Config::get('pdf.drivers');
     $temp_driver = isset($drivers[$driver]) ? $drivers[$driver] : false;
     if ($temp_driver === false) {
         throw new \Exception(sprintf('Driver \'%s\' doesn\'t exist.', $driver));
     }
     $driver = $temp_driver;
     // Include files
     foreach ($driver['includes'] as $include) {
         include_once $this->_get_include_file($include);
     }
     $this->set_driver_class($driver['class']);
     // Return this object. User must now call init and provide the parameters that
     // the driver wants. This action is caught by __call()
     return $this;
 }
Exemple #15
0
 /**
  * Return all defined permissions (results get stored at the first run)
  *
  *
  *
  * @return array
  */
 public function split($exclude)
 {
     static $list = null;
     if ($list == null) {
         $perms = array('free' => array(), 'excluded' => array());
         $paths = array_keys(Kohana::list_files('permissions'));
         foreach ($paths as $path) {
             $set = str_replace(array('permissions' . DIRECTORY_SEPARATOR, '.php'), '', $path);
             $list = $this->_list->load($set)->as_array();
             foreach ($list as $k => $v) {
                 if (is_int($k)) {
                     if (!in_array($set . '.' . $v, $exclude)) {
                         $perms['free'][] = $set . '.' . $v;
                     } else {
                         $perms['excluded'][] = $set . '.' . $v;
                     }
                 } else {
                     $perms = $this->_process_perms_split($v, $set . '.' . $k, $perms, $exclude);
                 }
             }
         }
         $list = $perms;
     }
     sort($perms['excluded']);
     sort($perms['free']);
     return $list;
 }
Exemple #16
0
 /**
  * Get list of pages
  *
  * @uses  Config::load
  * @uses  Config_Group::get
  * @uses  URL::site
  * @uses  Cache::set
  */
 public function action_list()
 {
     if (empty($this->_items)) {
         $config = Config::load('page');
         // Cache is Empty so Re-Cache
         $pages = ORM::factory('page')->where('status', '=', 'publish')->order_by('pubdate', 'DESC')->limit($this->_limit)->offset($this->_offset)->find_all();
         $items = array();
         foreach ($pages as $page) {
             $item = array();
             $item['guid'] = $page->id;
             $item['title'] = $page->title;
             $item['link'] = URL::site($page->url, TRUE);
             if ($config->get('use_submitted', FALSE)) {
                 $item['author'] = $page->user->nick;
             }
             $item['description'] = $page->teaser;
             $item['pubDate'] = $page->pubdate;
             $items[] = $item;
         }
         $this->_cache->set($this->_cache_key, $items, $this->_ttl);
         $this->_items = $items;
     }
     if (isset($this->_items[0])) {
         $this->_info['title'] = __('Pages - Recent updates');
         $this->_info['link'] = Route::url('rss', array('controller' => 'page'), TRUE);
         $this->_info['pubDate'] = $this->_items[0]['pubDate'];
     }
 }
 function down()
 {
     // get the drivers defined
     $drivers = normalize_driver_types();
     if (in_array('Simpleauth', $drivers)) {
         // get the tablename
         \Config::load('simpleauth', true);
         $basetable = \Config::get('simpleauth.table_name', 'users');
         // make sure the configured DB is used
         \DBUtil::set_connection(\Config::get('simpleauth.db_connection', null));
     } elseif (in_array('Ormauth', $drivers)) {
         // get the tablename
         \Config::load('ormauth', true);
         $basetable = \Config::get('ormauth.table_name', 'users');
         // make sure the configured DB is used
         \DBUtil::set_connection(\Config::get('ormauth.db_connection', null));
     } else {
         $basetable = 'users';
     }
     \DBUtil::drop_table($basetable . '_sessionscopes');
     \DBUtil::drop_table($basetable . '_sessions');
     \DBUtil::drop_table($basetable . '_scopes');
     \DBUtil::drop_table($basetable . '_clients');
     // reset any DBUtil connection set
     \DBUtil::set_connection(null);
 }
Exemple #18
0
	/**
	 * Get a singleton Database instance. If configuration is not specified,
	 * it will be loaded from the database configuration file using the same
	 * group as the name.
	 *
	 *     // Load the default database
	 *     $db = static::instance();
	 *
	 *     // Create a custom configured instance
	 *     $db = static::instance('custom', $config);
	 *
	 * @param   string   instance name
	 * @param   array    configuration parameters
	 * @return  Database
	 */
	public static function instance($name = NULL, array $config = NULL)
	{
		\Config::load('db', true);
		if ($name === NULL)
		{
			// Use the default instance name
			$name = \Config::get('db.active');
		}

		if ( ! isset(static::$instances[$name]))
		{
			if ($config === NULL)
			{
				// Load the configuration for this database
				$config = \Config::get("db.{$name}");
			}

			if ( ! isset($config['type']))
			{
				throw new \Exception("Database type not defined in {$name} configuration");
			}

			// Set the driver class name
			$driver = 'Fuel\\Core\\Database_'.ucfirst($config['type']);

			// Create the database connection instance
			new $driver($name, $config);
		}

		return static::$instances[$name];
	}
Exemple #19
0
 public static function _init()
 {
     \Config::load('debtsolv', 'debtsolv');
     static::$_debtsolv_database = \Config::get('debtsolv.debtsolv_database', static::$_debtsolv_database);
     static::$_leadpool_database = \Config::get('debtsolv.leadpool_database', static::$_leadpool_database);
     static::$_connection = \Database_Connection::instance('Debtsolv', \Config::get('debtsolv.connection', static::$_connection));
 }
Exemple #20
0
 /**
  * Send email to group of admin users
  * 
  * @param type $group_name
  * @param type $subject
  * @param type $view
  * @param type $email_data
  * @param type $attachment = Attache a file
  * @param type $theme = theme to load views from
  * @return boolean
  * @throws \Exception
  */
 public static function send_email_to_group($group_name, $subject, $view, $email_data, $attachment = false)
 {
     \Config::load('auto_response_emails', 'auto_response_emails', true);
     $emails = \Config::get('auto_response_emails.' . $group_name . '_emails', false);
     if ($emails == false) {
         $emails = \Config::get('auto_response_emails.default_emails', false);
     }
     $bcc = \Config::get('auto_response_emails.bcc');
     $email = \Email::forge();
     $email->cc($emails);
     if ($bcc) {
         $email->bcc($bcc);
     }
     $email->subject($subject);
     $email->from(\Config::get('auto_response_emails.autoresponder_from_email'), \Config::get('site_title'));
     if ($attachment) {
         $email->attach($attachment);
     }
     $emailView = \Theme::instance()->view('views/' . $view)->set('email_data', $email_data, false);
     $email->html_body($emailView);
     try {
         $email->send();
     } catch (\Exception $e) {
         if (\Fuel::$env == 'development') {
             throw new \Exception($e->getMessage());
         } else {
             return false;
         }
     }
     return true;
 }
Exemple #21
0
 /**
  * Initialize by loading config & starting default session
  */
 public static function _init()
 {
     \Config::load('session', true);
     if (\Config::get('session.auto_initialize', true)) {
         static::instance();
     }
 }
Exemple #22
0
 public function index()
 {
     $cfg = new Config();
     $cfg->load(__DIR__ . "/../config.php");
     echo $cfg->get("method_name") . "<br>";
     echo $cfg->get("method_description") . "<br>";
 }
Exemple #23
0
 /**
  * Router
  *
  * Requests are not made to methods directly The request will be for an "object".
  * this simply maps the object and method to the correct Controller method.
  *
  * @param  string
  * @param  array
  */
 public function router($resource, array $arguments)
 {
     \Config::load('rest', true);
     $pattern = '/\\.(' . implode('|', array_keys($this->_supported_formats)) . ')$/';
     // Check if a file extension is used
     if (preg_match($pattern, $resource, $matches)) {
         // Remove the extension from arguments too
         $resource = preg_replace($pattern, '', $resource);
         $this->format = $matches[1];
     } else {
         // Which format should the data be returned in?
         $this->format = $this->_detect_format();
     }
     //Check method is authorized if required
     if (\Config::get('rest.auth') == 'basic') {
         $valid_login = $this->_prepare_basic_auth();
     } elseif (\Config::get('rest.auth') == 'digest') {
         $valid_login = $this->_prepare_digest_auth();
     }
     //If the request passes auth then execute as normal
     if (\Config::get('rest.auth') == '' or $valid_login) {
         // If they call user, go to $this->post_user();
         $controller_method = strtolower(\Input::method()) . '_' . $resource;
         // If method is not available, set status code to 404
         if (method_exists($this, $controller_method)) {
             call_user_func_array(array($this, $controller_method), $arguments);
         } else {
             $this->response->status = 404;
             return;
         }
     } else {
         $this->response(array('status' => 0, 'error' => 'Not Authorized'), 401);
     }
 }
Exemple #24
0
 /**
  * Class initialisation
  */
 public static function _init()
 {
     // just checkin', do we have Opauth installed?
     if (!class_exists('Opauth')) {
         throw new \OpauthException('Opauth composer package not installed. Add "opauth/opauth" to composer.json and run a composer update.');
     }
     // load the auth and opauth config
     \Config::load('auth', true);
     \Config::load('opauth', true);
     // determine the auth driver we're going to use
     $drivers = \Config::get('auth.driver', array());
     is_array($drivers) or $drivers = array($drivers);
     if (in_array('Simpleauth', $drivers)) {
         // get the tablename
         \Config::load('simpleauth', true);
         static::$provider_table = \Config::get('simpleauth.table_name', 'users') . '_providers';
         static::$db_connection = \Config::get('simpleauth.db_connection', null);
     } elseif (in_array('Ormauth', $drivers)) {
         // get the tablename
         \Config::load('ormauth', true);
         static::$provider_table = \Config::get('ormauth.table_name', 'users') . '_providers';
         static::$db_connection = \Config::get('ormauth.db_connection', null);
     } else {
         throw new \OpauthException('No supported driver found. Opauth currently only supports Simpleauth and Ormauth.');
     }
 }
Exemple #25
0
	/**
	 * Init
	 *
	 * Loads in the config and sets the variables
	 *
	 * @access	public
	 * @return	void
	 */
	public static function _init()
	{
		// Prevent multiple initializations
		if (static::$initialized)
		{
			return;
		}

		\Config::load('asset', true);

		$paths = \Config::get('asset.paths');

		foreach($paths as $path)
		{
			static::add_path($path);
		}

		static::$_asset_url = \Config::get('asset.url');

		static::$_folders = array(
			'css'	=>	\Config::get('asset.css_dir'),
			'js'	=>	\Config::get('asset.js_dir'),
			'img'	=>	\Config::get('asset.img_dir')
		);

		static::$initialized = true;
	}
 /**
  * The index action
  * 
  * @access public
  * @return void
  */
 public function action_index()
 {
     $settings = \Config::load('autoresponder.db');
     // $autoResponder = Model_Setting::find(array('where' => array(array('meta_key', '=', 'auto-responders'))));
     if (\Input::post()) {
         $input = \Input::post();
         if (!\Input::is_ajax()) {
             $val = Model_Setting::validate('create');
             if (!$val->run()) {
                 if ($val->error() != array()) {
                     // show validation errors
                     \Messages::error('<strong>There was an error while trying to create settings</strong>');
                     foreach ($val->error() as $e) {
                         \Messages::error($e->get_message());
                     }
                 }
             } else {
                 try {
                     \Config::save('autoresponder.db', array('logo_url' => $input['logo_url'], 'company_name' => $input['company_name'], 'address' => $input['address'], 'website' => $input['website'], 'phone' => $input['phone'], 'email_address' => $input['email_address'], 'sender_email_address' => $input['sender_email_address'], 'contact_us_email_address' => $input['contact_us_email_address'], 'instagram_account_name' => $input['instagram_account_name'], 'facebook_account_name' => $input['facebook_account_name']));
                     // $setting->save();
                     \Messages::success('Settings successfully created.');
                     \Response::redirect('admin/settings');
                 } catch (\Database_Exception $e) {
                     // show validation errors
                     \Messages::error('<strong>There was an error while trying to create settings.</strong>');
                     // Uncomment lines below to show database errors
                     $errors = $e->getMessage();
                     \Messages::error($errors);
                 }
             }
         }
     }
     \View::set_global('title', 'Settings');
     \Theme::instance()->set_partial('content', $this->view_dir . 'index')->set('settings', $settings, false);
 }
Exemple #27
0
 /**
  * Router
  *
  * Requests are not made to methods directly The request will be for an "object".
  * this simply maps the object and method to the correct Controller method.
  *
  * @param  string
  * @param  array
  */
 public function router($resource, array $arguments)
 {
     \Config::load('rest', true);
     // If no (or an invalid) format is given, auto detect the format
     if (is_null($this->format) or !array_key_exists($this->format, $this->_supported_formats)) {
         // auto-detect the format
         $this->format = array_key_exists(\Input::extension(), $this->_supported_formats) ? \Input::extension() : $this->_detect_format();
     }
     //Check method is authorized if required
     if (\Config::get('rest.auth') == 'basic') {
         $valid_login = $this->_prepare_basic_auth();
     } elseif (\Config::get('rest.auth') == 'digest') {
         $valid_login = $this->_prepare_digest_auth();
     }
     //If the request passes auth then execute as normal
     if (\Config::get('rest.auth') == '' or $valid_login) {
         // If they call user, go to $this->post_user();
         $controller_method = strtolower(\Input::method()) . '_' . $resource;
         // Fall back to action_ if no rest method is provided
         if (!method_exists($this, $controller_method)) {
             $controller_method = 'action_' . $resource;
         }
         // If method is not available, set status code to 404
         if (method_exists($this, $controller_method)) {
             return call_user_func_array(array($this, $controller_method), $arguments);
         } else {
             $this->response->status = $this->no_method_status;
             return;
         }
     } else {
         $this->response(array('status' => 0, 'error' => 'Not Authorized'), 401);
     }
 }
Exemple #28
0
 /**
  * コンストラクタ
  */
 public function __construct($args = array())
 {
     \Config::load(self::$config_filename, true);
     $this->config['master'] = \Config::get(self::$config_filename, array());
     $this->load_config();
     $this->create_TCPDF($args);
 }
 /**
  * Get a singleton Database instance. If configuration is not specified,
  * it will be loaded from the database configuration file using the same
  * group as the name.
  *
  *     // Load the default database
  *     $db = static::instance();
  *
  *     // Create a custom configured instance
  *     $db = static::instance('custom', $config);
  *
  * @param   string $name     instance name
  * @param   array  $config   configuration parameters
  * @param   bool   $writable when replication is enabled, whether to return the master connection
  *
  * @return  Database_Connection
  *
  * @throws \FuelException
  */
 public static function instance($name = null, array $config = null, $writable = true)
 {
     \Config::load('db', true);
     if ($name === null) {
         // Use the default instance name
         $name = \Config::get('db.active');
     }
     if (!$writable and $readonly = \Config::get("db.{$name}.readonly", false)) {
         !isset(static::$_readonly[$name]) and static::$_readonly[$name] = \Arr::get($readonly, array_rand($readonly));
         $name = static::$_readonly[$name];
     }
     if (!isset(static::$instances[$name])) {
         if ($config === null) {
             // Load the configuration for this database
             $config = \Config::get("db.{$name}");
         }
         if (!isset($config['type'])) {
             throw new \FuelException('Database type not defined in "{$name}" configuration or "{$name}" configuration does not exist');
         }
         // Set the driver class name
         $driver = '\\Database_' . ucfirst($config['type']) . '_Connection';
         // Create the database connection instance
         new $driver($name, $config);
     }
     return static::$instances[$name];
 }
Exemple #30
0
 /**
  * Load the active theme.
  *
  * This is called at bootstrap time.
  * We will only ever have one theme active for any given request.
  *
  * @uses Kohana::modules
  */
 public static function load_themes()
 {
     $config = Config::load('site');
     self::$themes = self::available(FALSE);
     //set admin theme based on path info
     $path = ltrim(Request::detect_uri(), '/');
     Theme::$is_admin = $path == "admin" || !strncmp($path, "admin/", 6);
     if (Theme::$is_admin) {
         // Load the admin theme
         Theme::$active = $config->get('admin_theme', 'cerber');
     } else {
         // Load the site theme
         Theme::$active = $config->get('theme', 'cerber');
     }
     //Set mobile theme, if enabled and mobile request
     if (Request::is_mobile() and $config->get('mobile_theme', FALSE)) {
         // Load the mobile theme
         Theme::$active = $config->get('mobile_theme', 'cerber');
     }
     // Admins can override the site theme, temporarily. This lets us preview themes.
     if (User::is_admin() and isset($_GET['theme']) and $override = Text::plain($_GET['theme'])) {
         Theme::$active = $override;
     }
     //Finally set the active theme
     Theme::set_theme();
 }