示例#1
0
文件: Auth.php 项目: jthurteau/saf
 public static function init($config = array())
 {
     if (self::$_initialized) {
         return;
     }
     self::$_loadedConfig = $config;
     if (array_key_exists('supportsInternal', $config) && Saf_Filter_Truthy::filter($config['supportsInternal'])) {
         self::$_activePlugin = new Saf_Auth_Plugin_Local();
         self::$_supportsInternal = TRUE;
     }
     $plugins = array_key_exists('plugin', $config) ? Saf_Array::isNumericArray($config['plugin']) ? $config['plugin'] : array($config['plugin']) : array();
     self::$_autocreate = array_key_exists('autocreateUsers', $config) ? $config['autocreateUsers'] : FALSE;
     $firstPass = TRUE;
     foreach ($plugins as $pluginConfig) {
         if (is_array($pluginConfig) && array_key_exists('name', $pluginConfig)) {
             $pluginName = $pluginConfig['name'];
             $pluginConfig = $pluginConfig;
         } else {
             $pluginName = trim($pluginConfig);
             $pluginConfig = array();
         }
         if ($firstPass) {
             self::$_defaultPlugins[] = $pluginName;
             self::$_defaultPluginName = $pluginName;
         } else {
             if (array_key_exists('default', $pluginConfig) && $pluginConfig['default']) {
                 self::$_defaultPlugins[] = $pluginName;
             }
         }
         if (!in_array($pluginName, self::$_loadedPlugins)) {
             self::$_loadedPlugins[] = $pluginName;
             $className = 'Saf_Auth_Plugin_' . $pluginName;
             $classPath = LIBRARY_PATH . '/' . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
             if (!file_exists($classPath)) {
                 $className = $pluginName;
                 Saf_Kickstart::autoload($className);
             } else {
                 Saf_Kickstart::autoload($className);
             }
             if ($pluginConfig) {
                 self::$_classMap[$pluginName] = array($className => $pluginConfig);
             } else {
                 self::$_classMap[$pluginName] = $className;
             }
         }
         $firstPass = FALSE;
     }
     self::$_initialized = TRUE;
 }
示例#2
0
 public function bootstrap($type = NULL)
 {
     if ($type === TRUE || $type === FALSE) {
         $type = NULL;
         //#TODO #2.0.0 allow valid class names and bootstrapObjects
     }
     if (is_null($type) && !is_null($this->_bootstrap)) {
         return $this->_bootstrap;
     } else {
         if (!is_null($this->_bootstrap)) {
             $bootstrapClass = get_class($this->_bootstrap);
             if ("Saf_Bootstrap_{$type}" == $bootstrapClass) {
                 return $this->_bootstrap;
             }
         }
     }
     if (is_null($type)) {
         $type = defined('APPLICATION_PROTOCOL') ? APPLICATION_PROTOCOL != 'commandline' ? 'Http' : 'Commandline' : 'Http';
     }
     try {
         $bootstrapClass = "Saf_Bootstrap_{$type}";
         if (!$this->_autoLoad && !class_exists($bootstrapClass)) {
             Saf_Kickstart::autoload($bootstrapClass);
         }
         $this->_bootstrap = new $bootstrapClass($this, $this->_bootstrapConfig);
     } catch (Exception $e) {
         if (!class_exists($bootstrapClass, FALSE)) {
             //!in_array($bootstrapClass, get_declared_classes())) { //also seems to fail
             //#TODO #RAINYDAY for some reason if spl_autoload throws an exception for a class,
             //PHPseems to refuse try again, or even load the class manually...
             if ($this->_autoLoad) {
                 throw new Exception('Unable to load the requested Bootstrap' . (Saf_Debug::isEnabled() ? " ({$bootstrapClass}) " : '') . '. Autoloading is enabled, but unable to find the bootstrap.', 0, $e);
             } else {
                 throw new Exception('Unable to load the requested Bootstrap' . (Saf_Debug::isEnabled() ? " ({$bootstrapClass}) " : '') . '. Manually require this class, or enable autoloading.', 0, $e);
             }
         } else {
             throw $e;
         }
     }
     return $this->_bootstrap;
 }