protected function _preApplicationRun(&$request = NULL, &$response = NULL) { //#TODO #2.0.0 testing isolation and profiling (e.g. time isolation) if (!isset($_SESSION)) { if (array_key_exists('autoSession', $this->_config)) { $this->_autoSession = Saf_Filter_Truthy::filter($this->_config['autoSession']); } if ($this->_autoSession) { $this->_preSessionStart()->_sessionStart()->_postSessionStart(); } } return $this; }
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; }
/** * Create a new Ldap connection adapter. Accepts a config array, or a connection * address string and context with optional login Id and password. */ public function __construct($addressOrConfig, $context = '', $login = '', $password = '') { Saf_Debug::outData(array($addressOrConfig, $context, $login, $password)); if (is_array($addressOrConfig)) { $this->_setupConnection($addressOrConfig['params']['host'], $addressOrConfig['params']['bind'], $addressOrConfig['params']['login'], $addressOrConfig['params']['pass']); $this->_search = array_key_exists('search', $addressOrConfig['params']) ? $addressOrConfig['params']['search'] : ''; if (array_key_exists('secure', $addressOrConfig['params']) && Saf_Filter_Truthy::filter($addressOrConfig['params']['secure'])) { $this->secureConnection(); } else { $this->allowInsecureAuth(); $this->unsecureConnection(); } $this->_attributes = array_values($addressOrConfig['map']); } else { $this->_setupConnection($addressOrConfig, $context, $login, $password); $this->unsecureConnection(); //#TODO #2.0.0 should detect this from the address... $this->_setupConnection(); } }
public static function valueMap($data, $cast = 'auto') { switch ($cast) { case 'boolean': case 'bool': return (bool) $data; break; case 'truthy': return Saf_Filter_Truthy::filter($data); case 'string': return (string) $data; case 'int': case 'integer': return (int) $data; case 'float': case 'double': case 'real': return (double) $data; default: return is_array($data) || is_object($data) ? self::arrayMap($data) : $data; } }
/** * casts a value into a different type * @param mixed $value * @param int $cast matching one of the CAST_ class constants * @return mixed */ public static function cast($value, $cast) { switch ($cast) { case self::CAST_BOOL: return Saf_Filter_Truthy::filter($value); default: //#TODO #2.0.0 support the other cast features return $value; } }
protected function _applyConfig() { //#TODO #2.0.0 loop through the tags instead $autoLoad = $this->_config->getOptional('autoLoad', FALSE); $debugMode = $this->_config->getOptional('debug:mode', Saf_Debug::DEBUG_MODE_OFF); $errorMode = $this->_config->getOptional('error:mode', Saf_Debug::ERROR_MODE_DEFAULT); Saf_Debug::init($debugMode, $errorMode, FALSE); if ($autoLoad) { $autoLoadTakeover = array_key_exists('takeover', $autoLoad) && Saf_Filter_Truthy::filter($autoLoad['takeover']); Saf_Kickstart::initializeAutoloader($autoLoad); if (array_key_exists('loader', $autoLoad)) { $loaders = Saf_Config::autoGroup($autoLoad['loader']); foreach ($loaders as $loader) { $loaderParts = explode(':', Saf_Filter_ConfigString($loader), 2); !array_key_exists(1, $loaderParts) ? Saf_Kickstart::addAutoloader($loaderParts[0]) : Saf_Kickstart::addAutoloader($loaderParts[0], $loaderParts[1]); } } if (array_key_exists('library', $autoLoad)) { $libraries = Saf_Config::autoGroup($autoLoad['library']); foreach ($libraries as $library) { $libParts = explode(':', Saf_Filter_ConfigString($library), 2); !array_key_exists(1, $libParts) ? Saf_Kickstart::addLibrary($libParts[0]) : Saf_Kickstart::addLibrary(array($libParts[0], $libParts[1])); } } if (array_key_exists('special', $autoLoad)) { $specialLoaders = Saf_Config::autoGroup($autoLoad['special']); foreach ($specialLoaders as $special) { $specialParts = explode(':', Saf_Filter_ConfigString($special), 2); !array_key_exists(1, $specialParts) ? Saf_Kickstart::addLibrary(array($specialParts[0])) : Saf_Kickstart::addLibrary(array($specialParts[0], $specialParts[1])); } } } $this->_bootstrapConfig = $this->_config->getOptional('bootstrap', NULL); if ($this->_config->has('resources')) { $resources = Saf_Array::coerce($this->_config->get('resources:+'), Saf_Array::MODE_TRUNCATE); foreach ($resources as $pluginName => $pluginConfig) { $this->provision($pluginName, $pluginConfig); } } }