提交 c0dc85de 编写于 作者: M Michael Dowling

Breaking / Potentially breaking changes:

    1. Adopting a marker interface for Guzzle exceptions.
        A. All exceptions emitted from Guzzle are now wrapped with a Guzzle namespaced exception.
        B. Guzzle\Common\GuzzleExceptionInterface was renamed to Guzzle\Common\GuzzleException
        C. Guzzle\Common\ExceptionCollection was renamed to Guzzle\Common\Exception\ExceptionCollection
    2. Using Header objects for Request and Response objects
        A. When you call $request->getHeader('X'), you will get back a Guzzle\Http\Message\Header object that contains all of the headers that case insensitively match.  This object can be cast to a string or iterated like an array.  You can pass true in the second argument to retrieve the header as a string.
        B. Removing the old Guzzle\Common\Collection based searching arguments from most of the request and response header methods.  All retrievals are case-insensitive and return Header objects.
    3. Changing the two headers added by the cache plugin to just one header with key and ttl.
    4. Changing Guzzle\Http\Message\Response::factory() to fromMessage().
    5. Removing the NullObject return value from ServiceDescriptions and instead simply returning null

New Features / enhancements:

    1. Adding Guzzle\Http\Message\AbstractMessage::addHeaders()
    2. Making it simpler to create service descriptions using a unified factory method that delegates to other factories.
    3. Better handling of ports and hosts in Guzzle\Http\Url

Note: This is a noisy diff because I'm removing trailing whitespace and adding a new line at the end of each source file.
上级 cbf125fd
......@@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
\ No newline at end of file
THE SOFTWARE.
......@@ -111,7 +111,7 @@ try {
$client->head('messages/123'),
$client->delete('orders/123')
));
} catch (Guzzle\Common\ExceptionCollection $e) {
} catch (Guzzle\Common\Exception\ExceptionCollection $e) {
echo "The following requests encountered an exception: \n";
foreach ($e as $exception) {
echo $exception->getRequest() . "\n" . $exception->getMessage() . "\n";
......
......@@ -63,4 +63,4 @@
</else>
</if>
</target>
</project>
\ No newline at end of file
</project>
<?php
__HALT_COMPILER();
\ No newline at end of file
__HALT_COMPILER();
......@@ -12,4 +12,4 @@ $classLoader->registerNamespaces(array(
));
$classLoader->register();
__HALT_COMPILER();
\ No newline at end of file
__HALT_COMPILER();
......@@ -20,7 +20,18 @@
<directory suffix=".php">./src/Guzzle</directory>
<exclude>
<directory suffix="Interface.php">./src/Guzzle</directory>
<file>./src/Guzzle/Common/GuzzleException.php</file>
<file>./src/Guzzle/Http/HttpException.php</file>
<file>./src/Guzzle/Common/Exception/BadMethodCallException.php</file>
<file>./src/Guzzle/Common/Exception/InvalidArgumentException.php</file>
<file>./src/Guzzle/Common/Exception/RuntimeException.php</file>
<file>./src/Guzzle/Common/Exception/UnexpectedValueException.php</file>
<file>./src/Guzzle/Service/Exception/ClientNotFoundException.php</file>
<file>./src/Guzzle/Service/Exception/CommandException.php</file>
<file>./src/Guzzle/Service/Exception/DescriptionBuilderException.php</file>
<file>./src/Guzzle/Service/Exception/ServiceBuilderException.php</file>
<file>./src/Guzzle/Service/Exception/ServiceNotFoundException.php</file>
<file>./src/Guzzle/Service/Exception/ValidationException.php</file>
</exclude>
</whitelist>
</filter>
......
......@@ -52,4 +52,4 @@ class AbstractHasDispatcher implements HasDispatcherInterface
{
$this->getEventDispatcher()->dispatch($eventName, new Event($context));
}
}
\ No newline at end of file
}
......@@ -16,4 +16,4 @@ abstract class AbstractCacheAdapter implements CacheAdapterInterface
{
return $this->cache;
}
}
\ No newline at end of file
}
......@@ -2,6 +2,9 @@
namespace Guzzle\Common\Cache;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Common\Exception\RuntimeException;
/**
* Generates cache adapters and cache providers objects using an array of
* configuration data. This can be useful for creating cache adapters
......@@ -21,12 +24,12 @@ class CacheAdapterFactory
foreach (array('cache.adapter', 'cache.provider') as $required) {
// Validate that the required parameters were set
if (!isset($config[$required])) {
throw new \InvalidArgumentException("{$required} is a required CacheAdapterFactory option");
throw new InvalidArgumentException("{$required} is a required CacheAdapterFactory option");
}
// Ensure that the cache adapter and provider are actual classes
if (is_string($config[$required]) && !class_exists($config[$required])) {
throw new \InvalidArgumentException("{$config[$required]} is not a valid class for {$required}");
throw new InvalidArgumentException("{$config[$required]} is not a valid class for {$required}");
}
}
......@@ -56,11 +59,15 @@ class CacheAdapterFactory
*/
protected static function createObject($className, array $args = null)
{
if (!$args) {
return new $className;
} else {
$c = new \ReflectionClass($className);
return $c->newInstanceArgs($args);
try {
if (!$args) {
return new $className;
} else {
$c = new \ReflectionClass($className);
return $c->newInstanceArgs($args);
}
} catch (\Exception $e) {
throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
}
}
}
\ No newline at end of file
}
......@@ -58,4 +58,4 @@ interface CacheAdapterInterface
* FALSE otherwise.
*/
function save($id, $data, $lifeTime = false, array $options = null);
}
\ No newline at end of file
}
......@@ -2,6 +2,8 @@
namespace Guzzle\Common\Cache;
use Guzzle\Common\Exception\InvalidArgumentException;
/**
* Cache adapter that defers to closures for implementation
*/
......@@ -28,7 +30,7 @@ class ClosureCacheAdapter implements CacheAdapterInterface
// Validate each key to ensure it exists and is callable
foreach (array('contains', 'delete', 'fetch', 'save') as $key) {
if (!array_key_exists($key, $callables) || !is_callable($callables[$key])) {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
"callables must contain a callable $key key");
}
}
......@@ -67,4 +69,4 @@ class ClosureCacheAdapter implements CacheAdapterInterface
{
return call_user_func($this->callables['save'], $id, $data, $lifeTime, $options);
}
}
\ No newline at end of file
}
......@@ -50,4 +50,4 @@ class DoctrineCacheAdapter extends AbstractCacheAdapter
{
return $this->cache->save($id, $data, $lifeTime);
}
}
\ No newline at end of file
}
......@@ -48,4 +48,4 @@ class Zf1CacheAdapter extends AbstractCacheAdapter
{
return $this->cache->save($data, $id, array(), $lifeTime);
}
}
\ No newline at end of file
}
......@@ -79,4 +79,4 @@ class Zf2CacheAdapter extends AbstractCacheAdapter
'ttl' => $lifeTime
)));
}
}
\ No newline at end of file
}
......@@ -417,4 +417,4 @@ class Collection implements \ArrayAccess, \IteratorAggregate, \Countable
return $this;
}
}
\ No newline at end of file
}
......@@ -63,4 +63,4 @@ class Event extends SymfonyEvent implements \ArrayAccess, \IteratorAggregate
{
unset($this->context[$offset]);
}
}
\ No newline at end of file
}
<?php
namespace Guzzle\Common\Exception;
use Guzzle\Common\GuzzleException;
class BadMethodCallException extends \BadMethodCallException implements GuzzleException {}
<?php
namespace Guzzle\Common;
namespace Guzzle\Common\Exception;
use Guzzle\Common\GuzzleException;
/**
* Collection of exceptions
*/
class ExceptionCollection extends \Exception implements GuzzleExceptionInterface, \IteratorAggregate, \Countable
class ExceptionCollection extends \Exception implements GuzzleException, \IteratorAggregate, \Countable
{
/**
* @var array Array of Exceptions
......@@ -55,4 +57,4 @@ class ExceptionCollection extends \Exception implements GuzzleExceptionInterface
{
return new \ArrayIterator($this->exceptions);
}
}
\ No newline at end of file
}
<?php
namespace Guzzle\Common\Exception;
use Guzzle\Common\GuzzleException;
class InvalidArgumentException extends \InvalidArgumentException implements GuzzleException {}
<?php
namespace Guzzle\Common\Exception;
use Guzzle\Common\GuzzleException;
class RuntimeException extends \RuntimeException implements GuzzleException {}
<?php
namespace Guzzle\Common\Exception;
use Guzzle\Common\GuzzleException;
class UnexpectedValueException extends \UnexpectedValueException implements GuzzleException {}
......@@ -5,6 +5,4 @@ namespace Guzzle\Common;
/**
* Guzzle exception
*/
interface GuzzleExceptionInterface
{
}
\ No newline at end of file
interface GuzzleException {}
......@@ -5,22 +5,22 @@ namespace Guzzle\Common;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Holds an event dispatcher
* Holds an event dispatcher
*/
interface HasDispatcherInterface
{
/**
* Get a list of all of the events emitted from the class
*
* @return array
*
* @return array
*/
static function getAllEvents();
/**
* Set the EventDispatcher of the request
*
* @param EventDispatcherInterface $eventDispatcher
*
*
* @return HasDispatcherInterface
*/
function setEventDispatcher(EventDispatcherInterface $eventDispatcher);
......@@ -31,12 +31,12 @@ interface HasDispatcherInterface
* @return EventDispatcherInterface
*/
function getEventDispatcher();
/**
* Helper to dispatch Guzzle events and set the event name on the event
*
*
* @param $eventName Name of the event to dispatch
* @param array $context Context of the event
*/
function dispatch($eventName, array $context = array());
}
\ No newline at end of file
}
......@@ -18,4 +18,4 @@ abstract class AbstractLogAdapter implements LogAdapterInterface
{
return $this->log;
}
}
\ No newline at end of file
}
......@@ -2,6 +2,8 @@
namespace Guzzle\Common\Log;
use Guzzle\Common\Exception\InvalidArgumentException;
/**
* Allows Closures to be called when messages are logged. Closures combined
* with filtering can trigger application events based on log messages.
......@@ -14,7 +16,7 @@ class ClosureLogAdapter extends AbstractLogAdapter
public function __construct($logObject)
{
if (!is_callable($logObject)) {
throw new \InvalidArgumentException('Object must be callable');
throw new InvalidArgumentException('Object must be callable');
}
$this->log = $logObject;
......@@ -27,4 +29,4 @@ class ClosureLogAdapter extends AbstractLogAdapter
{
call_user_func($this->log, $message, $priority, $extras);
}
}
\ No newline at end of file
}
......@@ -17,4 +17,4 @@ interface LogAdapterInterface
* @param mixed $extras (optional) Extra information to log in event
*/
function log($message, $priority = LOG_INFO, $extras = null);
}
\ No newline at end of file
}
......@@ -38,4 +38,4 @@ class MonologLogAdapter extends AbstractLogAdapter
{
$this->log->addRecord(self::$mapping[$priority], $message);
}
}
\ No newline at end of file
}
......@@ -22,4 +22,4 @@ class Zf1LogAdapter extends AbstractLogAdapter
{
$this->log->log($message, $priority, $extras);
}
}
\ No newline at end of file
}
......@@ -24,4 +24,4 @@ class Zf2LogAdapter extends AbstractLogAdapter
{
$this->log->log($message, $priority, $extras);
}
}
\ No newline at end of file
}
......@@ -22,4 +22,4 @@ class NullObject implements \Iterator, \Countable, \ArrayAccess
public function next() {}
public function rewind() {}
public function valid() {}
}
\ No newline at end of file
}
......@@ -2,6 +2,8 @@
namespace Guzzle\Common;
use Guzzle\Common\Exception\InvalidArgumentException;
/**
* OO interface to PHP streams
*/
......@@ -34,7 +36,7 @@ class Stream
public function __construct($stream, $size = null)
{
if (!is_resource($stream)) {
throw new \InvalidArgumentException('Stream must be a resource');
throw new InvalidArgumentException('Stream must be a resource');
}
$this->size = $size;
......@@ -279,4 +281,4 @@ class Stream
{
return $this->isWritable() ? fwrite($this->stream, $string) : false;
}
}
\ No newline at end of file
}
......@@ -79,4 +79,4 @@ class XmlElement extends \SimpleXMLElement
return $doc->saveXML();
}
}
\ No newline at end of file
}
......@@ -104,4 +104,4 @@ class Guzzle
{
self::$cache = array();
}
}
\ No newline at end of file
}
......@@ -3,9 +3,10 @@
namespace Guzzle\Http;
use Guzzle\Guzzle;
use Guzzle\Common\AbstractHasDispatcher;
use Guzzle\Common\ExceptionCollection;
use Guzzle\Common\Collection;
use Guzzle\Common\AbstractHasDispatcher;
use Guzzle\Common\Exception\ExceptionCollection;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Http\Url;
use Guzzle\Http\UriTemplate;
use Guzzle\Http\EntityBody;
......@@ -98,7 +99,7 @@ class Client extends AbstractHasDispatcher implements ClientInterface
} else if (is_array($config)) {
$this->config = new Collection($config);
} else {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
'Config must be an array or Collection'
);
}
......@@ -144,7 +145,7 @@ class Client extends AbstractHasDispatcher implements ClientInterface
} else if (is_array($headers)) {
$this->defaultHeaders = new Collection($headers);
} else {
throw new \InvalidArgumentException('Headers must be an array or Collection');
throw new InvalidArgumentException('Headers must be an array or Collection');
}
return $this;
......@@ -222,7 +223,7 @@ class Client extends AbstractHasDispatcher implements ClientInterface
$templateVars = null;
} else {
if (count($uri) != 2 || !is_array($uri[1])) {
throw new \InvalidArgumentException('You must provide a URI'
throw new InvalidArgumentException('You must provide a URI'
. ' template followed by an array of template variables'
. ' when using an array for a URI template');
}
......@@ -536,4 +537,4 @@ class Client extends AbstractHasDispatcher implements ClientInterface
return $this;
}
}
\ No newline at end of file
}
......@@ -250,4 +250,4 @@ interface ClientInterface extends HasDispatcherInterface
* @return ClientInterface
*/
function setRequestFactory(RequestFactoryInterface $factory);
}
\ No newline at end of file
}
......@@ -53,4 +53,4 @@ class Cookie extends QueryString
);
});
}
}
\ No newline at end of file
}
......@@ -3,6 +3,7 @@
namespace Guzzle\Http\CookieJar;
use Guzzle\Common\Collection;
use Guzzle\Common\Exception\InvalidArgumentException;
/**
* Cookie jar that stores cookies an an array
......@@ -155,11 +156,11 @@ class ArrayCookieJar implements CookieJarInterface, \Serializable
public function save(array $cookieData)
{
if (!isset($cookieData['domain'])) {
throw new \InvalidArgumentException('Cookies require a domain');
throw new InvalidArgumentException('Cookies require a domain');
}
if (!isset($cookieData['cookie']) || !is_array($cookieData['cookie'])) {
throw new \InvalidArgumentException('Cookies require a names and values');
throw new InvalidArgumentException('Cookies require a names and values');
}
$cookieData = array_merge(array(
......@@ -255,4 +256,4 @@ class ArrayCookieJar implements CookieJarInterface, \Serializable
return $originalCount - count($this->cookies);
}
}
\ No newline at end of file
}
......@@ -90,4 +90,4 @@ interface CookieJarInterface
* @return CookieJarInterface
*/
function save(array $cookieData);
}
\ No newline at end of file
}
......@@ -75,4 +75,4 @@ class FileCookieJar extends ArrayCookieJar
$this->cookies = $json ? json_decode($json, true) : array();
}
}
\ No newline at end of file
}
......@@ -3,6 +3,7 @@
namespace Guzzle\Http\Curl;
use Guzzle\Guzzle;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Common\Collection;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\EntityEnclosingRequestInterface;
......@@ -46,7 +47,7 @@ class CurlHandle
CURLOPT_CONNECTTIMEOUT => 10, // Connect timeout in seconds
CURLOPT_RETURNTRANSFER => false, // Streaming the return, so no need
CURLOPT_HEADER => false, // Retrieve the received headers
CURLOPT_USERAGENT => $request->getHeader('User-Agent', Guzzle::getDefaultUserAgent()),
CURLOPT_USERAGENT => (string) $request->getHeader('User-Agent'),
CURLOPT_ENCODING => '', // Supports all encodings
CURLOPT_PORT => $request->getPort(),
CURLOPT_HTTP_VERSION => $request->getProtocolVersion(true),
......@@ -87,7 +88,7 @@ class CurlHandle
}
// @codeCoverageIgnoreEnd
$headers = $request->getHeaders();
$headers = $request->getHeaders()->getAll();
// Specify settings according to the HTTP method
switch ($request->getMethod()) {
......@@ -106,7 +107,7 @@ class CurlHandle
$curlOptions[CURLOPT_UPLOAD] = true;
if ($request->hasHeader('Content-Length')) {
unset($headers['Content-Length']);
$curlOptions[CURLOPT_INFILESIZE] = $request->getHeader('Content-Length');
$curlOptions[CURLOPT_INFILESIZE] = (int) (string) $request->getHeader('Content-Length');
}
break;
......@@ -149,14 +150,12 @@ class CurlHandle
$curlOptions[$key] = $value;
}
// Add any custom headers to the request. Empty headers will not be
// added. Headers explicitly set to NULL _will_ be added.
// Add any custom headers to the request. Emtpy headers will cause curl to
// not send the header at all.
foreach ($headers as $key => $value) {
if ($value === null) {
$curlOptions[CURLOPT_HTTPHEADER][] = "{$key}:";
} else if ($key) {
if ($key) {
foreach ((array) $value as $val) {
$curlOptions[CURLOPT_HTTPHEADER][] = "{$key}: {$val}";
$curlOptions[CURLOPT_HTTPHEADER][] = trim("{$key}: {$val}");
}
}
}
......@@ -191,14 +190,14 @@ class CurlHandle
public function __construct($handle, $options)
{
if (!is_resource($handle)) {
throw new \InvalidArgumentException('Invalid handle provided');
throw new InvalidArgumentException('Invalid handle provided');
}
if (is_array($options)) {
$this->options = new Collection($options);
} else if ($options instanceof Collection) {
$this->options = $options;
} else {
throw new \InvalidArgumentException('Expected array or Collection');
throw new InvalidArgumentException('Expected array or Collection');
}
$this->handle = $handle;
}
......@@ -346,4 +345,4 @@ class CurlHandle