Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 984269c

Browse files
committed
Merge branch 'hotfix/config-dependencies' of https://github.com/Maks3w/zf2 into feature/config-hinting-removal
Conflicts: library/Zend/Feed/PubSubHubbub/AbstractCallbackInterface.php library/Zend/Feed/PubSubHubbub/Publisher.php library/Zend/Feed/PubSubHubbub/Subscriber.php library/Zend/Http/Client.php library/Zend/Http/Client/Adapter/Curl.php library/Zend/Http/Client/Adapter/Socket.php library/Zend/Http/Client/Adapter/Test.php library/Zend/Markup/Parser/Bbcode.php library/Zend/Markup/Parser/ParserInterface.php library/Zend/Markup/Renderer/AbstractRenderer.php library/Zend/Markup/Renderer/Html.php library/Zend/Service/Twitter/Twitter.php
2 parents defd56d + c098d13 commit 984269c

File tree

11 files changed

+100
-92
lines changed

11 files changed

+100
-92
lines changed

src/Client.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020

2121
namespace Zend\Http;
2222

23+
use Traversable;
24+
use Zend\Stdlib\ArrayUtils;
2325
use ArrayIterator,
24-
Zend\Config\Config,
2526
Zend\Uri\Http,
2627
Zend\Stdlib;
2728

@@ -108,7 +109,7 @@ class Client implements Stdlib\DispatchableInterface
108109
protected $redirectCounter = 0;
109110

110111
/**
111-
* Configuration array, set using the constructor or using ::setConfig()
112+
* Configuration array, set using the constructor or using ::setOptions()
112113
*
113114
* @var array
114115
*/
@@ -140,42 +141,42 @@ class Client implements Stdlib\DispatchableInterface
140141
* Constructor
141142
*
142143
* @param string $uri
143-
* @param array $config
144+
* @param array|Traversable $options
144145
*/
145-
public function __construct($uri = null, $config = null)
146+
public function __construct($uri = null, $options = null)
146147
{
147148
if ($uri !== null) {
148149
$this->setUri($uri);
149150
}
150-
if ($config !== null) {
151-
$this->setConfig($config);
151+
if ($options !== null) {
152+
$this->setOptions($options);
152153
}
153154
}
154155

155156
/**
156157
* Set configuration parameters for this HTTP client
157158
*
158-
* @param Config|array $config
159+
* @param array|Traversable $options
159160
* @return Client
160161
* @throws Client\Exception\InvalidArgumentException
161162
*/
162-
public function setConfig($config = array())
163+
public function setOptions($options = array())
163164
{
164-
if ($config instanceof Config) {
165-
$config = $config->toArray();
166-
167-
} elseif (!is_array($config)) {
168-
throw new Exception\InvalidArgumentException('Config parameter is not valid');
165+
if ($options instanceof Traversable) {
166+
$options = ArrayUtils::iteratorToArray($options);
167+
}
168+
if (!is_array($options)) {
169+
throw new Client\Exception\InvalidArgumentException('Config parameter is not valid');
169170
}
170171

171172
/** Config Key Normalization */
172-
foreach ($config as $k => $v) {
173+
foreach ($options as $k => $v) {
173174
$this->config[str_replace(array('-', '_', ' ', '.'), '', strtolower($k))] = $v; // replace w/ normalized
174175
}
175176

176177
// Pass configuration options to the adapter if it exists
177178
if ($this->adapter instanceof Client\Adapter\AdapterInterface) {
178-
$this->adapter->setConfig($config);
179+
$this->adapter->setOptions($options);
179180
}
180181

181182
return $this;
@@ -207,7 +208,7 @@ public function setAdapter($adapter)
207208
$this->adapter = $adapter;
208209
$config = $this->config;
209210
unset($config['adapter']);
210-
$this->adapter->setConfig($config);
211+
$this->adapter->setOptions($config);
211212
return $this;
212213
}
213214

@@ -579,7 +580,7 @@ public function getHeader($name)
579580
*/
580581
public function setStream($streamfile = true)
581582
{
582-
$this->setConfig(array("outputstream" => $streamfile));
583+
$this->setOptions(array("outputstream" => $streamfile));
583584
return $this;
584585
}
585586

src/Client/Adapter/AdapterInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ interface AdapterInterface
3838
/**
3939
* Set the configuration array for the adapter
4040
*
41-
* @param array $config
41+
* @param array $options
4242
*/
43-
public function setConfig($config = array());
43+
public function setOptions($options = array());
4444

4545
/**
4646
* Connect to the remote server

src/Client/Adapter/Curl.php

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222

2323
namespace Zend\Http\Client\Adapter;
2424

25-
use Zend\Http\Client\Adapter\AdapterInterface as HttpAdapter,
26-
Zend\Http\Client\Adapter\Exception as AdapterException,
27-
Zend\Http\Client,
28-
Zend\Http\Request;
25+
use Traversable;
26+
use Zend\Stdlib\ArrayUtils;
27+
use Zend\Http\Client\Adapter\AdapterInterface as HttpAdapter;
28+
use Zend\Http\Client\Adapter\Exception as AdapterException;
29+
use Zend\Http\Client;
30+
use Zend\Http\Request;
2931

3032
/**
3133
* An adapter class for Zend\Http\Client based on the curl extension.
@@ -84,7 +86,7 @@ class Curl implements HttpAdapter, StreamInterface
8486
/**
8587
* Adapter constructor
8688
*
87-
* Config is set using setConfig()
89+
* Config is set using setOptions()
8890
*
8991
* @return void
9092
* @throws AdapterException\InitializationException
@@ -116,32 +118,33 @@ public function __construct()
116118
/**
117119
* Set the configuration array for the adapter
118120
*
121+
* @param array|Traversable $options
122+
* @return Curl
119123
* @throws AdapterException\InvalidArgumentException
120-
* @param \Zend\Config\Config | array $config
121-
* @return \Zend\Http\Client\Adapter\Curl
122124
*/
123-
public function setConfig($config = array())
125+
public function setOptions($options = array())
124126
{
125-
if ($config instanceof \Zend\Config\Config) {
126-
$config = $config->toArray();
127-
} elseif (!is_array($config)) {
127+
if ($options instanceof Traversable) {
128+
$options = ArrayUtils::iteratorToArray($options);
129+
}
130+
if (!is_array($options)) {
128131
throw new AdapterException\InvalidArgumentException(
129-
'Array or Zend\Config\Config object expected, got ' . gettype($config)
132+
'Array or Traversable object expected, got ' . gettype($options)
130133
);
131134
}
132135

133136
/** Config Key Normalization */
134-
foreach ($config as $k => $v) {
135-
unset($config[$k]); // unset original value
136-
$config[str_replace(array('-', '_', ' ', '.'), '', strtolower($k))] = $v; // replace w/ normalized
137+
foreach ($options as $k => $v) {
138+
unset($options[$k]); // unset original value
139+
$options[str_replace(array('-', '_', ' ', '.'), '', strtolower($k))] = $v; // replace w/ normalized
137140
}
138141

139-
if (isset($config['proxyuser']) && isset($config['proxypass'])) {
140-
$this->setCurlOption(CURLOPT_PROXYUSERPWD, $config['proxyuser'].":".$config['proxypass']);
141-
unset($config['proxyuser'], $config['proxypass']);
142+
if (isset($options['proxyuser']) && isset($options['proxypass'])) {
143+
$this->setCurlOption(CURLOPT_PROXYUSERPWD, $options['proxyuser'].":".$options['proxypass']);
144+
unset($options['proxyuser'], $options['proxypass']);
142145
}
143146

144-
foreach ($config as $k => $v) {
147+
foreach ($options as $k => $v) {
145148
$option = strtolower($k);
146149
switch($option) {
147150
case 'proxyhost':

src/Client/Adapter/Socket.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121

2222
namespace Zend\Http\Client\Adapter;
2323

24-
use Zend\Http\Client\Adapter\AdapterInterface as HttpAdapter,
25-
Zend\Http\Client\Adapter\Exception as AdapterException,
26-
Zend\Http\Response;
24+
use Traversable;
25+
use Zend\Stdlib\ArrayUtils;
26+
use Zend\Http\Client\Adapter\AdapterInterface as HttpAdapter;
27+
use Zend\Http\Client\Adapter\Exception as AdapterException;
28+
use Zend\Http\Response;
2729

2830
/**
2931
* A sockets based (stream\socket\client) adapter class for Zend\Http\Client. Can be used
@@ -86,7 +88,7 @@ class Socket implements HttpAdapter, StreamInterface
8688
protected $_context = null;
8789

8890
/**
89-
* Adapter constructor, currently empty. Config is set using setConfig()
91+
* Adapter constructor, currently empty. Config is set using setOptions()
9092
*
9193
*/
9294
public function __construct()
@@ -96,20 +98,20 @@ public function __construct()
9698
/**
9799
* Set the configuration array for the adapter
98100
*
99-
* @param \Zend\Config\Config | array $config
101+
* @param array|Traversable $options
100102
*/
101-
public function setConfig($config = array())
103+
public function setOptions($options = array())
102104
{
103-
if ($config instanceof \Zend\Config\Config) {
104-
$config = $config->toArray();
105-
106-
} elseif (! is_array($config)) {
105+
if ($options instanceof Traversable) {
106+
$options = ArrayUtils::iteratorToArray($options);
107+
}
108+
if (!is_array($options)) {
107109
throw new AdapterException\InvalidArgumentException(
108-
'Array or Zend_Config object expected, got ' . gettype($config)
110+
'Array or Zend_Config object expected, got ' . gettype($options)
109111
);
110112
}
111113

112-
foreach ($config as $k => $v) {
114+
foreach ($options as $k => $v) {
113115
$this->config[strtolower($k)] = $v;
114116
}
115117
}

src/Client/Adapter/Test.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121

2222
namespace Zend\Http\Client\Adapter;
2323

24-
use Zend\Http\Client\Adapter\AdapterInterface as HttpAdapter,
25-
Zend\Http\Client\Adapter\Exception as AdapterException,
26-
Zend\Http\Response;
24+
use Traversable;
25+
use Zend\Stdlib\ArrayUtils;
26+
use Zend\Http\Client\Adapter\AdapterInterface as HttpAdapter;
27+
use Zend\Http\Client\Adapter\Exception as AdapterException;
28+
use Zend\Http\Response;
2729

2830
/**
2931
* A testing-purposes adapter.
@@ -71,8 +73,7 @@ class Test implements HttpAdapter
7173
protected $_nextRequestWillFail = false;
7274

7375
/**
74-
* Adapter constructor, currently empty. Config is set using setConfig()
75-
*
76+
* Adapter constructor, currently empty. Config is set using setOptions()
7677
*/
7778
public function __construct()
7879
{ }
@@ -93,20 +94,21 @@ public function setNextRequestWillFail($flag)
9394
/**
9495
* Set the configuration array for the adapter
9596
*
96-
* @param \Zend\Config\Config | array $config
97+
* @param array|Traversable $options
9798
*/
98-
public function setConfig($config = array())
99+
public function setOptions($options = array())
99100
{
100-
if ($config instanceof \Zend\Config\Config) {
101-
$config = $config->toArray();
101+
if ($options instanceof Traversable) {
102+
$options = ArrayUtils::iteratorToArray($options);
103+
}
102104

103-
} elseif (! is_array($config)) {
105+
if (! is_array($options)) {
104106
throw new AdapterException\InvalidArgumentException(
105-
'Array or Zend\Config\Config object expected, got ' . gettype($config)
107+
'Array or Traversable object expected, got ' . gettype($options)
106108
);
107109
}
108110

109-
foreach ($config as $k => $v) {
111+
foreach ($options as $k => $v) {
110112
$this->config[strtolower($k)] = $v;
111113
}
112114
}

test/Client/CommonHttpTests.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ public function testRedirectStrict()
496496
$this->client->setParameterPost(array('Camelot' => 'A silly place'));
497497

498498
// Set strict redirections
499-
$this->client->setConfig(array('strictredirects' => true));
499+
$this->client->setOptions(array('strictredirects' => true));
500500

501501
// Request
502502
$this->client->setMethod('POST');
@@ -523,7 +523,7 @@ public function testMaxRedirectsExceeded()
523523

524524
// Set lower max redirections
525525
// Try with strict redirections first
526-
$this->client->setConfig(array('strictredirects' => true, 'maxredirects' => 2));
526+
$this->client->setOptions(array('strictredirects' => true, 'maxredirects' => 2));
527527

528528
$this->client->setMethod('POST');
529529
$res = $this->client->send();
@@ -532,7 +532,7 @@ public function testMaxRedirectsExceeded()
532532

533533
// Then try with normal redirections
534534
$this->client->setParameterGet(array('redirection' => '0'));
535-
$this->client->setConfig(array('strictredirects' => false));
535+
$this->client->setOptions(array('strictredirects' => false));
536536
$this->client->setMethod('POST');
537537
$res = $this->client->send();
538538
$this->assertTrue($res->isRedirect(),
@@ -547,7 +547,7 @@ public function testAbsolutePathRedirect()
547547
{
548548
$this->client->setUri($this->baseuri . 'testRelativeRedirections.php');
549549
$this->client->setParameterGet(array('redirect' => 'abpath'));
550-
$this->client->setConfig(array('maxredirects' => 1));
550+
$this->client->setOptions(array('maxredirects' => 1));
551551

552552
// Get the host and port part of our baseuri
553553
$port = ($this->client->getUri()->getPort() == 80) ? '' : ':' .$this->client->getUri()->getPort();
@@ -567,7 +567,7 @@ public function testRelativePathRedirect()
567567
{
568568
$this->client->setUri($this->baseuri . 'testRelativeRedirections.php');
569569
$this->client->setParameterGet(array('redirect' => 'relpath'));
570-
$this->client->setConfig(array('maxredirects' => 1));
570+
$this->client->setOptions(array('maxredirects' => 1));
571571

572572
// Set the new expected URI
573573
$uri = clone $this->client->getUri();

0 commit comments

Comments
 (0)