* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class RequestParser extends ParserAbstract { protected $baseUrl; public function __construct(Url $baseUrl = null, $mode = self::MODE_STRICT) { parent::__construct($mode); $this->baseUrl = $baseUrl; } /** * Converts an raw http request into an PSX\Http\Request object * * @param string $content * @return \PSX\Http\Request * @throws \PSX\Http\Parser\ParseException */ public function parse($content) { $content = $this->normalize($content); list($method, $path, $scheme) = $this->getStatus($content); // resolve uri path if ($this->baseUrl !== null) { $path = UriResolver::resolve($this->baseUrl, new Uri($path)); } else { $path = new Uri($path); } $request = new Request($path, $method); $request->setProtocolVersion($scheme); list($header, $body) = $this->splitMessage($content); $this->headerToArray($request, $header); $request->setBody(new StringStream($body)); return $request; } /** * @param string $request * @return array * @throws \PSX\Http\Parser\ParseException */ protected function getStatus($request) { $line = $this->getStatusLine($request); if ($line !== false) { $parts = explode(' ', $line, 3); if (isset($parts[0]) && isset($parts[1]) && isset($parts[2])) { $method = $parts[0]; $path = $parts[1]; $scheme = $parts[2]; return array($method, $path, $scheme); } else { throw new ParseException('Invalid status line format'); } } else { throw new ParseException('Couldnt find status line'); } } /** * @param \PSX\Http\RequestInterface $request * @return string */ public static function buildStatusLine(RequestInterface $request) { $method = $request->getMethod(); $target = $request->getRequestTarget(); $protocol = $request->getProtocolVersion(); if (empty($target)) { throw new \RuntimeException('Target not set'); } $method = !empty($method) ? $method : 'GET'; $protocol = !empty($protocol) ? $protocol : 'HTTP/1.1'; return $method . ' ' . $target . ' ' . $protocol; } /** * Parses an raw http request into an PSX\Http\Request object. Throws an * exception if the request has not an valid format * * @param string $content * @param \PSX\Uri\Url $baseUrl * @param integer $mode * @return \PSX\Http\RequestInterface * @throws \PSX\Http\Parser\ParseException */ public static function convert($content, Url $baseUrl = null, $mode = ParserAbstract::MODE_STRICT) { $parser = new self($baseUrl, $mode); return $parser->parse($content); } } __halt_compiler();----SIGNATURE:----CyEfWCnsfoSij3ICS+NVd+x9KPmAifAH4jAx25ZToRyZxiqqbRXdW70PD30UAKvJVVl6lN/wWrJ8u1GoI5JNCcEK9pkbi4KjgwS61wDQvRg1dkKGQd+++1ykPhMUQUNK5HAw+ddWqz8ioARQAHiq5SurwRlYMWEpGHYddWOm6DqUhMxjyDX8HydOdM8gLXXQ/YLp0Nfoz1p8fw9yVb/TNo/0rl3NmAKvXMYmzfT0KVG/GHfvEFdZdqgj1tYKY8Y0zfqTcS4Qhzzpb314bSZfVNq47wfXSluAvTgpxz6z5i7TfLqBRhdOIAbO2cb4fKpCQooutHruBwXWTjP1Uhn+VWZupS4JcEOFqJNN6Xy7MtvFmWe/j+N3Ftcy5mUs7Wq6k1PvBHB30r2zn0GwZCzFq2jPhzfi7V9o6QZMDc4OaYoEkhgZNktKc8MgHTap3iUscsd6hLz6RrZ+4Yb9I9nT0/CumDdOo5vHV4jW0eeYIansFvcDwBztOH3uiuBV5uY5JW627mHmTxbPMWgGCg37K7Z00KOnIMC93f4gXl9S8wMH2e08nA9gVNPrw5IREtRyJWZtIApb8JmgqBXUzb4GdZR2j39AiLKG7MF7KjH0CYnsWTixWHifu1H6+HoUoqfO7p1rIa1gg3hPnViYo32UxL7f8jpZRQ5zIpLpmSpfFnM=----ATTACHMENT:----NDk5MDM0NDE2NTQ1MzQ2OSAxMDMwMTg4NzI1NTI2MjUyIDcwNjg4Mzk2NzU2OTQ0MTQ=