示例#1
0
 /**
  * Load a login driver to the array of loaded drivers
  *
  * @param   Array  settings for the new driver
  * @throws  AuthException  on driver load failure
  */
 public static function forge($custom = array())
 {
     // Driver is given as array key or just string in custom
     $custom = !is_array($custom) ? array('driver' => $custom) : $custom;
     $config = \Config::get('auth.' . $custom['driver'] . '_config', array());
     $config = array_merge($config, $custom);
     // Driver must be set
     if (empty($config['driver']) || !is_string($config['driver'])) {
         throw new \AuthException('No auth driver given.');
     }
     // determine the driver to load
     $driver = \Auth_Login_Driver::forge($config);
     // get the driver's cookie name
     $id = $driver->get_id();
     // do we already have a driver instance for this cookie?
     if (isset(static::$_instances[$id])) {
         // if so, they must be using the same driver class!
         $class = get_class($driver);
         if (!static::$_instances[$id] instanceof $class) {
             throw new \AuthException('You can not instantiate two different login drivers using the same id "' . $id . '"');
         }
     } else {
         // store this instance
         static::$_instances[$id] = $driver;
     }
     return static::$_instances[$id];
 }