Esempio n. 1
0
 /**
  * Request object provided to the Photon views.
  *
  * @param &$mess Mongrel2 request message object.
  */
 function __construct(&$mess)
 {
     $this->mess = $mess;
     $this->path = $this->mess->path;
     $this->method = $this->mess->headers->METHOD;
     $this->sender = $this->mess->sender;
     $this->client = $this->mess->conn_id;
     $this->headers = $this->mess->headers;
     if (isset($this->mess->headers->QUERY)) {
         \mb_parse_str($this->mess->headers->QUERY, $this->GET);
         $this->query = $this->mess->headers->QUERY;
     }
     if ('POST' === $this->mess->headers->METHOD || 'PUT' === $this->mess->headers->METHOD) {
         if (isset($this->mess->headers->{'content-type'}) === false) {
             $this->BODY =& $mess->body;
         } else {
             if (0 === strpos($this->mess->headers->{'content-type'}, 'multipart/form-data; boundary=')) {
                 $parser = new \photon\http\multipartparser\MultiPartParser($mess->headers, $mess->body);
                 foreach ($parser->parse() as $part) {
                     if ('FIELD' === $part['of_type']) {
                         add_to_post($this->POST, $part['name'], $part['data']);
                     } else {
                         add_file_to_post($this->FILES, $part['name'], $part);
                     }
                 }
             } else {
                 if (false !== mb_strstr($this->mess->headers->{'content-type'}, 'application/x-www-form-urlencoded')) {
                     $this->POST = parse_str(substr(stream_get_contents($mess->body), 0, -1));
                 } else {
                     $this->BODY =& $mess->body;
                 }
             }
         }
     } else {
         if ('JSON' === $this->mess->headers->METHOD) {
             $this->BODY = $this->mess->body;
         }
     }
     $this->COOKIE = CookieHandler::parse($this->mess->headers, Conf::f('secret_key', ''));
 }
Esempio n. 2
0
 public function testReadSmallDataFields()
 {
     $datafile = fopen(__DIR__ . '/../data/small.upload', 'rb');
     $headers = (object) array('content-type' => 'multipart/form-data; boundary=---------------------------10102754414578508781458777923');
     $parser = new \photon\http\multipartparser\MultiPartParser($headers, $datafile);
     $fields = $parser->parse();
     $this->assertEquals(1, count($fields));
     $this->assertEquals(19, strlen($fields[0]['data']));
     fclose($datafile);
 }