public static function Factory(&$source, $conf_file = NULL, $conf_section = NULL, $strict = TRUE) { if (!is_array($source)) { Inspekt_Error::raiseError('$source ' . $source . ' is not an array', E_USER_NOTICE); } $cage = new Inspekt_Cage_Session(); $cage->_setSource($source); $cage->_parseAndApplyAutoFilters($conf_file); if (ini_get('session.use_cookies') || ini_get('session.use_only_cookies')) { if (isset($_COOKIE) && isset($_COOKIE[session_name()])) { session_id($_COOKIE[session_name()]); } elseif ($cookie = Inspekt::makeSessionCage()) { session_id($cookie->getAlnum(session_name())); } } else { // we're using session ids passed via GET if (isset($_GET) && isset($_GET[session_name()])) { session_id($_GET[session_name()]); } elseif ($cookie = Inspekt::makeSessionCage()) { session_id($cookie->getAlnum(session_name())); } } if ($strict) { $source = NULL; } return $cage; register_shutdown_function(); register_shutdown_function(array($this, '_repopulateSession')); }
/** * If an array is the value of the given key, this method walks the array * recursively, applying $this->inspekt on any non-array values * * @param mixed $input * @param * @author Ed Finkler */ protected function walkArray($input) { if (!isset($classname)) { $classname = __CLASS__; } if (!Inspekt::isArrayOrArrayObject($input)) { Inspekt_Error::raiseError('$input must be an array or ArrayObject', E_USER_ERROR); return FALSE; } foreach ($input as $key => $val) { if (Inspekt::isArrayOrArrayObject($val)) { $input[$key] = $this->walkArray($val); } else { $val = $this->inspekt($val); $input[$key] = $val; } } return $input; }
protected function _setValueRecursive($keys, $val, $data_array, $level = 0) { $thiskey = current($keys); if (is_numeric($thiskey)) { // force numeric strings to be integers $thiskey = (int)$thiskey; } if (array_key_exists($thiskey, $data_array)) { if (sizeof($keys) == 1) { $data_array[$thiskey] = $val; return $data_array[$thiskey]; } elseif ($data_array[$thiskey] instanceof ArrayObject) { if ($level < ISPK_RECURSION_MAX) { unset($keys[key($keys)]); return $this->_setValueRecursive($keys, $val, $data_array[$thiskey], $level + 1); } else { Inspekt_Error::raiseError('Inspekt recursion limit met', E_USER_WARNING); return false; } } } else { // if any key DNE, return false return false; } }
/** * Enter description here... * * @param string $value * @param integer $mode * @return boolean * * @link http://www.ietf.org/rfc/rfc2396.txt * * @tag validator * @static */ function isUri($value, $mode = ISPK_URI_ALLOW_COMMON) { /** * @todo */ $regex = ''; switch ($mode) { // a common absolute URI: ftp, http or https case ISPK_URI_ALLOW_COMMON: $regex .= '&'; $regex .= '^(ftp|http|https):'; // protocol $regex .= '(//)'; // authority-start $regex .= '([-a-z0-9/~;:@=+$,.!*()\']+@)?'; // userinfo $regex .= '('; $regex .= '((?:[^\\W_]((?:[^\\W_]|-){0,61}[^\\W_])?\\.)+[a-zA-Z]{2,6}\\.?)'; // domain name $regex .= '|'; $regex .= '([0-9]{1,3}(\\.[0-9]{1,3})?(\\.[0-9]{1,3})?(\\.[0-9]{1,3})?)'; // OR ipv4 $regex .= ')'; $regex .= '(:([0-9]*))?'; // port $regex .= '(/((%[0-9a-f]{2}|[-a-z0-9/~;:@=+$,.!*()\'\\&]*)*)/?)?'; // path $regex .= '(\\?[^#]*)?'; // query $regex .= '(#([-a-z0-9_]*))?'; // anchor (fragment) $regex .= '$&i'; break; case ISPK_URI_ALLOW_ABSOLUTE: Inspekt_Error::raiseError('isUri() for ISPK_URI_ALLOW_ABSOLUTE has not been implemented.', E_USER_WARNING); return FALSE; // $regex .= '&'; // $regex .= '^(ftp|http|https):'; // protocol // $regex .= '(//)'; // authority-start // $regex .= '([-a-z0-9/~;:@=+$,.!*()\']+@)?'; // userinfo // $regex .= '('; // $regex .= '((?:[^\W_]((?:[^\W_]|-){0,61}[^\W_])?\.)+[a-zA-Z]{2,6}\.?)'; // domain name // $regex .= '|'; // $regex .= '([0-9]{1,3}(\.[0-9]{1,3})?(\.[0-9]{1,3})?(\.[0-9]{1,3})?)'; // OR ipv4 // $regex .= ')'; // $regex .= '(:([0-9]*))?'; // port // $regex .= '(/((%[0-9a-f]{2}|[-a-z0-9/~;:@=+$,.!*()\'\&]*)*)/?)?'; // path // $regex .= '(\?[^#]*)?'; // query // $regex .= '(#([-a-z0-9_]*))?'; // anchor (fragment) // $regex .= '$&i'; break; } $result = preg_match($regex, $value, $subpatterns); return $result; }
/** * {@internal we use this to set the data array in Factory()} * * @see Factory() * @param array $newsource */ function _setSource(&$newsource) { if (!is_array($newsource)) { Inspekt_Error::raiseError('$source is not an array', E_USER_ERROR); } $this->_source = $newsource; }