/** * Loads Session and configuration options. * * @return void */ public function __construct($config = array()) { // Load Session $this->session = Session::instance(); // Append default auth configuration $config += Eight::config('auth'); // Save the config in the object $this->config = $config; // Init Bcrypt if we're using it if ($this->config['hash_method'] == 'bcrypt') { $this->bcrypt = new Bcrypt(12); } // Set the driver class name $driver = 'Auth_Driver_' . $config['driver']; if (!Eight::auto_load($driver)) { throw new Eight_Exception('core.driver_not_found', $config['driver'], get_class($this)); } // Load the driver $driver = new $driver($config); if (!$driver instanceof Auth_Driver) { throw new Eight_Exception('core.driver_implements', $config['driver'], get_class($this), 'Auth_Driver'); } // Load the driver for access $this->driver = $driver; Eight::log('debug', 'Auth Library loaded'); }
/** * Loads the configured driver and validates it. * * @param array|string custom configuration or config group name * @return void */ public function __construct($config = NO) { if (is_string($config)) { $name = $config; // Test the config group name if (($config = Eight::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 += Eight::config('cache.default'); } else { // Load the default group $config = Eight::config('cache.default'); } // Cache the config in the object $this->config = $config; // Set driver name $driver = 'Cache_Driver_' . ucfirst($this->config['driver']); // Load the driver if (!Eight::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')); } Eight::log('debug', 'Cache Library initialized'); }
public function __construct($config = array()) { // Set the config $this->config = $config; // Set a filename, if we don't have one if (str::e($this->config['filename'])) { $this->config['filename'] = date("Y-m-d_g-ia"); } // Build driver class $driver = "Export_Driver_" . trim(strtoupper($config['driver'])); // Load the driver if (!Eight::auto_load($driver)) { throw new Export_Exception('export.driver_not_supported', $config['driver']); } // Initialize the driver $this->driver = new $driver($this->config); // Validate the driver if (!$this->driver instanceof Export_Driver) { throw new Export_Exception('export.driver_not_supported', 'Export drivers must use the Export_Driver interface.'); } // Set the columns if (!arr::e($this->config['columns'])) { $this->driver->set_columns($this->config['columns']); } }
/** * 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 = Eight::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_Driver_' . ucfirst($this->config['driver']); // Load the driver if (!Eight::auto_load($driver)) { throw new Eight_Exception('core.driver_not_found', $this->config['driver'], get_class($this)); } // Get the driver specific settings $this->config = array_merge($this->config, Eight::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 Eight_Exception('core.driver_implements', $this->config['driver'], get_class($this), 'Payment_Driver'); } }
/** * Loads the archive driver. * * @throws Eight_Exception * @param string type of archive to create * @return void */ public function __construct($type = nil) { $type = empty($type) ? 'zip' : $type; // Set driver name $driver = 'Archive_Driver_' . ucfirst($type); // Load the driver if (!Eight::auto_load($driver)) { throw new Eight_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 Eight_Exception('core.driver_implements', $type, get_class($this), 'Archive_Driver'); } Eight::log('debug', 'Archive Library initialized'); }
/** * Creates a new image editor instance. * * @throws Eight_Exception * @param string filename of image * @param array non-default configurations * @return void */ public function __construct($image, $config = nil) { static $check; // Make the check exactly once $check === nil and $check = function_exists('getimagesize'); if ($check === NO) { throw new Eight_Exception('image.getimagesize_missing'); } // Check to make sure the image exists if (!is_file($image)) { throw new Eight_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 Eight_Exception('image.file_unreadable', $image); } // Check to make sure the image type is allowed if (!isset(Image::$allowed_types[$image_info[2]])) { throw new Eight_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 + Eight::config('image'); // Set driver class name $driver = 'Image_Driver_' . ucfirst($this->config['driver']); // Load the driver if (!Eight::auto_load($driver)) { throw new Eight_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 Eight_Exception('core.driver_implements', $this->config['driver'], get_class($this), 'Image_Driver'); } }
/** * Constructor: __construct * On first session instance creation, sets up the driver and creates session. */ public function __construct() { $this->input = new Input(); // This part only needs to be run once if (self::$instance === NULL) { // Load config self::$config = Eight::config('session'); // Makes a mirrored array, eg: foo=foo self::$protect = array_combine(self::$protect, self::$protect); if (self::$config['driver'] != 'native') { // Set driver name $driver = 'Session_Driver_' . ucfirst(self::$config['driver']); // Load the driver if (!Eight::auto_load($driver)) { throw new Eight_Exception('session.driver_not_supported', self::$config['driver']); } // Initialize the driver self::$driver = new $driver(); // Validate the driver if (!self::$driver instanceof Session_Driver) { throw new Eight_Exception('session.driver_must_implement_interface'); } } // Create a new session $this->create(); // Regenerate session id if (self::$config['regenerate'] > 0 and $_SESSION['total_hits'] % self::$config['regenerate'] === 0) { $this->regenerate(); } // Close the session just before sending the headers, so that // the session cookie can be written Event::add('system.post_controller', 'session_write_close'); // Singleton instance self::$instance = $this; } Eight::log('debug', 'Session Library initialized'); }
/** * Loads Session and configuration options. * * @return void */ public function __construct($config = array()) { // Load Session $this->session = Session::instance(); // Append default auth configuration $config += Eight::config('auth'); // Clean up the salt pattern and split it into an array $config['salt_pattern'] = preg_split('/,\\s*/', Eight::config('auth.salt_pattern')); // Save the config in the object $this->config = $config; // Set the driver class name $driver = 'Auth_Driver_' . $config['driver']; if (!Eight::auto_load($driver)) { throw new Eight_Exception('core.driver_not_found', $config['driver'], get_class($this)); } // Load the driver $driver = new $driver($config); if (!$driver instanceof Auth_Driver) { throw new Eight_Exception('core.driver_implements', $config['driver'], get_class($this), 'Auth_Driver'); } // Load the driver for access $this->driver = $driver; Eight::log('debug', 'Auth Library loaded'); }
/** * Sets up the database configuration, loads the <Database_Driver>. * * @param array|string Config array or DSN String * * @throws <Database_Exception> if there is no database group, an invalid DSN is supplied, or the requested driver doesn't exist. */ public function __construct($config = array()) { if (empty($config)) { // Load the default group $config = Eight::config('database.default'); } 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 = Eight::config('database.' . $config)) === NULL) { throw new Database_Exception('database.undefined_group', $name); } $this->connection_group = $name; } } // Merge the default config with the passed config $this->config = array_merge($this->config, $config); // Make sure the connection is valid if (strpos($this->config['connection'], '://') === FALSE) { throw new 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); // Set driver name $driver = 'Database_Driver_' . ucfirst($db['type']); // Load the driver if (!Eight::auto_load($driver)) { throw new Database_Exception('database.driver_not_supported', $this->config['connection']['type']); } // Reset the connection array to the database config $this->config['connection'] = call_user_func(array($driver, 'parse_connection'), $db['type'], $connection); $this->name = $this->config['connection']['database']; // Check to see if we use a separate database for updates if (!str::e($this->config['connection_master'])) { // Get the protocol and arguments list($db['type'], $connection) = explode('://', $this->config['connection_master'], 2); // Reset the connection array to the database config $this->config['connection_master'] = call_user_func(array($driver, 'parse_connection'), $db['type'], $connection); } // Initialize the driver $this->type = $db['type']; $this->driver = new $driver($this->config); // Validate the driver if (!$this->driver instanceof Database_Driver) { throw new Database_Exception('database.driver_not_supported', 'Database drivers must use the Database_Driver interface.'); } Eight::log('debug', 'Database Library initialized'); }
/** * Constructs a new Captcha object. * * @throws Eight_Exception * @param string config group name * @return void */ public function __construct($group = nil) { // Create a singleton instance once empty(self::$instances[$group]) and self::$instances[$group] = $this; // No config group name given if (!is_string($group)) { $group = 'default'; } // Load and validate config group if (!is_array($config = Eight::config('captcha.' . $group))) { throw new Eight_Exception('captcha.undefined_group', $group); } // All captcha config groups inherit default config group if ($group !== 'default') { // Load and validate default config group if (!is_array($default = Eight::config('captcha.default'))) { throw new Eight_Exception('captcha.undefined_group', 'default'); } // Merge config group with default config group $config += $default; } // Assign config values to the object foreach ($config as $key => $value) { if (array_key_exists($key, self::$config)) { self::$config[$key] = $value; } } // Store the config group name as well, so the drivers can access it self::$config['group'] = $group; // If using a background image, check if it exists if (!empty($config['background'])) { self::$config['background'] = str_replace('\\', '/', realpath($config['background'])); if (!is_file(self::$config['background'])) { throw new Eight_Exception('captcha.file_not_found', self::$config['background']); } } // If using any fonts, check if they exist if (!empty($config['fonts'])) { self::$config['fontpath'] = str_replace('\\', '/', realpath($config['fontpath'])) . '/'; foreach ($config['fonts'] as $font) { if (!is_file(self::$config['fontpath'] . $font)) { throw new Eight_Exception('captcha.file_not_found', self::$config['fontpath'] . $font); } } } // Set driver name $driver = 'Captcha_Driver_' . ucfirst($config['style']); // Load the driver if (!Eight::auto_load($driver)) { throw new Eight_Exception('core.driver_not_found', $config['style'], get_class($this)); } // Initialize the driver $this->driver = new $driver(); // Validate the driver if (!$this->driver instanceof Captcha_Driver) { throw new Eight_Exception('core.driver_implements', $config['style'], get_class($this), 'Captcha_Driver'); } Eight::log('debug', 'Captcha Library initialized'); }