示例#1
0
 /**
  * Sets the payment processing fields.
  * The driver will translate these into the specific format for the provider.
  * Standard fields are (Providers may have additional or different fields):
  *
  * card_num
  * exp_date
  * cvv
  * description
  * amount
  * tax
  * shipping
  * first_name
  * last_name
  * company
  * address
  * city
  * state
  * zip
  * email
  * phone
  * fax
  * ship_to_first_name
  * ship_to_last_name
  * ship_to_company
  * ship_to_address
  * ship_to_city
  * ship_to_state
  * ship_to_zip
  *
  * @param  array  the driver string
  */
 public function __construct($config = array())
 {
     if (empty($config)) {
         // Load the default group
         $config = Kohana::config('payment.default');
     } elseif (is_string($config)) {
         $this->config['driver'] = $config;
     }
     // Merge the default config with the passed config
     is_array($config) and $this->config = array_merge($this->config, $config);
     // Set driver name
     $driver = 'Payment_' . ucfirst($this->config['driver']) . '_Driver';
     // Load the driver
     if (!Kohana::auto_load($driver)) {
         throw new Kohana_Exception('core.driver_not_found', $this->config['driver'], get_class($this));
     }
     // Get the driver specific settings
     $this->config = array_merge($this->config, Kohana::config('payment.' . $this->config['driver']));
     // Initialize the driver
     $this->driver = new $driver($this->config);
     // Validate the driver
     if (!$this->driver instanceof Payment_Driver) {
         throw new Kohana_Exception('core.driver_implements', $this->config['driver'], get_class($this), 'Payment_Driver');
     }
 }
示例#2
0
文件: Cache.php 项目: JasonWiki/docs
 /**
  * Loads the configured driver and validates it.
  *
  * @param   array|string  custom configuration or config group name
  * @return  void
  */
 public function __construct($config = FALSE)
 {
     if (is_string($config)) {
         $name = $config;
         // Test the config group name
         if (($config = Kohana::config('cache.' . $config)) === NULL) {
             throw new Cache_Exception('The :group: group is not defined in your configuration.', array(':group:' => $name));
         }
     }
     if (is_array($config)) {
         // Append the default configuration options
         $config += Kohana::config('cache.default');
     } else {
         // Load the default group
         $config = Kohana::config('cache.default');
     }
     // Cache the config in the object
     $this->config = $config;
     // Set driver name
     $driver = 'Cache_' . ucfirst($this->config['driver']) . '_Driver';
     // Load the driver
     if (!Kohana::auto_load($driver)) {
         throw new Cache_Exception('The :driver: driver for the :class: library could not be found', array(':driver:' => $this->config['driver'], ':class:' => get_class($this)));
     }
     // Initialize the driver
     $this->driver = new $driver($this->config['params']);
     // Validate the driver
     if (!$this->driver instanceof Cache_Driver) {
         throw new Cache_Exception('The :driver: driver for the :library: library must implement the :interface: interface', array(':driver:' => $this->config['driver'], ':library:' => get_class($this), ':interface:' => 'Cache_Driver'));
     }
     Kohana_Log::add('debug', 'Cache Library initialized');
 }
示例#3
0
文件: cache.php 项目: azuya/Wi3
 public function auto_load($class)
 {
     if ($this->_run_first) {
         $this->_run_first = FALSE;
         if (is_file($this->_directory . $this->_filename)) {
             // cache expired?
             if (time() - filemtime($this->_directory . $this->_filename) < $this->lifetime) {
                 $this->_cached = TRUE;
                 require $this->_directory . $this->_filename;
                 $this->_classes[$class] = $class;
                 self::$loaded_classes[$class] = $class;
                 if (class_exists($class)) {
                     return TRUE;
                 }
             } else {
                 // Cache has expired
                 unlink($this->_directory . $this->_filename);
             }
         }
     }
     $result = Kohana::auto_load($class);
     $this->_classes[$class] = $class;
     self::$loaded_classes[$class] = $class;
     return $result;
 }
示例#4
0
 /**
  * Configuration options.
  *
  * @return  void
  */
 public function __construct()
 {
     $config = array();
     // Append application database configuration
     $config['host'] = Kohana::config('database.default.connection.host');
     $config['user'] = Kohana::config('database.default.connection.user');
     $config['type'] = Kohana::config('database.default.connection.type');
     $config['database'] = Kohana::config('database.default.connection.database');
     $config['table_prefix'] = Kohana::config('database.default.table_prefix');
     // Save the config in the object
     $this->config = $config;
     // Set the driver class name
     $driver = 'DBManager_' . $config['type'] . '_Driver';
     if (!Kohana::auto_load($driver)) {
         throw new Kohana_Exception('core.driver_not_found', $config['type'], get_class($this));
     }
     // Load the driver
     $driver = new $driver($config);
     if (!$driver instanceof DBManager_Driver) {
         throw new Kohana_Exception('core.driver_implements', $config['type'], get_class($this), 'DBManager_Driver');
     }
     // Load the driver for access
     $this->driver = $driver;
     Kohana::log('debug', 'DBManager Library loaded');
     Event::add('system.display', array($this, 'auto_backup'));
     //Event::add('system.display', array($this, 'auto_optimize'));
 }
示例#5
0
 /**
  * Add a new message to the log.
  *
  * @param   string  type of message
  * @param   string  message text
  * @return  void
  */
 public static function add($type, $message)
 {
     // Make sure the drivers and config are loaded
     if (!is_array(Kohana_Log::$config)) {
         Kohana_Log::$config = Kohana::config('log');
     }
     if (!is_array(Kohana_Log::$drivers)) {
         foreach ((array) Kohana::config('log.drivers') as $driver_name) {
             // Set driver name
             $driver = 'Log_' . ucfirst($driver_name) . '_Driver';
             // Load the driver
             if (!Kohana::auto_load($driver)) {
                 throw new Kohana_Exception('Log Driver Not Found: %driver%', array('%driver%' => $driver));
             }
             // Initialize the driver
             $driver = new $driver(array_merge(Kohana::config('log'), Kohana::config('log_' . $driver_name)));
             // Validate the driver
             if (!$driver instanceof Log_Driver) {
                 throw new Kohana_Exception('%driver% does not implement the Log_Driver interface', array('%driver%' => $driver));
             }
             Kohana_Log::$drivers[] = $driver;
         }
         // Always save logs on shutdown
         Event::add('system.shutdown', array('Kohana_Log', 'save'));
     }
     Kohana_Log::$messages[] = array('date' => time(), 'type' => $type, 'message' => $message);
 }
示例#6
0
文件: Furi.php 项目: nocash/fURI
 public function __construct($config = array())
 {
     // Append default fURI configuration
     $config += Kohana::config('furi');
     // Check for 'auto' driver and adjust configuration
     if (strtolower($config['driver'] == 'auto')) {
         if (function_exists('curl_init')) {
             $config['driver'] = 'cURL';
         } else {
             $config['driver'] = 'Stream';
         }
     }
     // Save the config in the object
     $this->config = $config;
     // Set the driver class name
     $driver = 'Furi_' . $config['driver'] . '_Driver';
     if (!Kohana::auto_load($driver)) {
         throw new Kohana_Exception('core.driver_not_found', $config['driver'], get_class($this));
     }
     // Load the driver
     $driver = new $driver($config);
     if (!$driver instanceof Furi_Driver) {
         throw new Kohana_Exception('core.driver_implements', $config['driver'], get_class($this), 'Furi_Driver');
     }
     // Load the driver for access
     $this->driver = $driver;
     Kohana::log('debug', 'Furi Library loaded');
 }
示例#7
0
    public function __construct($user, $cart)
    {
        $db = new Database();
        $rows = $db->query('
			SELECT d.*, dt.name as discount_name 
			FROM discounts as d 
			LEFT JOIN discounts_types dt ON (d.type_id=dt.id) 
			WHERE (effective_from <= now() OR effective_from="0000:00:00") AND (effective_to >= now() OR effective_to = "0000:00:00")');
        foreach ($rows as $row) {
            $driver = 'Discount_' . $row->discount_name . '_Driver';
            if (!Kohana::auto_load($driver)) {
                throw new Kohana_Exception('core.driver_not_found', $row->discount_name, get_class($this));
            }
            $driver = new $driver($user, $cart);
            $driver->setValues($row);
            if (is_array($amount = $driver->amount())) {
                $this->amount['total'] += $amount['total'];
                if (isset($amount['shippingDiscount'])) {
                    $this->amount['shippingDiscount'] += $amount['shippingDiscount'];
                }
            } else {
                $this->amount['total'] += $amount;
            }
            $this->appliedDiscounts = array_merge($this->appliedDiscounts, $driver->getApplied());
        }
    }
 public static function add($controller_name, $method_name, $parameters = array(), $priority = 5, $application_path = '')
 {
     if ($priority < 1 or $priority > 10) {
         Kohana::log('error', 'The priority of the task was out of range!');
         return FALSE;
     }
     $application_path = empty($application_path) ? APPPATH : $application_path;
     $old_module_list = Kohana::config('core.modules');
     Kohana::config_set('core.modules', array_merge($old_module_list, array($application_path)));
     // Make sure the controller name and method are valid
     if (Kohana::auto_load($controller_name)) {
         // Only add it to the queue if the controller method exists
         if (Kohana::config('queue.validate_methods') and !method_exists($controller_name, $method_name)) {
             Kohana::log('error', 'The method ' . $controller_name . '::' . $method_name . ' does not exist.');
             return FALSE;
         }
         // Add the action to the run queue with the priority
         $task = new Task_Model();
         $task->set_fields(array('application' => $application_path, 'class' => $controller_name, 'method' => $method_name, 'params' => serialize($parameters), 'priority' => $priority));
         $task->save();
         // Restore the module list
         Kohana::config_set('core.modules', $old_module_list);
         return TRUE;
     }
     Kohana::log('error', 'The class ' . $controller_name . ' does not exist.');
     return FALSE;
 }
示例#9
0
 /**
  * Handles methods that do not exist.
  *
  * @param   string  method name
  * @param   array   arguments
  * @return  void
  */
 public function __call($method, $args)
 {
     // get(Db/Mem/Tt/Fs)Instance($routeStamp)
     if (substr($method, 0, 3) == 'get' && substr($method, -8) == 'Instance') {
         $baseDriverKey = substr($method, 3, strlen($method) - 11);
         if ($this->configObject->isExistsDriverKey($baseDriverKey) == FALSE) {
             throw new ServRouteInstanceException('Instance.driver_not_supported:' . $baseDriverKey, 500);
         }
         // 路由驱动
         $routeDriver = 'ServRoute_' . $baseDriverKey . '_Driver';
         // 实例驱动
         $instanceDriver = 'ServInstance_' . $baseDriverKey . '_Driver';
         if (!Kohana::auto_load($routeDriver)) {
             throw new ServRouteInstanceException('Instance.route_driver_not_found:' . $baseDriverKey, 500);
         }
         if (!Kohana::auto_load($instanceDriver)) {
             throw new ServRouteInstanceException('Instance.instance_driver_not_found:' . $baseDriverKey, 500);
         }
         // 实例池
         $driverInstancePoolName = $baseDriverKey;
         if (!array_key_exists($driverInstancePoolName, $this->instancePools)) {
             $this->instancePools[$driverInstancePoolName] = array();
         }
         // fast but unflexible
         $thisRouteClassInstance = new $routeDriver($this->configObject->getDriverSetup($baseDriverKey), $args);
         // slow but flexible
         //$rc = new ReflectionClass($routeDriver);$thisRouteClassInstance = $rc->newInstanceArgs($args);
         if (!$thisRouteClassInstance instanceof ServRoute_Driver || !is_subclass_of($thisRouteClassInstance, 'ServRoute_Driver')) {
             throw new ServRouteInstanceException('Instance.route_driver_implements:' . $driverKey, 500);
         }
         // 路由key
         $routeKey = $thisRouteClassInstance->getRouteKey();
         // 初始化Pool中的routeKey
         !isset($this->instancePools[$driverInstancePoolName][$routeKey]) && ($this->instancePools[$driverInstancePoolName][$routeKey] = false);
         if ($this->instancePools[$driverInstancePoolName][$routeKey] !== FALSE && $this->instancePools[$driverInstancePoolName][$routeKey]->isAvailable() == TRUE) {
             // 池中有对应的实例并且可用
             return $this->instancePools[$driverInstancePoolName][$routeKey];
         }
         // 设定池中的实例
         $thisInstanceClassInstance = new $instanceDriver($thisRouteClassInstance);
         if (!$thisInstanceClassInstance instanceof ServInstance_Driver || !is_subclass_of($thisInstanceClassInstance, 'ServInstance_Driver')) {
             throw new ServRouteInstanceException('Instance.instance_driver_implements:' . $driverKey, 500);
         }
         $this->instancePools[$driverInstancePoolName][$routeKey] = $thisInstanceClassInstance;
         if ($this->instancePools[$driverInstancePoolName][$routeKey] !== FALSE) {
             $this->instancePools[$driverInstancePoolName][$routeKey]->isAvailable() or $this->instancePools[$driverInstancePoolName][$routeKey]->setup();
             if ($this->instancePools[$driverInstancePoolName][$routeKey]->isAvailable() != TRUE) {
                 throw new ServRouteInstanceException('Instance.getInstance Failed,Service Not Available.', 500);
             }
             // 池中有对应的实例并且可用
             return $this->instancePools[$driverInstancePoolName][$routeKey];
         }
         throw new ServRouteInstanceException('Instance.getInstance Failed,critical error', 500);
     } else {
         throw new ServRouteInstanceException('Unknown Method', 500);
     }
 }
示例#10
0
文件: Ip.php 项目: RenzcPHP/3dproduct
 /**
  * Create an instance of Ip.
  *
  * @return  object
  */
 public function __construct()
 {
     $this->config = Kohana::config('ip');
     define('IPDATA_MINI', $this->config['IPDATA_MINI']);
     define('IPDATA_FULL', $this->config['IPDATA_FULL']);
     define('CHARSET', $this->config['CHARSET']);
     $driver = 'Ip_Ip2area_Driver';
     if (!Kohana::auto_load($driver)) {
         throw new Kohana_Exception('core.driver_not_found', $this->config['driver'], get_class($this));
     }
     $this->driver = new $driver();
 }
示例#11
0
文件: codebench.php 项目: laiello/ko3
 public function action_index($class)
 {
     // Convert submitted class name to URI segment
     if (isset($_POST['class'])) {
         $this->request->redirect('codebench/' . trim($_POST['class']));
     }
     // Pass the class name on to the view
     $this->template->class = (string) $class;
     // Try to load the class, then run it
     if (Kohana::auto_load($class) === TRUE) {
         $codebench = new $class();
         $this->template->codebench = $codebench->run();
     }
 }
示例#12
0
 public function __construct($name)
 {
     // Set driver name
     $driver = 'Mymonitor_' . ucfirst($name) . '_Driver';
     // Load the driver
     if (!Kohana::auto_load($driver)) {
         throw new Kohana_Exception($driver . '.driver_not_found', $name, get_class($this));
     }
     // Initialize the driver
     $this->driver = new $driver($name);
     // Validate the driver
     if (!$this->driver instanceof Mymonitor_Driver) {
         throw new Kohana_Exception('core.driver_implements', $name, get_class($this), 'Mymonitor_Driver');
     }
 }
示例#13
0
 public function action_index()
 {
     $class = $this->request->param('class');
     // Convert submitted class name to URI segment
     if (isset($_POST['class'])) {
         throw HTTP_Exception::factory(302)->location('codebench/' . trim($_POST['class']));
     }
     // Pass the class name on to the view
     $this->template->class = (string) $class;
     // Try to load the class, then run it
     if (Kohana::auto_load($class) === TRUE) {
         $codebench = new $class();
         $this->template->codebench = $codebench->run();
     }
 }
示例#14
0
 public function __construct($company, $zip, $country_code, $basket)
 {
     if (empty($company)) {
         throw new Kohana_Exception('core.shipping_company_not_provided', $d, get_class($this));
     }
     $driver = 'Shipping_' . ucfirst($company) . '_Driver';
     if (!Kohana::auto_load($driver)) {
         throw new Kohana_Exception('core.driver_not_found', $company, get_class($this));
     }
     $this->driver = new $driver();
     $this->shipping = $this->get();
     $this->basket = $basket;
     $this->destination->zip = $zip;
     $this->destination->country = $country_code;
 }
示例#15
0
 public function __construct($api)
 {
     //driver启动
     $driver = 'Mydomaininterface_' . ucfirst($api) . '_Driver';
     // Load the driver
     if (!Kohana::auto_load($driver)) {
         throw new Kohana_Exception($driver . '.driver_not_found', $api, get_class($this));
     }
     // Initialize the driver
     $this->driver = new $driver();
     // Validate the driver
     if (!$this->driver instanceof Mydomaininterface_Driver) {
         throw new Kohana_Exception('core.driver_implements', $api, get_class($this), 'Mydomain_interface_Driver');
     }
 }
示例#16
0
文件: Archive.php 项目: Toushi/flow
 /**
  * Loads the archive driver.
  *
  * @throws  Kohana_Exception
  * @param   string   type of archive to create
  * @return  void
  */
 public function __construct($type = NULL)
 {
     $type = empty($type) ? 'zip' : $type;
     // Set driver name
     $driver = 'Archive_' . ucfirst($type) . '_Driver';
     // Load the driver
     if (!Kohana::auto_load($driver)) {
         throw new Kohana_Exception('core.driver_not_found', $type, get_class($this));
     }
     // Initialize the driver
     $this->driver = new $driver();
     // Validate the driver
     if (!$this->driver instanceof Archive_Driver) {
         throw new Kohana_Exception('core.driver_implements', $type, get_class($this), 'Archive_Driver');
     }
     Kohana::log('debug', 'Archive Library initialized');
 }
示例#17
0
 /**
  * Loads the configured driver and validates it.
  *
  * @param   array|string  custom configuration or config group name
  * @return  void
  */
 public function __construct($config = FALSE)
 {
     if (is_string($config)) {
         $name = $config;
         // Test the config group name
         if (($config = Kohana::config('cache.' . $config)) === NULL) {
             throw new Kohana_Exception('cache.undefined_group', $name);
         }
     }
     if (is_array($config)) {
         // Append the default configuration options
         $config += Kohana::config('cache.default');
     } else {
         // Load the default group
         $config = Kohana::config('cache.default');
     }
     // Cache the config in the object
     $this->config = $config;
     if ($this->config['enable'] === false) {
         return false;
     }
     // Set driver name
     $driver = 'Cache_' . ucfirst($this->config['driver']) . '_Driver';
     // Load the driver
     if (!Kohana::auto_load($driver)) {
         throw new Kohana_Exception('core.driver_not_found', $this->config['driver'], get_class($this));
     }
     // Initialize the driver
     $this->driver = new $driver($this->config['params']);
     // Validate the driver
     if (!$this->driver instanceof Cache_Driver) {
         throw new Kohana_Exception('core.driver_implements', $this->config['driver'], get_class($this), 'Cache_Driver');
     }
     Kohana::log('debug', 'Cache Library initialized');
     if (Cache::$loaded !== TRUE) {
         $this->config['requests'] = (int) $this->config['requests'];
         if ($this->config['requests'] > 0 and mt_rand(1, $this->config['requests']) === 1) {
             // Do garbage collection
             $this->driver->delete_expired();
             Kohana::log('debug', 'Cache: Expired caches deleted.');
         }
         // Cache has been loaded once
         Cache::$loaded = TRUE;
     }
 }
示例#18
0
 public static function instance()
 {
     if (!isset(Auth::$instance)) {
         // Load the configuration for this type
         $config = Kohana::config('auth');
         if (!($type = $config->get('driver'))) {
             $type = 'ORM';
         }
         // Set the session class name
         $class = 'Auth_' . ucfirst($type);
         if (!Kohana::auto_load($class)) {
             throw new Kohana_Exception('core.driver_not_found', $config['driver'], get_class($this));
         }
         // Create a new session instance
         Auth::$instance = new $class($config);
     }
     return Auth::$instance;
 }
示例#19
0
 /**
  * get full information for an upload
  *
  * @param string $file 
  * @param array $file_data 
  * @return array
  * @author Andy Bennett
  */
 function get_upload_data($file, $file_data, $save = true)
 {
     $filename = $save ? upload::save($file_data) : $file;
     if (!strlen($filename)) {
         throw new Exception("Empty filename", 1);
     }
     $pp = pathinfo($filename);
     $ext = strtolower($pp['extension']);
     $file_type = uploads::check_filetype($file_data['type'], $filename, $ext);
     $d = Kohana::config('upload.directory');
     $upload_data['file_name'] = $pp['basename'];
     $upload_data['file_type'] = $file_type;
     $upload_data['file_path'] = $d;
     $upload_data['full_path'] = $filename;
     $upload_data['raw_name'] = $pp['filename'];
     $upload_data['orig_name'] = $file_data['name'];
     $upload_data['file_ext'] = '.' . strtolower($ext);
     $upload_data['file_size'] = $file_data['size'];
     $upload_data['is_image'] = file::is_image($file_type);
     $upload_data['is_video'] = 0;
     $upload_data['is_audio'] = 0;
     $upload_data['date_added'] = date('Y-m-d H:i:s');
     $upload_data['preview'] = false;
     $driver = uploads::get_driver($upload_data['is_image'], $file_type, $ext);
     if ($driver !== false) {
         // Load the driver
         if (Kohana::auto_load($driver)) {
             // Initialize the driver
             $upload_driver = new $driver();
             // Validate the driver
             if (!$upload_driver instanceof Uploader_Driver) {
                 throw new Kohana_Exception('core.driver_implements', $driver, 'upload', 'Uploader_Driver');
             }
             $upload_driver->generate_preview($upload_data, $filename, $ext);
         }
     }
     if ($upload_data['is_image']) {
         $properties = file::get_image_properties($filename);
         if (!empty($properties)) {
             $upload_data = array_merge($upload_data, $properties);
         }
     }
     return $upload_data;
 }
示例#20
0
 /**
  * Runs the loaded task
  * 
  */
 public function execute()
 {
     // Load the application
     $old_module_list = Kohana::config('core.modules');
     Kohana::config_set('core.modules', array_merge($old_module_list, array($this->data['application'])));
     if (Kohana::auto_load($this->data['class'])) {
         // Delete it from the queue
         $this->delete();
         $class = new $this->data['class']();
         // Run the task
         call_user_func_array(array($class, $this->data['method']), unserialize($this->data['params']));
         Kohana::log('info', 'Ran ' . $this->data['class'] . '->' . $this->data['method']);
         // Restore the module list
         Kohana::config_set('core.modules', $old_module_list);
         unset($class);
     } else {
         Kohana::log('info', $this->data['class'] . ' not found. Aborting.');
     }
 }
示例#21
0
 /**
  * 获取模块的实例
  * 
  * @param String $dirver_name
  * @return
  */
 public function get_instance($dirver_name = NULL)
 {
     if (!isset(self::$instance[$dirver_name])) {
         //driver启动
         $driver = 'Crond_' . ucfirst($dirver_name) . '_Driver';
         // Load the driver
         if (!Kohana::auto_load($driver)) {
             throw new Kohana_Exception('crond.driver_not_found', $dirver_name, get_class($this));
         }
         // Initialize the driver
         self::$instance[$dirver_name] = new $driver();
         // Validate the driver
         if (!self::$instance[$dirver_name] instanceof Crond_Driver) {
             throw new Kohana_Exception('crond.driver_implements', $dirver_name, get_class($this), 'Crond_Driver');
         }
         Kohana::log('debug', 'Crond Library initialized');
     }
     return self::$instance[$dirver_name];
 }
示例#22
0
 /**
  * Creates a new image editor instance.
  *
  * @throws  Kohana_Exception
  * @param   string   filename of image
  * @param   array    non-default configurations
  * @return  void
  */
 public function __construct($image, $config = NULL)
 {
     static $check;
     // Make the check exactly once
     $check === NULL and $check = function_exists('getimagesize');
     if ($check === FALSE) {
         throw new Kohana_Exception('image.getimagesize_missing');
     }
     // Check to make sure the image exists
     if (!is_file($image)) {
         throw new Kohana_Exception('image.file_not_found', $image);
     }
     // Disable error reporting, to prevent PHP warnings
     $ER = error_reporting(0);
     // Fetch the image size and mime type
     $image_info = getimagesize($image);
     // Turn on error reporting again
     error_reporting($ER);
     // Make sure that the image is readable and valid
     if (!is_array($image_info) or count($image_info) < 3) {
         throw new Kohana_Exception('image.file_unreadable', $image);
     }
     // Check to make sure the image type is allowed
     if (!isset(Image::$allowed_types[$image_info[2]])) {
         throw new Kohana_Exception('image.type_not_allowed', $image);
     }
     // Image has been validated, load it
     $this->image = array('file' => str_replace('\\', '/', realpath($image)), 'width' => $image_info[0], 'height' => $image_info[1], 'type' => $image_info[2], 'ext' => Image::$allowed_types[$image_info[2]], 'mime' => $image_info['mime']);
     // Load configuration
     $this->config = (array) $config + Kohana::config('image');
     // Set driver class name
     $driver = 'Image_' . ucfirst($this->config['driver']) . '_Driver';
     // Load the driver
     if (!Kohana::auto_load($driver)) {
         throw new Kohana_Exception('core.driver_not_found', $this->config['driver'], get_class($this));
     }
     // Initialize the driver
     $this->driver = new $driver($this->config['params']);
     // Validate the driver
     if (!$this->driver instanceof Image_Driver) {
         throw new Kohana_Exception('core.driver_implements', $this->config['driver'], get_class($this), 'Image_Driver');
     }
 }
示例#23
0
 /**
  * Return a static instance of fURI.
  * 
  * @return  object
  */
 public static function instance($config = array())
 {
     $config = Kohana::config('furi');
     // Check for 'auto' driver and adjust configuration
     if (strtolower($config->driver == 'auto')) {
         if (function_exists('curl_init')) {
             $config->driver = 'cURL';
         } else {
             $config->driver = 'Stream';
         }
     }
     $driver = 'Furi_Driver_' . $config->driver;
     if (!is_object(self::$instance)) {
         if (!Kohana::auto_load($driver)) {
             throw new Kohana_Exception('core.driver_not_found', $config['driver'], get_class($this));
         }
         self::$instance = new $driver($config->as_array());
     }
     return self::$instance;
 }
示例#24
0
 /**
  * Loads Session and configuration options.
  *
  * @return  void
  */
 public function __construct($config = array())
 {
     // Append default auth configuration
     $config += Kohana::config('auth');
     // Clean up the salt pattern and split it into an array
     $config['salt_pattern'] = preg_split('/,\\s*/', Kohana::config('auth.salt_pattern'));
     // Save the config in the object
     $this->config = $config;
     // Set the driver class name
     $driver = 'Auth_' . $config['driver'] . '_Driver';
     if (!Kohana::auto_load($driver)) {
         throw new Kohana_Exception('core.driver_not_found', $config['driver'], get_class($this));
     }
     // Load the driver
     $driver = new $driver($config);
     if (!$driver instanceof Auth_Driver) {
         throw new Kohana_Exception('core.driver_implements', $config['driver'], get_class($this), 'Auth_Driver');
     }
     // Load the driver for access
     $this->driver = $driver;
     Kohana::log('debug', 'Auth Library loaded');
 }
示例#25
0
 /**
  * Loads the configured driver and validates it.
  *
  * @return  void
  */
 public function __construct($config = null)
 {
     if (empty($config)) {
         $config = module::get_var("gallery", "identity_provider", "user");
     }
     // Test the config group name
     if (($this->config = Kohana::config("identity." . $config)) === NULL) {
         throw new Exception("@todo NO_USER_LIBRARY_CONFIGURATION_FOR: {$config}");
     }
     // Set driver name
     $driver = "IdentityProvider_" . ucfirst($this->config["driver"]) . "_Driver";
     // Load the driver
     if (!Kohana::auto_load($driver)) {
         throw new Kohana_Exception("core.driver_not_found", $this->config["driver"], get_class($this));
     }
     // Initialize the driver
     $this->driver = new $driver($this->config["params"]);
     // Validate the driver
     if (!$this->driver instanceof IdentityProvider_Driver) {
         throw new Kohana_Exception("core.driver_implements", $this->config["driver"], get_class($this), "IdentityProvider_Driver");
     }
     Kohana_Log::add("debug", "Identity Library initialized");
 }
示例#26
0
 /**
  * Initialize conversion process. Load and find driver, then convert.
  *
  * @param  string  $data
  */
 private function init($data)
 {
     // Set the driver class name
     $driver = 'Convert_' . $this->driver . '_Driver';
     if (!Kohana::auto_load($driver)) {
         throw new Kohana_Exception('convert.driver_not_found', $this->driver, get_class($this));
     }
     // Load the driver
     $driver = new $driver();
     // Pass options to driver
     $driver->options = $this->options;
     // check if driver implements Convert Driver properly
     if (!$driver instanceof Convert_Driver) {
         throw new Kohana_Exception('convert.driver_implements', $this->driver, get_class($this), 'Convert_Driver');
     }
     // check if vendor library exists
     if (!$this->exists($driver->lib())) {
         throw new Kohana_Exception('convert.vendor_not_found', $this->driver);
     }
     // check if passed file extension is allowed to be used for this driver
     $this->check_allowable($driver->allow());
     // render output through driver and pass it to the handler()
     $this->handler($driver->convert($data), $driver->default_ext());
 }
示例#27
0
 /**
  * Kohana_Config constructor to load the supplied driver.
  * Enforces the singleton pattern.
  *
  * @param   string       driver
  * @access  protected
  */
 protected function __construct(array $core_config)
 {
     $drivers = $core_config['config_drivers'];
     //remove array if it's found in config
     if (in_array('array', $drivers)) {
         unset($drivers[array_search('array', $drivers)]);
     }
     //add array at the very end
     $this->drivers = $drivers = array_merge($drivers, array('array'));
     foreach ($this->drivers as &$driver) {
         // Create the driver name
         $driver = 'Config_' . ucfirst($driver) . '_Driver';
         // Ensure the driver loads correctly
         if (!Kohana::auto_load($driver)) {
             throw new Kohana_Exception('The :driver: driver for the :library: library could not be found.', array(':driver:' => $driver, ':library:' => get_class($this)));
         }
         // Load the new driver
         $driver = new $driver($core_config);
         // Ensure the new driver is valid
         if (!$driver instanceof Config_Driver) {
             throw new Kohana_Exception('The :driver: driver for the :library: library must implement the :interface: interface', array(':driver:' => $driver, ':library:' => get_class($this), ':interface:' => 'Config_Driver'));
         }
     }
 }
示例#28
0
 /**
  * Sets up the database configuration, loads the Database_Driver.
  *
  * @throws  Kohana_Database_Exception
  */
 public function __construct($config = array())
 {
     if (empty($config)) {
         // Load the default group
         $config = Kohana::config('database.default');
     } elseif (is_array($config) and count($config) > 0) {
         if (!array_key_exists('connection', $config)) {
             $config = array('connection' => $config);
         }
     } elseif (is_string($config)) {
         // The config is a DSN string
         if (strpos($config, '://') !== FALSE) {
             $config = array('connection' => $config);
         } else {
             $name = $config;
             // Test the config group name
             if (($config = Kohana::config('database.' . $config)) === NULL) {
                 throw new Kohana_Database_Exception('database.undefined_group', $name);
             }
         }
     }
     // Merge the default config with the passed config
     $this->config = array_merge($this->config, $config);
     if (is_string($this->config['connection'])) {
         // Make sure the connection is valid
         if (strpos($this->config['connection'], '://') === FALSE) {
             throw new Kohana_Database_Exception('database.invalid_dsn', $this->config['connection']);
         }
         // Parse the DSN, creating an array to hold the connection parameters
         $db = array('type' => FALSE, 'user' => FALSE, 'pass' => FALSE, 'host' => FALSE, 'port' => FALSE, 'socket' => FALSE, 'database' => FALSE);
         // Get the protocol and arguments
         list($db['type'], $connection) = explode('://', $this->config['connection'], 2);
         if (strpos($connection, '@') !== FALSE) {
             // Get the username and password
             list($db['pass'], $connection) = explode('@', $connection, 2);
             // Check if a password is supplied
             $logindata = explode(':', $db['pass'], 2);
             $db['pass'] = count($logindata) > 1 ? $logindata[1] : '';
             $db['user'] = $logindata[0];
             // Prepare for finding the database
             $connection = explode('/', $connection);
             // Find the database name
             $db['database'] = array_pop($connection);
             // Reset connection string
             $connection = implode('/', $connection);
             // Find the socket
             if (preg_match('/^unix\\([^)]++\\)/', $connection)) {
                 // This one is a little hairy: we explode based on the end of
                 // the socket, removing the 'unix(' from the connection string
                 list($db['socket'], $connection) = explode(')', substr($connection, 5), 2);
             } elseif (strpos($connection, ':') !== FALSE) {
                 // Fetch the host and port name
                 list($db['host'], $db['port']) = explode(':', $connection, 2);
             } else {
                 $db['host'] = $connection;
             }
         } else {
             // File connection
             $connection = explode('/', $connection);
             // Find database file name
             $db['database'] = array_pop($connection);
             // Find database directory name
             $db['socket'] = implode('/', $connection) . '/';
         }
         // Reset the connection array to the database config
         $this->config['connection'] = $db;
     }
     // Set driver name
     $driver = 'Database_' . ucfirst($this->config['connection']['type']) . '_Driver';
     // Load the driver
     if (!Kohana::auto_load($driver)) {
         throw new Kohana_Database_Exception('core.driver_not_found', $this->config['connection']['type'], get_class($this));
     }
     // Initialize the driver
     $this->driver = new $driver($this->config);
     // Validate the driver
     if (!$this->driver instanceof Database_Driver) {
         throw new Kohana_Database_Exception('core.driver_implements', $this->config['connection']['type'], get_class($this), 'Database_Driver');
     }
     Kohana::log('debug', 'Database Library initialized');
 }
示例#29
0
 public function result_array($object = NULL, $type = MYSQL_ASSOC)
 {
     $rows = array();
     if (is_string($object)) {
         $fetch = $object;
     } elseif (is_bool($object)) {
         if ($object === TRUE) {
             $fetch = 'mysql_fetch_object';
             $type = (is_string($type) and Kohana::auto_load($type)) ? $type : 'stdClass';
         } else {
             $fetch = 'mysql_fetch_array';
         }
     } else {
         // Use the default config values
         $fetch = $this->fetch_type;
         if ($fetch == 'mysql_fetch_object') {
             $type = (is_string($this->return_type) and Kohana::auto_load($this->return_type)) ? $this->return_type : 'stdClass';
         }
     }
     if (mysql_num_rows($this->result)) {
         // Reset the pointer location to make sure things work properly
         mysql_data_seek($this->result, 0);
         while ($row = $fetch($this->result, $type)) {
             $rows[] = $row;
         }
     }
     return isset($rows) ? $rows : array();
 }
示例#30
0
 public function result_array($object = NULL, $type = PGSQL_ASSOC)
 {
     $rows = array();
     if (is_string($object)) {
         $fetch = $object;
     } elseif (is_bool($object)) {
         if ($object === TRUE) {
             $fetch = 'pg_fetch_object';
             // NOTE - The class set by $type must be defined before fetching the result,
             // autoloading is disabled to save a lot of stupid overhead.
             $type = (is_string($type) and Kohana::auto_load($type)) ? $type : 'stdClass';
         } else {
             $fetch = 'pg_fetch_array';
         }
     } else {
         // Use the default config values
         $fetch = $this->fetch_type;
         if ($fetch == 'pg_fetch_object') {
             $type = (is_string($type) and Kohana::auto_load($type)) ? $type : 'stdClass';
         }
     }
     if ($this->total_rows) {
         pg_result_seek($this->result, 0);
         while ($row = $fetch($this->result, NULL, $type)) {
             $rows[] = $row;
         }
     }
     return $rows;
 }