示例#1
0
 /**
  * Recursively builds the map of UploadedFile instances.
  *
  * @param array $files
  * @param array $destination
  *
  * @return void
  */
 private static function buildMap(array $files, array &$destination)
 {
     foreach ($files as $structure) {
         foreach ($structure as $key => $value) {
             $subFiles = [];
             foreach ($files as $uploadKey => $data) {
                 $subFiles[$uploadKey] = $data[$key];
             }
             if (is_array($value)) {
                 $destination[$key] = [];
                 self::buildMap($subFiles, $destination[$key]);
             } else {
                 $destination[$key] = UploadedFile::create($subFiles);
             }
         }
         // Only one of the entries was needed to get the structure.
         break;
     }
 }
示例#2
0
 protected function process_request_vars($params)
 {
     # throw an exception if the max post size is reached
     if (array_key_exists('CONTENT_LENGTH', $_SERVER) && !empty($_POST)) {
         $pms = ini_get('post_max_size');
         $mul = substr($pms, -1);
         $mul = $mul == 'M' ? 1048576 : ($mul == 'K' ? 1024 : ($mul == 'G' ? 1073741824 : 1));
         if ($_SERVER['CONTENT_LENGTH'] > $mul * (int) $pms && $pms) {
             throw new MaxPostSizeExceeded("The posted data was too large. The maximum post size is: {$pms}.");
         }
     }
     # add request to params and make sure magic quotes are dealt with
     unset($_POST['MAX_FILE_SIZE']);
     unset($_GET['MAX_FILE_SIZE']);
     $gpc = get_magic_quotes_gpc() == 1;
     foreach (array($_GET, $_POST) as $R) {
         foreach ($R as $k => $v) {
             if (!isset($params[$k])) {
                 if (is_array($v)) {
                     $params[$k] = array();
                     foreach ($v as $k2 => $v2) {
                         $params[$k][$k2] = $gpc && !is_array($v2) ? stripslashes($v2) : $v2;
                     }
                 } else {
                     $params[$k] = $gpc ? stripslashes($v) : $v;
                 }
             }
         }
     }
     # add files to params
     foreach ($_FILES as $k => $v) {
         if (!isset($params[$k])) {
             try {
                 $uploaded_file = UploadedFile::create($v);
             } catch (UpoadedFileException $e) {
                 $uploaded_file = false;
             }
             $params[$k] = $uploaded_file;
         }
     }
     return $params;
 }
示例#3
0
文件: Usher.php 项目: brysonian/Saint
 /**
  * find the best map include the right classes and
  * start hand off to the controller
  */
 static function handle_url($url)
 {
     if (defined('DEBUG') && DEBUG) {
         error_log("Begin processing: {$url}");
         $start = microtime(true);
     }
     $u = Usher::get_instance();
     # routing is here
     $params = $u->match_url($url);
     # if no match was found, show the error
     if (!$params) {
         throw new NoValidMapping("No mapping was found for "{$url}".");
     }
     # add request to params and make sure magic quotes are dealt with
     unset($_POST['MAX_FILE_SIZE']);
     unset($_GET['MAX_FILE_SIZE']);
     foreach ($_POST as $k => $v) {
         if (!array_key_exists($k, $params)) {
             $gpc = get_magic_quotes_gpc() == 1;
             if (is_array($v)) {
                 $params[$k] = array();
                 foreach ($v as $k2 => $v2) {
                     $params[$k][$k2] = $gpc && !is_array($v2) ? stripslashes($v2) : $v2;
                 }
             } else {
                 $params[$k] = $gpc ? stripslashes($v) : $v;
             }
         }
     }
     foreach ($_GET as $k => $v) {
         if (!array_key_exists($k, $params)) {
             $gpc = get_magic_quotes_gpc() == 1;
             if (is_array($v)) {
                 $params[$k] = array();
                 foreach ($v as $k2 => $v2) {
                     $params[$k][$k2] = $gpc && !is_array($v2) ? stripslashes($v2) : $v2;
                 }
             } else {
                 $params[$k] = $gpc ? stripslashes($v) : $v;
             }
         }
     }
     # add files to params and make sure magic quotes are dealt with
     foreach ($_FILES as $k => $v) {
         if (!array_key_exists($k, $params)) {
             $params[$k] = array();
         }
         $params[$k] = array_merge($params[$k], UploadedFile::create($v));
     }
     # save the params
     self::$params = $params;
     # get the controller name
     #$cname = preg_replace('/(?:^|_)([a-zA-Z])/e', "strtoupper('\\1')", $params['controller']);
     $cname = class_name($params['controller']);
     $cname = ucfirst($cname . 'Controller');
     # make sure the name is a valid class name
     if (preg_match('|[^a-zA-Z_]|', $cname) > 0 || preg_match('|^[^a-zA-Z_]|', $cname) > 0) {
         throw new UnknownController("{$cname} is not a valid controller.");
     }
     if (defined('DEBUG') && DEBUG) {
         error_log("Controller found in " . (microtime(true) - $start) . " seconds.");
     }
     # make an instance of the controller class
     self::$controller = new $cname();
     # set the method name
     $action = $params['action'];
     # tell the controller to execute the action
     self::$controller->execute($action);
     # log exec time
     if (defined('DEBUG') && DEBUG) {
         $end = microtime(true);
         error_log("Executed in " . ($end - $start) . " seconds.");
     }
 }