Skip to content

Commit

Permalink
more CS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
denixport committed Jul 19, 2012
1 parent 062443c commit 9939d59
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 26 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ PLEASE USE AT YOUR OWN RISK.
- Select-style elements now have options populated as value => label
pairs instead of label => value pairs. This is done to ensure that
option values are unique.
- Http
- set/getServer() and set/getEnv() were removed from Http\Request
and now part of Http\PhpEnvironment\Request
- set/getFile() methods in Http\PhpEnvironment\Request
were renamed to set/getFiles(). Also above methods
- When submitted form has file inputs with brackets (name="file[]")
$fileParams parameters in Http\PhpEnvironment\Request will be
re-structured to have the same look as query/post/server/envParams

Over *XXX* pull requests for a variety of features and bugfixes were handled
since beta5!
Expand Down
20 changes: 10 additions & 10 deletions library/Zend/Http/AbstractMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ abstract class AbstractMessage extends Message
/**#@+
* @const string Version constant numbers
*/
const VERSION_11 = '1.1';
const VERSION_10 = '1.0';
const VERSION_11 = '1.1';
/**#@-*/

/**
Expand All @@ -34,20 +34,21 @@ abstract class AbstractMessage extends Message
protected $version = self::VERSION_11;

/**
* @var Headers|string
* @var Headers|null
*/
protected $headers = null;

/**
* Set the HTTP version for this object, one of 1.0 or 1.1 (Request::VERSION_10, Request::VERSION_11)
* Set the HTTP version for this object, one of 1.0 or 1.1
* (AbstractMessage::VERSION_10, AbstractMessage::VERSION_11)
*
* @throws Exception\InvalidArgumentException
* @param string $version (Must be 1.0 or 1.1)
* @return Request
* @return AbstractMessage
* @throws Exception\InvalidArgumentException
*/
public function setVersion($version)
{
if ($version != self::VERSION_11 && $version != self::VERSION_10) {
if ($version != self::VERSION_10 && $version != self::VERSION_11) {
throw new Exception\InvalidArgumentException(
'Not valid or not supported HTTP version: ' . $version
);
Expand All @@ -68,11 +69,11 @@ public function getVersion()

/**
* Provide an alternate Parameter Container implementation for headers in this object,
* (this is NOT the primary API for value setting, for that see headers())
* (this is NOT the primary API for value setting, for that see getHeaders())
*
* @see headers()
* @see getHeaders()
* @param Headers $headers
* @return Request|Response
* @return AbstractMessage
*/
public function setHeaders(Headers $headers)
{
Expand All @@ -95,7 +96,6 @@ public function getHeaders()
return $this->headers;
}


/**
* Allow PHP casting of this object
*
Expand Down
16 changes: 10 additions & 6 deletions library/Zend/Http/PhpEnvironment/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ public function setServer(ParametersInterface $server)

// set HTTP version
if (isset($this->serverParams['SERVER_PROTOCOL'])
&& strpos($this->serverParams['SERVER_PROTOCOL'], '1.0') !== false
&& strpos($this->serverParams['SERVER_PROTOCOL'], self::VERSION_10) !== false
) {
$this->setVersion('1.0');
$this->setVersion(self::VERSION_10);
}

// set URI
Expand All @@ -262,22 +262,26 @@ public function setServer(ParametersInterface $server)
if (isset($this->serverParams['SERVER_NAME'])) {
$host = $this->serverParams['SERVER_NAME'];
if (isset($this->serverParams['SERVER_PORT'])) {
$port = $this->serverParams['SERVER_PORT'];
$port = (int) $this->serverParams['SERVER_PORT'];
}
} elseif ($this->getHeaders()->get('host')) {
$host = $this->getHeaders()->get('host')->getFieldValue();
// works for regname, IPv4 & IPv6
if (preg_match('|\:(\d+)$|', $host, $matches)) {
$port = $matches[1];
$host = substr($host, 0, -1 * (strlen($port) + 1));
$host = substr($host, 0, -1 * (strlen($matches[1]) + 1));
$port = (int) $matches[1];
}
}
$uri->setHost($host);
$uri->setPort($port);

// URI path
$requestUri = $this->getRequestUri();
$uri->setPath(substr($requestUri, 0, strpos($requestUri, '?') ?: strlen($requestUri)));
if (($qpos = strpos($requestUri, '?')) !== false) {
$requestUri = substr($requestUri, 0, $qpos);
}

$uri->setPath($requestUri);

// URI query
if (isset($this->serverParams['QUERY_STRING'])) {
Expand Down
5 changes: 2 additions & 3 deletions library/Zend/Http/PhpEnvironment/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use Zend\Http\Header\MultipleHeaderInterface;
use Zend\Http\Response as HttpResponse;
use Zend\Stdlib\Parameters;

/**
* HTTP Response for current PHP environment
Expand Down Expand Up @@ -62,6 +61,7 @@ public function sendHeaders()
$status = $this->renderStatusLine();
header($status);

/** @var \Zend\Http\Header\HeaderInterface $header */
foreach ($this->getHeaders() as $header) {
if ($header instanceof MultipleHeaderInterface) {
header($header->toString(), false);
Expand Down Expand Up @@ -101,5 +101,4 @@ public function send()
->sendContent();
return $this;
}
}

}
18 changes: 11 additions & 7 deletions library/Zend/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ public static function fromString($string)
self::METHOD_PUT, self::METHOD_DELETE, self::METHOD_TRACE, self::METHOD_CONNECT,
self::METHOD_PATCH
));
$regex = '^(?P<method>' . $methods . ')\s(?P<uri>[^ ]*)(?:\sHTTP\/(?P<version>\d+\.\d+)){0,1}';
$regex = '#^(?P<method>' . $methods . ')\s(?P<uri>[^ ]*)(?:\sHTTP\/(?P<version>\d+\.\d+)){0,1}#';
$firstLine = array_shift($lines);
if (!preg_match('#' . $regex . '#', $firstLine, $matches)) {
throw new Exception\InvalidArgumentException('A valid request line was not found in the provided string');
if (!preg_match($regex, $firstLine, $matches)) {
throw new Exception\InvalidArgumentException(
'A valid request line was not found in the provided string'
);
}

$request->setMethod($matches['method']);
Expand Down Expand Up @@ -168,13 +170,15 @@ public function setUri($uri)
$uri = new HttpUri($uri);
} catch (UriException\InvalidUriPartException $e) {
throw new Exception\InvalidArgumentException(
sprintf('Invalid URI passed as string (%s)', (string) $uri),
$e->getCode(),
$e
sprintf('Invalid URI passed as string (%s)', (string) $uri),
$e->getCode(),
$e
);
}
} elseif (!($uri instanceof HttpUri)) {
throw new Exception\InvalidArgumentException('URI must be an instance of Zend\Uri\Http or a string');
throw new Exception\InvalidArgumentException(
'URI must be an instance of Zend\Uri\Http or a string'
);
}
$this->uri = $uri;

Expand Down

0 comments on commit 9939d59

Please sign in to comment.