Ejemplo n.º 1
0
 /**
  * Returns a new instance of the Kohana_Config library
  * based on the singleton pattern
  *
  * @param   string       driver
  * @return  Kohana_Config
  * @access  public
  * @static
  */
 public static function &instance()
 {
     // If the driver has not been initialised, intialise it
     if (empty(Kohana_Config::$instance)) {
         //call a 1 time non singleton of Kohana_Config to get a list of drivers
         $config = new Kohana_Config(array('config_drivers' => array(), 'internal_cache' => FALSE));
         $core_config = $config->get('core');
         Kohana_Config::$instance = new Kohana_Config($core_config);
     }
     // Return the Kohana_Config driver requested
     return Kohana_Config::$instance;
 }
Ejemplo n.º 2
0
 /**
  * Load the active theme.  This is called at bootstrap time.  We will only ever have one theme
  * active for any given request.
  */
 static function load_themes()
 {
     $input = Input::instance();
     $path = $input->server("PATH_INFO");
     if (empty($path)) {
         $path = "/" . $input->get("kohana_uri");
     }
     $config = Kohana_Config::instance();
     $modules = $config->get("core.modules");
     self::$is_admin = $path == "/admin" || !strncmp($path, "/admin/", 7);
     self::$site_theme_name = module::get_var("gallery", "active_site_theme");
     if (self::$is_admin) {
         // Load the admin theme
         self::$admin_theme_name = module::get_var("gallery", "active_admin_theme");
         array_unshift($modules, THEMEPATH . self::$admin_theme_name);
         // If the site theme has an admin subdir, load that as a module so that
         // themes can provide their own code.
         if (file_exists(THEMEPATH . self::$site_theme_name . "/admin")) {
             array_unshift($modules, THEMEPATH . self::$site_theme_name . "/admin");
         }
     } else {
         // Admins can override the site theme, temporarily.  This lets us preview themes.
         if (identity::active_user()->admin && ($override = $input->get("theme"))) {
             if (file_exists(THEMEPATH . $override)) {
                 self::$site_theme_name = $override;
             } else {
                 Kohana_Log::add("error", "Missing override theme: '{$override}'");
             }
         }
         array_unshift($modules, THEMEPATH . self::$site_theme_name);
     }
     $config->set("core.modules", $modules);
 }
Ejemplo n.º 3
0
 function setup()
 {
     $config = Kohana_Config::instance();
     $config->set("database.mock.connection.type", "mock");
     $config->set("database.mock.cache", false);
     $config->set("database.mock.table_prefix", "g_");
 }
Ejemplo n.º 4
0
 /**
  * Get the singleton instance of Kohana_Config.
  *
  *     $config = Kohana_Config::instance();
  *
  * @return  Kohana_Config
  */
 public static function instance()
 {
     if (self::$_instance === NULL) {
         // Create a new instance
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 public function setUp()
 {
     if (($config = Kohana::config('cache.testing.file')) === NULL) {
         $this->markTestSkipped('No cache.testing.file config found.');
     }
     Kohana_Config::instance()->set('cache.testing.file.requests', 1);
     $this->cache = Cache::instance('testing.file');
     parent::setUp();
 }
Ejemplo n.º 6
0
 /**
  * Load the active theme.  This is called at bootstrap time.  We will only ever have one theme
  * active for any given request.
  */
 static function load_themes()
 {
     $input = Input::instance();
     $path = $input->server("PATH_INFO");
     if (empty($path)) {
         $path = "/" . $input->get("kohana_uri");
     }
     $config = Kohana_Config::instance();
     $modules = $config->get("core.modules");
     // Normally Router::find_uri() strips off the url suffix for us, but we're working off of the
     // PATH_INFO here so we need to strip it off manually
     if ($suffix = Kohana::config("core.url_suffix")) {
         $path = preg_replace("#" . preg_quote($suffix) . "\$#u", "", $path);
     }
     self::$is_admin = $path == "/admin" || !strncmp($path, "/admin/", 7);
     self::$site_theme_name = module::get_var("gallery", "active_site_theme");
     // If the site theme doesn't exist, fall back to wind.
     if (!file_exists(THEMEPATH . self::$site_theme_name . "/theme.info")) {
         site_status::error(t("Theme '%name' is missing.  Falling back to the Wind theme.", array("name" => self::$site_theme_name)), "missing_site_theme");
         module::set_var("gallery", "active_site_theme", self::$site_theme_name = "wind");
     }
     if (self::$is_admin) {
         // Load the admin theme
         self::$admin_theme_name = module::get_var("gallery", "active_admin_theme");
         // If the admin theme doesn't exist, fall back to admin_wind.
         if (!file_exists(THEMEPATH . self::$admin_theme_name . "/theme.info")) {
             site_status::error(t("Admin theme '%name' is missing!  Falling back to the Wind theme.", array("name" => self::$admin_theme_name)), "missing_admin_theme");
             module::set_var("gallery", "active_admin_theme", self::$admin_theme_name = "admin_wind");
         }
         array_unshift($modules, THEMEPATH . self::$admin_theme_name);
         // If the site theme has an admin subdir, load that as a module so that
         // themes can provide their own code.
         if (file_exists(THEMEPATH . self::$site_theme_name . "/admin")) {
             array_unshift($modules, THEMEPATH . self::$site_theme_name . "/admin");
         }
         // Admins can override the site theme, temporarily.  This lets us preview themes.
         if (identity::active_user()->admin && ($override = $input->get("theme"))) {
             if (file_exists(THEMEPATH . $override)) {
                 self::$admin_theme_name = $override;
                 array_unshift($modules, THEMEPATH . self::$admin_theme_name);
             } else {
                 Kohana_Log::add("error", "Missing override admin theme: '{$override}'");
             }
         }
     } else {
         // Admins can override the site theme, temporarily.  This lets us preview themes.
         if (identity::active_user()->admin && ($override = $input->get("theme"))) {
             if (file_exists(THEMEPATH . $override)) {
                 self::$site_theme_name = $override;
             } else {
                 Kohana_Log::add("error", "Missing override site theme: '{$override}'");
             }
         }
         array_unshift($modules, THEMEPATH . self::$site_theme_name);
     }
     $config->set("core.modules", $modules);
 }
Ejemplo n.º 7
0
 public function logout($destroy = FALSE, $logout_all = FALSE)
 {
     $settings = Kohana_Config::instance()->load("mmdb");
     if (empty($settings->localMachine)) {
         $user = $this->get_user();
         if (!empty($user->kids_id)) {
             setcookie("kidsessionid", null, -1, "/", ".nationalgeographic.com");
         }
     }
     parent::logout($destroy, $logout_all);
 }
Ejemplo n.º 8
0
 public function __construct($request)
 {
     parent::__construct($request);
     $this->template = View::factory('hmo_masterpage');
     $config = Kohana_Config::instance()->load("config");
     $this->site = $config['app_path'];
     $this->session = Session::instance();
     if ($this->authenticate) {
         $this->authenticate();
     }
     $this->message = I18n::load('en-us');
 }
Ejemplo n.º 9
0
 public function action_download()
 {
     $this->template->content->download_url = FALSE;
     $versions = Kohana_Config::instance()->load('kohana');
     if ($version = Arr::get($_GET, 'get')) {
         if (($requested_version = self::multi_array_key_exists($version, $versions)) !== FALSE) {
             // Try to start the download
             $this->template->content->download_url = Arr::get($requested_version, 'download');
             $this->template->meta_tags[] = array('http-equiv' => 'refresh', 'content' => '2; ' . $requested_version['download']);
         }
     }
     $this->template->content->versions = $versions;
 }
 public function setUp()
 {
     if (!extension_loaded('sqlite')) {
         $this->markTestSkipped('The Sqlite extension is not loaded');
     }
     if (($config = Kohana::config('cache.testing.sqlite')) === NULL) {
         $this->markTestSkipped('No cache.testing.sqlite config found.');
     }
     if (Kohana::config('cache_sqlite') === NULL) {
         $this->markTestSkipped('No cache_sqlite config found.');
     }
     Kohana_Config::instance()->set('cache.testing.sqlite.requests', 1);
     $this->cache = Cache::instance('testing.sqlite');
     parent::setUp();
 }
Ejemplo n.º 11
0
 /**
  * Creates a new configuration object for the specified group. When caching
  * is enabled, Kohana_Config will attempt to load the group from the cache.
  *
  * @param   string   group name
  * @param   boolean  cache the group array
  * @return  void
  */
 public function __construct($group, $cache = TRUE)
 {
     // Set the configuration group name
     $this->_configuration_group = $group;
     if ($cache === FALSE) {
         // Load the configuration
         $config = Kohana_Config::load($group);
     } elseif (($config = Kohana::cache(self::CACHE_PREFIX . $group)) === NULL) {
         // Load the configuration, it has not been cached
         $config = Kohana_Config::load($group);
         // Create a cache of the configuration group
         Kohana::cache(self::CACHE_PREFIX . $group, $config);
     }
     // Load the array using the values as properties
     ArrayObject::__construct($config, ArrayObject::ARRAY_AS_PROPS);
 }
Ejemplo n.º 12
0
 /**
  * Handles XHR POST request for file upload from RTE
  * This is a base example of how an upload can work
  * This method should be overridden to validate file types (images for example) or
  * custom functionality like cropping, resizing, etc. 
  * Based on the jqueryrte uploader.php file by Andrey Gayvoronsky - http://www.gayvoronsky.com
  * located at http://code.google.com/p/lwrte/source/browse/trunk/toolbar/uploader.php
  * 
  * @return string
  */
 public function action_upload()
 {
     $config = Kohana_Config::instance()->load('lwrte');
     $upload_dir = $config['upload']['abs_path'];
     // only handles one file
     $file = current($_FILES);
     if ($file['error'] == UPLOAD_ERR_OK) {
         //no errors, 0 - is our error code for 'moving error'
         if (move_uploaded_file($file['tmp_name'], "{$upload_dir}/{$file['name']}")) {
             $file['error'] = '';
         }
     }
     $arr = array('error' => $file['error'], 'file' => "{$config['upload']['rel_path']}/{$file['name']}", 'tmpfile' => $file['tmp_name'], 'size' => $file['size']);
     if (function_exists('json_encode')) {
         $this->request->response = json_encode($arr);
     } else {
         $result = array();
         foreach ($arr as $key => $val) {
             $val = is_bool($val) ? $val ? 'true' : 'false' : $val;
             $result[] = "'{$key}':'{$val}'";
         }
         $this->request->response = '{' . implode(',', $result) . '}';
     }
 }
Ejemplo n.º 13
0
 /**
  * Calling load() with a group that doesn't exist, should get it to use the last reader
  * to create a new config group
  *
  * @test
  * @covers Kohana_Config::load
  */
 public function test_load_returns_new_config_group_if_one_dnx()
 {
     $config = new Kohana_Config();
     $group = 'my_group';
     $reader1 = $this->getMock('Kohana_Config_Reader');
     $reader2 = $this->getMock('Kohana_Config_Reader', array('load'), array(), 'Kohana_Config_Waffles');
     // This is a slightly hacky way of doing it, but it works
     $reader2->expects($this->exactly(2))->method('load')->with($group)->will($this->onConsecutiveCalls($this->returnValue(FALSE), $this->returnValue(clone $reader2)));
     $config->attach($reader1)->attach($reader2);
     $new_config = $config->load('my_group');
     $this->assertInstanceOf('Kohana_Config_Waffles', $new_config);
     // Slightly taboo, testing a different api!!
     $this->assertSame(array(), $new_config->as_array());
 }
Ejemplo n.º 14
0
Archivo: core.php Proyecto: ascseb/core
 /**
  * Initializes the environment:
  *
  * - Disables register_globals and magic_quotes_gpc
  * - Determines the current environment
  * - Set global settings
  * - Sanitizes GET, POST, and COOKIE variables
  * - Converts GET, POST, and COOKIE variables to the global character set
  *
  * Any of the global settings can be set here:
  *
  * > boolean "errors"      : use internal error and exception handling?
  * > boolean "profile"     : do internal benchmarking?
  * > boolean "caching"     : cache the location of files between requests?
  * > string  "charset"     : character set used for all input and output
  * > string  "base_url"    : set the base URL for the application
  * > string  "index_file"  : set the index.php file name
  * > string  "cache_dir"   : set the cache directory path
  *
  * @throws  Kohana_Exception
  * @param   array   global settings
  * @return  void
  */
 public static function init(array $settings = NULL)
 {
     static $run;
     // This function can only be run once
     if ($run === TRUE) {
         return;
     }
     // The system is now ready
     $run = TRUE;
     if (isset($settings['profile'])) {
         // Enable profiling
         self::$profiling = (bool) $settings['profile'];
     }
     if (self::$profiling === TRUE) {
         // Start a new benchmark
         $benchmark = Profiler::start(__CLASS__, __FUNCTION__);
     }
     // Start an output buffer
     ob_start();
     if (isset($settings['errors'])) {
         // Enable error handling
         Kohana::$errors = (bool) $settings['errors'];
     }
     if (Kohana::$errors === TRUE) {
         // Enable the Kohana shutdown handler, which catches E_FATAL errors.
         register_shutdown_function(array('Kohana', 'shutdown_handler'));
         // Enable Kohana exception handling, adds stack traces and error source.
         set_exception_handler(array('Kohana', 'exception_handler'));
         // Enable Kohana error handling, converts all PHP errors to exceptions.
         set_error_handler(array('Kohana', 'error_handler'));
     }
     if (ini_get('register_globals')) {
         if (isset($_REQUEST['GLOBALS'])) {
             // Prevent malicious GLOBALS overload attack
             echo "Global variable overload attack detected! Request aborted.\n";
             // Exit with an error status
             exit(1);
         }
         // Get the variable names of all globals
         $global_variables = array_keys($GLOBALS);
         // Remove the standard global variables from the list
         $global_variables = array_diff($global_variables, array('GLOBALS', '_REQUEST', '_GET', '_POST', '_FILES', '_COOKIE', '_SERVER', '_ENV', '_SESSION'));
         foreach ($global_variables as $name) {
             // Retrieve the global variable and make it null
             global ${$name};
             ${$name} = NULL;
             // Unset the global variable, effectively disabling register_globals
             unset($GLOBALS[$name], ${$name});
         }
     }
     // Determine if we are running in a command line environment
     self::$is_cli = PHP_SAPI === 'cli';
     // Determine if we are running in a Windows environment
     self::$is_windows = DIRECTORY_SEPARATOR === '\\';
     if (isset($settings['cache_dir'])) {
         // Set the cache directory path
         self::$cache_dir = realpath($settings['cache_dir']);
     } else {
         // Use the default cache directory
         self::$cache_dir = APPPATH . 'cache';
     }
     if (!is_writable(self::$cache_dir)) {
         throw new Kohana_Exception('Directory :dir must be writable', array(':dir' => Kohana::debug_path(self::$cache_dir)));
     }
     if (isset($settings['caching'])) {
         // Enable or disable internal caching
         self::$caching = (bool) $settings['caching'];
     }
     if (self::$caching === TRUE) {
         // Load the file path cache
         self::$_files = Kohana::cache('Kohana::find_file()');
     }
     if (isset($settings['charset'])) {
         // Set the system character set
         self::$charset = strtolower($settings['charset']);
     }
     if (isset($settings['base_url'])) {
         // Set the base URL
         self::$base_url = rtrim($settings['base_url'], '/') . '/';
     }
     if (isset($settings['index_file'])) {
         // Set the index file
         self::$index_file = trim($settings['index_file'], '/');
     }
     // Determine if the extremely evil magic quotes are enabled
     self::$magic_quotes = (bool) get_magic_quotes_gpc();
     // Sanitize all request variables
     $_GET = self::sanitize($_GET);
     $_POST = self::sanitize($_POST);
     $_COOKIE = self::sanitize($_COOKIE);
     // Load the logger
     self::$log = Kohana_Log::instance();
     // Load the config
     self::$config = Kohana_Config::instance();
     if (isset($benchmark)) {
         // Stop benchmarking
         Profiler::stop($benchmark);
     }
 }
Ejemplo n.º 15
0
 /**
  * Load the active modules.  This is called at bootstrap time.
  */
 static function load_modules()
 {
     self::$modules = array();
     self::$active = array();
     $kohana_modules = array();
     // In version 32 we introduced a weight column so we can specify the module order
     // If we try to use that blindly, we'll break earlier versions before they can even
     // run the upgrader.
     $modules = module::get_version("gallery") < 32 ? ORM::factory("module")->find_all() : ORM::factory("module")->order_by("weight")->find_all();
     foreach ($modules as $module) {
         self::$modules[$module->name] = $module;
         if (!$module->active) {
             continue;
         }
         if ($module->name == "gallery") {
             $gallery = $module;
         } else {
             self::$active[] = $module;
             $kohana_modules[] = MODPATH . $module->name;
         }
     }
     self::$active[] = $gallery;
     // put gallery last in the module list to match core.modules
     $config = Kohana_Config::instance();
     $config->set("core.modules", array_merge($kohana_modules, $config->get("core.modules")));
 }
Ejemplo n.º 16
0
 /**
  * Initializes the environment:
  *
  * - Disables register_globals and magic_quotes_gpc
  * - Determines the current environment
  * - Set global settings
  * - Sanitizes GET, POST, and COOKIE variables
  * - Converts GET, POST, and COOKIE variables to the global character set
  *
  * Any of the global settings can be set here:
  *
  * Type      | Setting    | Description                                    | Default Value
  * ----------|------------|------------------------------------------------|---------------
  * `boolean` | errors     | use internal error and exception handling?     | `TRUE`
  * `boolean` | profile    | do internal benchmarking?                      | `TRUE`
  * `boolean` | caching    | cache the location of files between requests?  | `FALSE`
  * `string`  | charset    | character set used for all input and output    | `"utf-8"`
  * `string`  | base_url   | set the base URL for the application           | `"/"`
  * `string`  | index_file | set the index.php file name                    | `"index.php"`
  * `string`  | cache_dir  | set the cache directory path                   | `APPPATH."cache"`
  *
  * @throws  Kohana_Exception
  * @param   array   global settings
  * @return  void
  * @uses    Kohana::globals
  * @uses    Kohana::sanitize
  * @uses    Kohana::cache
  * @uses    Profiler
  */
 public static function init(array $settings = NULL)
 {
     if (Kohana::$_init) {
         // Do not allow execution twice
         return;
     }
     // Kohana is now initialized
     Kohana::$_init = TRUE;
     if (isset($settings['profile'])) {
         // Enable profiling
         Kohana::$profiling = (bool) $settings['profile'];
     }
     if (Kohana::$profiling === TRUE) {
         // Start a new benchmark
         $benchmark = Profiler::start('Kohana', __FUNCTION__);
     }
     // Start an output buffer
     ob_start();
     if (defined('E_DEPRECATED')) {
         // E_DEPRECATED only exists in PHP >= 5.3.0
         Kohana::$php_errors[E_DEPRECATED] = 'Deprecated';
     }
     if (isset($settings['errors'])) {
         // Enable error handling
         Kohana::$errors = (bool) $settings['errors'];
     }
     if (Kohana::$errors === TRUE) {
         // Enable Kohana exception handling, adds stack traces and error source.
         set_exception_handler(array('Kohana', 'exception_handler'));
         // Enable Kohana error handling, converts all PHP errors to exceptions.
         set_error_handler(array('Kohana', 'error_handler'));
     }
     // Enable the Kohana shutdown handler, which catches E_FATAL errors.
     register_shutdown_function(array('Kohana', 'shutdown_handler'));
     if (ini_get('register_globals')) {
         // Reverse the effects of register_globals
         Kohana::globals();
     }
     // Determine if we are running in a command line environment
     Kohana::$is_cli = PHP_SAPI === 'cli';
     // Determine if we are running in a Windows environment
     Kohana::$is_windows = DIRECTORY_SEPARATOR === '\\';
     if (isset($settings['cache_dir'])) {
         // Set the cache directory path
         Kohana::$cache_dir = realpath($settings['cache_dir']);
     } else {
         // Use the default cache directory
         Kohana::$cache_dir = APPPATH . 'cache';
     }
     if (!is_writable(Kohana::$cache_dir)) {
         throw new Kohana_Exception('Directory :dir must be writable', array(':dir' => Kohana::debug_path(Kohana::$cache_dir)));
     }
     if (isset($settings['caching'])) {
         // Enable or disable internal caching
         Kohana::$caching = (bool) $settings['caching'];
     }
     if (Kohana::$caching === TRUE) {
         // Load the file path cache
         Kohana::$_files = Kohana::cache('Kohana::find_file()');
     }
     if (isset($settings['charset'])) {
         // Set the system character set
         Kohana::$charset = strtolower($settings['charset']);
     }
     if (function_exists('mb_internal_encoding')) {
         // Set the MB extension encoding to the same character set
         mb_internal_encoding(Kohana::$charset);
     }
     if (isset($settings['base_url'])) {
         // Set the base URL
         Kohana::$base_url = rtrim($settings['base_url'], '/') . '/';
     }
     if (isset($settings['index_file'])) {
         // Set the index file
         Kohana::$index_file = trim($settings['index_file'], '/');
     }
     // Determine if the extremely evil magic quotes are enabled
     Kohana::$magic_quotes = (bool) get_magic_quotes_gpc();
     // Sanitize all request variables
     $_GET = Kohana::sanitize($_GET);
     $_POST = Kohana::sanitize($_POST);
     $_COOKIE = Kohana::sanitize($_COOKIE);
     // Load the logger
     Kohana::$log = Kohana_Log::instance();
     // Load the config
     Kohana::$config = Kohana_Config::instance();
     if (isset($benchmark)) {
         // Stop benchmarking
         Profiler::stop($benchmark);
     }
 }
Ejemplo n.º 17
0
 function index()
 {
     if (!TEST_MODE) {
         throw new Kohana_404_Exception();
     }
     // Force strict behavior to flush out bugs early
     ini_set("display_errors", true);
     error_reporting(-1);
     // Jump through some hoops to satisfy the way that we check for the site_domain in
     // config.php.  We structure this such that the code in config will leave us with a
     // site_domain of "." (for historical reasons)
     // @todo: for tests, we should force the site_domain to something like example.com
     $_SERVER["SCRIPT_FILENAME"] = "index.php";
     $_SERVER["SCRIPT_NAME"] = "./index.php";
     $config = Kohana_Config::instance();
     $original_config = DOCROOT . "var/database.php";
     $test_config = VARPATH . "database.php";
     if (!file_exists($original_config)) {
         print "Please copy kohana/config/database.php to {$original_config}.\n";
         return;
     } else {
         copy($original_config, $test_config);
         $db_config = Kohana::config('database');
         if (empty($db_config['unit_test'])) {
             $default = $db_config['default'];
             $conn = $default['connection'];
             $config->set('database.unit_test.benchmark', $default['benchmark']);
             $config->set('database.unit_test.persistent', $default['persistent']);
             $config->set('database.unit_test.connection.type', $conn['type']);
             $config->set('database.unit_test.connection.user', $conn['user']);
             $config->set('database.unit_test.connection.pass', $conn['pass']);
             $config->set('database.unit_test.connection.host', $conn['host']);
             $config->set('database.unit_test.connection.port', $conn['port']);
             $config->set('database.unit_test.connection.socket', $conn['socket']);
             $config->set('database.unit_test.connection.database', "{$conn['database']}_test");
             $config->set('database.unit_test.character_set', $default['character_set']);
             $config->set('database.unit_test.table_prefix', $default['table_prefix']);
             $config->set('database.unit_test.object', $default['object']);
             $config->set('database.unit_test.cache', $default['cache']);
             $config->set('database.unit_test.escape', $default['escape']);
             $db_config = Kohana::config('database');
         }
         if ($db_config['default']['connection']['database'] == $db_config['unit_test']['connection']['database']) {
             print "Don't use the default database for your unit tests or you'll lose all your data.\n";
             return;
         }
         try {
             $db = Database::instance('unit_test');
             $db->connect();
             // Make this the default database for the rest of this run
             Database::set_default_instance($db);
         } catch (Exception $e) {
             print "{$e->getMessage()}\n";
             return;
         }
     }
     try {
         // Clean out the database
         if ($tables = $db->list_tables()) {
             foreach ($db->list_tables() as $table) {
                 $db->query("DROP TABLE {{$table}}");
             }
         }
         // Clean out the filesystem.  Note that this cleans out test/var/database.php, but that's ok
         // because we technically don't need it anymore.  If this is confusing, we could always
         // arrange to preserve that one file.
         @system("rm -rf test/var");
         @mkdir('test/var/logs', 0777, true);
         $active_modules = module::$active;
         // Reset our caches
         module::$modules = array();
         module::$active = array();
         module::$var_cache = array();
         $db->clear_cache();
         // Rest the cascading class path
         $config->set("core", $config->load("core"));
         // Install the active modules
         // Force gallery and user to be installed first to resolve dependencies.
         gallery_installer::install(true);
         module::load_modules();
         module::install("user");
         module::activate("user");
         $modules = $paths = array();
         foreach (module::available() as $module_name => $unused) {
             if (in_array($module_name, array("gallery", "user"))) {
                 $paths[] = MODPATH . "{$module_name}/tests";
                 continue;
             }
             if (file_exists($path = MODPATH . "{$module_name}/tests")) {
                 $paths[] = $path;
                 module::install($module_name);
                 module::activate($module_name);
             }
         }
         $config->set('unit_test.paths', $paths);
         // Trigger late-binding install actions (defined in gallery_event::user_login)
         graphics::choose_default_toolkit();
         $filter = count($_SERVER["argv"]) > 2 ? $_SERVER["argv"][2] : null;
         print new Unit_Test($modules, $filter);
     } catch (ORM_Validation_Exception $e) {
         print "Validation Exception: {$e->getMessage()}\n";
         print $e->getTraceAsString() . "\n";
         foreach ($e->validation->errors() as $field => $msg) {
             print "{$field}: {$msg}\n";
         }
     } catch (Exception $e) {
         print "Exception: {$e->getMessage()}\n";
         print $e->getTraceAsString() . "\n";
     }
 }
Ejemplo n.º 18
0
 /**
  * Get list of possible model bindings
  *
  * @param   boolean|string  true = short list, false = full list, string = specific bind
  * @return  array
  */
 public static function binds($bind = true)
 {
     static $config;
     // Load bind config
     if (!is_array($config)) {
         $config = (array) Kohana_Config::instance()->get('forum.bind');
     }
     if ($bind === true) {
         // Short list for selects etc
         $list = array();
         foreach ($config as $type => $data) {
             $list[$type] = $data['name'];
         }
         return $list;
     } else {
         if ($bind === false) {
             // Full bind config
             return $config;
         } else {
             if (is_string($bind)) {
                 // Specific config
                 return $config[$bind];
             }
         }
     }
 }
Ejemplo n.º 19
0
 /**
  * Template loading and setup routine.
  */
 public function __construct()
 {
     parent::__construct();
     // Get loaded modules
     $this->modules = Kohana_Config::instance()->get('core.modules');
     // Initialize libraries
     $this->cache = Cache::instance();
     $this->input = Input::instance();
     $this->uri = URI::instance();
     $this->visitor = Visitor::instance();
     // Validate CSRF token
     if (isset($_REQUEST['csrf'])) {
         $this->valid_csrf = csrf::valid($_REQUEST['csrf']);
     }
     // Load current user for easy controller access, null if not logged
     $this->user =& $this->visitor->get_user();
     // Build the page
     $this->template = View::factory($this->template);
     // Display the template immediately after the controller method?
     if ($this->auto_render === true) {
         Event::add('system.post_controller', array($this, '_display'));
     }
 }
Ejemplo n.º 20
0
 public function setup()
 {
     Kohana_Config::instance()->set("sendmail.from", "*****@*****.**");
 }
Ejemplo n.º 21
0
 /**
  * Gets an array from Kohan_Config
  * 
  * @return array
  */
 protected static function _get_config($type)
 {
     $config = Kohana_Config::instance()->load('lwrte');
     return $config[$type];
 }
Ejemplo n.º 22
0
 /**
  * Load the active modules.  This is called at bootstrap time.
  */
 static function load_modules()
 {
     self::$modules = array();
     self::$active = array();
     $kohana_modules = array();
     foreach (ORM::factory("module")->find_all() as $module) {
         self::$modules[$module->name] = $module;
         if (!$module->active) {
             continue;
         }
         if ($module->name == "gallery") {
             $gallery = $module;
         } else {
             self::$active[] = $module;
             $kohana_modules[] = MODPATH . $module->name;
         }
     }
     self::$active[] = $gallery;
     // put gallery last in the module list to match core.modules
     $config = Kohana_Config::instance();
     $config->set("core.modules", array_merge($kohana_modules, $config->get("core.modules")));
 }
Ejemplo n.º 23
0
 /**
  * Get a config item or group proxies Kohana_Config.
  *
  * @param   string   item name
  * @param   boolean  force a forward slash (/) at the end of the item
  * @param   boolean  is the item required?
  * @return  mixed
  */
 public static function config($key, $slash = FALSE, $required = FALSE)
 {
     return Kohana_Config::instance()->get($key, $slash, $required);
 }
Ejemplo n.º 24
0
 /**
  * Choose which driver the Kohana Image library uses.
  */
 static function init_toolkit()
 {
     if (self::$init) {
         return;
     }
     switch (module::get_var("gallery", "graphics_toolkit")) {
         case "gd":
             Kohana_Config::instance()->set("image.driver", "GD");
             break;
         case "imagemagick":
             Kohana_Config::instance()->set("image.driver", "ImageMagick");
             Kohana_Config::instance()->set("image.params.directory", module::get_var("gallery", "graphics_toolkit_path"));
             break;
         case "graphicsmagick":
             Kohana_Config::instance()->set("image.driver", "GraphicsMagick");
             Kohana_Config::instance()->set("image.params.directory", module::get_var("gallery", "graphics_toolkit_path"));
             break;
     }
     self::$init = 1;
 }
Ejemplo n.º 25
0
 public function __construct(Request $request)
 {
     parent::__construct($request);
     $this->_config = Kohana_Config::instance()->load('ledger');
     $this->_user = Kuaas::instance()->get_user();
 }
Ejemplo n.º 26
0
 /**
  * Frees the current instance of the identity provider so the next call to instance will reload
  *
  * @param   string  configuration
  * @return  Identity_Core
  */
 static function reset()
 {
     self::$instance = null;
     Kohana_Config::instance()->clear("identity");
 }
 /**
  * @test
  */
 public function find_uri_suffix()
 {
     Kohana::$server_api = 'cgi-fcgi';
     Kohana_Config::instance()->set('core.url_suffix', '.html');
     $_SERVER = array_merge($_SERVER, array('ORIG_PATH_INFO' => NULL, 'PATH_INFO' => '/default/index.html', 'PHP_SELF' => '/' . KOHANA . '/default/index.html', 'REQUEST_URI' => '/default/index.html', 'QUERY_STRING' => NULL, 'SCRIPT_NAME' => '/' . KOHANA));
     Router::find_uri();
     $this->assertEquals('default/index', Router::$current_uri);
     $this->assertEquals('.html', Router::$url_suffix);
 }
Ejemplo n.º 28
0
 /**
  * When we call copy() we expect it to copy the merged config to all writers
  *
  * @TODO This test sucks due to limitations in the phpunit mock generator.  MAKE THIS AWESOME AGAIN!
  * @test
  * @covers Kohana_Config::copy
  */
 public function test_copy_copies_merged_config_to_all_writers()
 {
     $config = new Kohana_Config();
     $reader1 = $this->getMock('Kohana_Config_Reader', array('load'));
     $reader2 = $this->getMock('Kohana_Config_Reader', array('load'));
     $reader1->expects($this->once())->method('load')->with('something')->will($this->returnValue(array('pie' => 'good', 'kohana' => 'awesome')));
     $reader2->expects($this->once())->method('load')->with('something')->will($this->returnValue(array('kohana' => 'good')));
     $writer1 = $this->getMock('Kohana_Config_Writer', array('write'));
     $writer2 = $this->getMock('Kohana_Config_Writer', array('write'));
     // Due to crazy limitations in phpunit's mocking engine we have to be fairly
     // liberal here as to what order we receive the config items
     // Good news is that order shouldn't matter *yay*
     //
     // Now save your eyes and skip the next... 13 lines!
     $key = $this->logicalOr('pie', 'kohana');
     $val = $this->logicalOr('good', 'awesome');
     $writer1->expects($this->exactly(2))->method('write')->with('something', clone $key, clone $val);
     $writer2->expects($this->exactly(2))->method('write')->with('something', clone $key, clone $val);
     $config->attach($reader1)->attach($reader2, FALSE)->attach($writer1)->attach($writer2);
     // Now let's get this thing going!
     $config->copy('something');
 }
 /**
  * Overrides ArrayObject::offsetSet()
  * This method is called when config is changed via
  *
  *     $config->var = 'asd';
  *
  *     // OR
  *
  *     $config['var'] = 'asd';
  *
  * @param string $key   The key of the config item we're changing
  * @param mixed  $value The new array value
  */
 public function offsetSet($key, $value)
 {
     $this->_parent_instance->_write_config($this->_group_name, $key, $value);
     return parent::offsetSet($key, $value);
 }
Ejemplo n.º 30
0
 private static function loadSettings()
 {
     if (empty(self::$settings)) {
         self::$settings = Kohana_Config::instance()->load("mmdb");
     }
 }