This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Added missing constructor parameter #3287
Merged
weierophinney
merged 3 commits into
zendframework:develop
from
iwalz:fix/zend-http-cookies
Jan 3, 2013
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,8 @@ | |
namespace Zend\Http\Client; | ||
|
||
use ArrayIterator; | ||
use Zend\Http\Header\Cookie; | ||
use Zend\Http\Header\SetCookie; | ||
use Zend\Stdlib\ArrayUtils; | ||
use Zend\Http\Response; | ||
use Zend\Uri; | ||
|
||
|
@@ -93,7 +94,7 @@ public function __construct() | |
* Add a cookie to the class. Cookie should be passed either as a Zend\Http\Header\Cookie object | ||
* or as a string - in which case an object is created from the string. | ||
* | ||
* @param Cookie|string $cookie | ||
* @param SetCookie|string $cookie | ||
* @param Uri\Uri|string $ref_uri Optional reference URI (for domain, path, secure) | ||
* @throws Exception\InvalidArgumentException if invalid $cookie value | ||
*/ | ||
|
@@ -103,7 +104,7 @@ public function addCookie($cookie, $ref_uri = null) | |
$cookie = Cookie::fromString($cookie, $ref_uri); | ||
} | ||
|
||
if ($cookie instanceof Cookie) { | ||
if ($cookie instanceof SetCookie) { | ||
$domain = $cookie->getDomain(); | ||
$path = $cookie->getPath(); | ||
if (!isset($this->cookies[$domain])) { | ||
|
@@ -128,6 +129,9 @@ public function addCookie($cookie, $ref_uri = null) | |
public function addCookiesFromResponse(Response $response, $ref_uri) | ||
{ | ||
$cookie_hdrs = $response->getHeaders()->get('Set-Cookie'); | ||
if ($cookie_hdrs instanceof \ArrayIterator) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
$cookie_hdrs = ArrayUtils::iteratorToArray($cookie_hdrs); | ||
} | ||
|
||
if (is_array($cookie_hdrs)) { | ||
foreach ($cookie_hdrs as $cookie) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,10 +92,8 @@ public static function fromString($string) | |
); | ||
} | ||
|
||
public function __construct(Headers $headers) | ||
{ | ||
$this->headers = $headers; | ||
} | ||
public function __construct() | ||
{ } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the constructor won't be doing anything, remove it. |
||
|
||
/** | ||
* Add a cookie to the class. Cookie should be passed either as a Zend\Http\Header\Cookie object | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Http | ||
*/ | ||
|
||
namespace ZendTest\Http; | ||
|
||
use Zend\Http\Header\SetCookie; | ||
use Zend\Http\Response; | ||
use \Zend\Http\Headers; | ||
|
||
|
||
class CookiesTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testFromResponseInSetCookie() | ||
{ | ||
$response = new Response(); | ||
$headers = new Headers(); | ||
$header = new \Zend\Http\Header\SetCookie("foo", "bar"); | ||
$header->setDomain("www.zend.com"); | ||
$header->setPath("/"); | ||
$headers->addHeader($header); | ||
$response->setHeaders($headers); | ||
|
||
$response = \Zend\Http\Cookies::fromResponse($response, "http://www.zend.com"); | ||
$this->assertSame($header, $response->getCookie('http://www.zend.com', 'foo')); | ||
} | ||
|
||
public function testFromResponseInCookie() | ||
{ | ||
$response = new Response(); | ||
$headers = new Headers(); | ||
$header = new \Zend\Http\Header\SetCookie("foo", "bar"); | ||
$header->setDomain("www.zend.com"); | ||
$header->setPath("/"); | ||
$headers->addHeader($header); | ||
$response->setHeaders($headers); | ||
|
||
$response = \Zend\Http\Client\Cookies::fromResponse($response, "http://www.zend.com"); | ||
$this->assertSame($header, $response->getCookie('http://www.zend.com', 'foo')); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you still intend for this to use Cookie (vs. SetCookie)? If so, you need to re-add the import; if not, this should be updated.