Skip to content
Browse files

Guzzle 2.0

Adopting composer for dependency management
Updating LICENSE, travis build file, making better use of git ignores, and remove unused build target
Removing @author tags.  Use the commit history for a changelog.
Moving files from build folder to /
Adding min build target to product a Guzzle only phar with no autoloader
[Common] Accepting ZF1 or ZF2 cache in ZendCacheAdapter
[Common] Optimizing Stream wrapper and EntityBody abstractions.
[Common] [Http] Migrating from Guzzle event system to the Symfony2 event dispatcher
[Common] Moved Inflector and Inspector to Service namespace
[Http] Simplifying Guzzle\Guzzle curl detection
[Http] Removing Guzzle\Http\Pool and now using Guzzle\Http\Curl\CurlMulti
[Http] The helper methods from Guzzle\Http\Message\RequestFactory have been removed to prevent confusion and encourage developers to use Guzzle\Http\Client to create requests.
[Http] Clients can now send one or more requests in an array using the send() method, so the batch() method was removed.
[Http] Updating curl multi to allow blocking calls while sending other transfers
[Http] Making the Request::hasHeader method more intuitive.  Guzzle\Http\Message\AbstractMessage::hasHeader() now returns true if the header is found using exact matching.  If the header is found using a regex or case-insensitive match, then it will return the name of the found header.
[Http] Removing content-type guessing from EntityBody based on file extension and solely using finfo.
[Http] Adding basic auth plugin
[Http] Cleaning up CookieJar and CurlMulti
[Http] Removing custom rawurlencode from QueryString because PHP 5.3 now properly deals with tilde characters.
[Http] Minor optimization to parsing messages in RequestFactory
[Http] Adding Guzzle\Http\Client for developers that don't need commands or service descriptions
[Http] Making it easier to set a global User-Agent header for a Guzzle\Http\Client
[Http] Fixing the discrepancies between the ClientInterface and Guzzle\Http\Client
[Http] Adding the ability to set and retrieve tokenized headers from Requests and Responses
[Service] Ditching NIH filters and using the Symfony2 validator
[Service] Moving most service building logic to the ServiceBuilder::factory method so that it is easier to build custom config readers.
[Service] Allowing deep nested command inheritance.
[Service] Cleaning up Inflector caching.
[Service] Getting rid of concept of can_batch because everything is now sent in parallel.
[Service] Adding a JSON description builder.
[Service] Cleaning up ResourceIteratorApplyBatched.
[Service] Removing caching stuff from ServiceBuilder because the data being cached is extremely fast to generate.
[Service] Added a method to serialize the ServiceDescription in case a ServiceDescription needs to be cached in an application.
[Service] Making description builders use static methods.
[Service] Adding support to include other description files for XML and JSON description builders.
[Service] Adding support for filters to ApiCommands
[Service] Using {{}} instead of $. to reference other services as a dependency for another service
  • Loading branch information...
1 parent 85dae7d commit 4c46e7701530f45e7893d03537b05073a3ea639e @mtdowling mtdowling committed
Showing with 2,929 additions and 4,512 deletions.
  1. +16 −6 .gitignore
  2. +0 −9 .gitmodules
  3. +3 −5 .travis.yml
  4. +1 −1 LICENSE
  5. +23 −11 README.md
  6. +24 −0 autoload.php
  7. +42 −0 build.xml
  8. +0 −22 build/autoload.php
  9. +0 −53 build/build.xml
  10. +55 −10 composer.json
  11. +0 −2 phpunit.xml.dist
  12. +55 −0 src/Guzzle/Common/AbstractHasDispatcher.php
  13. +1 −9 src/Guzzle/Common/Cache/AbstractCacheAdapter.php
  14. +0 −2 src/Guzzle/Common/Cache/CacheAdapterInterface.php
  15. +6 −30 src/Guzzle/Common/Cache/DoctrineCacheAdapter.php
  16. +13 −34 src/Guzzle/Common/Cache/ZendCacheAdapter.php
  17. +5 −10 src/Guzzle/Common/Collection.php
  18. +66 −0 src/Guzzle/Common/Event.php
  19. +0 −30 src/Guzzle/Common/Event/AbstractSubject.php
  20. +0 −234 src/Guzzle/Common/Event/EventManager.php
  21. +0 −22 src/Guzzle/Common/Event/Observer.php
  22. +0 −18 src/Guzzle/Common/Event/Subject.php
  23. +58 −0 src/Guzzle/Common/ExceptionCollection.php
  24. +0 −77 src/Guzzle/Common/Filter/AbstractFilter.php
  25. +0 −24 src/Guzzle/Common/Filter/ArrayFilter.php
  26. +0 −33 src/Guzzle/Common/Filter/BooleanFilter.php
  27. +0 −40 src/Guzzle/Common/Filter/ClassFilter.php
  28. +0 −34 src/Guzzle/Common/Filter/ClosureFilter.php
  29. +0 −36 src/Guzzle/Common/Filter/DateFilter.php
  30. +0 −39 src/Guzzle/Common/Filter/EnumFilter.php
  31. +0 −22 src/Guzzle/Common/Filter/FilterInterface.php
  32. +0 −25 src/Guzzle/Common/Filter/FloatFilter.php
  33. +0 −25 src/Guzzle/Common/Filter/IntegerFilter.php
  34. +0 −36 src/Guzzle/Common/Filter/RegexFilter.php
  35. +0 −25 src/Guzzle/Common/Filter/StringFilter.php
  36. +0 −31 src/Guzzle/Common/Filter/TimestampFilter.php
  37. +0 −12 src/Guzzle/Common/GuzzleException.php
  38. +10 −0 src/Guzzle/Common/GuzzleExceptionInterface.php
  39. +42 −0 src/Guzzle/Common/HasDispatcherInterface.php
  40. +0 −102 src/Guzzle/Common/Inflector.php
  41. +1 −8 src/Guzzle/Common/Log/AbstractLogAdapter.php
  42. +1 −8 src/Guzzle/Common/Log/ClosureLogAdapter.php
  43. +1 −5 src/Guzzle/Common/Log/LogAdapterInterface.php
  44. +1 −7 src/Guzzle/Common/Log/MonologLogAdapter.php
  45. +7 −12 src/Guzzle/Common/Log/ZendLogAdapter.php
  46. +15 −76 src/Guzzle/Common/NullObject.php
  47. +46 −142 src/Guzzle/Common/Stream.php
  48. +0 −3 src/Guzzle/Common/XmlElement.php
  49. +20 −40 src/Guzzle/Guzzle.php
  50. +391 −0 src/Guzzle/Http/Client.php
  51. +200 −0 src/Guzzle/Http/ClientInterface.php
  52. +3 −7 src/Guzzle/Http/Cookie.php
  53. +6 −17 src/Guzzle/Http/CookieJar/ArrayCookieJar.php
  54. +0 −2 src/Guzzle/Http/CookieJar/CookieJarInterface.php
  55. +3 −5 src/Guzzle/Http/CookieJar/FileCookieJar.php
  56. +15 −7 src/Guzzle/Http/Curl/CurlException.php
  57. +0 −474 src/Guzzle/Http/Curl/CurlFactory.php
  58. +0 −32 src/Guzzle/Http/Curl/CurlFactoryInterface.php
  59. +149 −267 src/Guzzle/Http/Curl/CurlHandle.php
  60. +485 −0 src/Guzzle/Http/Curl/CurlMulti.php
  61. +19 −18 src/Guzzle/Http/{Pool/PoolInterface.php → Curl/CurlMultiInterface.php}
  62. +21 −109 src/Guzzle/Http/EntityBody.php
  63. +1 −5 src/Guzzle/Http/HttpException.php
  64. +97 −47 src/Guzzle/Http/Message/AbstractMessage.php
  65. +0 −2 src/Guzzle/Http/Message/BadResponseException.php
  66. +101 −125 src/Guzzle/Http/Message/EntityEnclosingRequest.php
  67. +37 −11 src/Guzzle/Http/Message/EntityEnclosingRequestInterface.php
  68. +52 −24 src/Guzzle/Http/Message/MessageInterface.php
  69. +170 −291 src/Guzzle/Http/Message/Request.php
  70. +4 −2 src/Guzzle/Http/Message/RequestException.php
  71. +10 −103 src/Guzzle/Http/Message/RequestFactory.php
  72. +21 −45 src/Guzzle/Http/Message/RequestInterface.php
  73. +15 −23 src/Guzzle/Http/Message/Response.php
  74. +46 −0 src/Guzzle/Http/Plugin/BasicAuthPlugin.php
  75. +85 −89 src/Guzzle/Http/Plugin/CachePlugin.php
  76. +72 −54 src/Guzzle/Http/Plugin/CookiePlugin.php
  77. +56 −62 src/Guzzle/Http/Plugin/ExponentialBackoffPlugin.php
  78. +13 −9 src/Guzzle/Http/Plugin/HistoryPlugin.php
  79. +98 −69 src/Guzzle/Http/Plugin/LogPlugin.php
  80. +24 −21 src/Guzzle/Http/Plugin/Md5ValidatorPlugin.php
  81. +34 −20 src/Guzzle/{Service → Http}/Plugin/MockPlugin.php
  82. +0 −268 src/Guzzle/Http/Pool/Pool.php
  83. +0 −63 src/Guzzle/Http/Pool/PoolRequestException.php
  84. +18 −45 src/Guzzle/Http/QueryString.php
  85. +12 −15 src/Guzzle/Http/Url.php
  86. +20 −379 src/Guzzle/Service/Client.php
  87. +2 −197 src/Guzzle/Service/ClientInterface.php
  88. +13 −33 src/Guzzle/Service/Command/AbstractCommand.php
  89. +0 −16 src/Guzzle/Service/Command/ClosureCommand.php
  90. +0 −9 src/Guzzle/Service/Command/CommandInterface.php
  91. +39 −70 src/Guzzle/Service/Command/CommandSet.php
  92. +0 −2 src/Guzzle/Service/Command/CommandSetException.php
  93. +35 −86 src/Guzzle/Service/Description/ApiCommand.php
  94. +0 −2 src/Guzzle/Service/Description/CommandFactoryInterface.php
  95. +3 −3 src/Guzzle/Service/Description/DescriptionBuilderInterface.php
  96. +9 −14 src/Guzzle/Service/Description/DynamicCommandFactory.php
  97. +38 −0 src/Guzzle/Service/Description/JsonDescriptionBuilder.php
Sorry, we could not display the entire diff because it was too big.
View
22 .gitignore
@@ -1,10 +1,20 @@
+# Ingore common cruft
.DS_STORE
coverage
+
+# Ignore binary files
+guzzle.phar
+
+# Ignore potentially sensitive phpunit file
phpunit.xml
-build/guzzle.phar
-build/guzzle-na.phar
-src/Guzzle/Aws/
-src/Guzzle/CardinalCommerce/
-src/Guzzle/Unfuddle/
+
+# Helps to ignore services being tested
+src/Guzzle/
+!src/Guzzle/Guzzle.php
+!src/Guzzle/Common
+!src/Guzzle/Http
+!src/Guzzle/Service
+
+# Ignore composer generated files
composer.lock
-vendor/.composer
+vendor/
View
9 .gitmodules
@@ -1,9 +0,0 @@
-[submodule "vendor/Symfony/Component/ClassLoader"]
- path = vendor/Symfony/Component/ClassLoader
- url = https://github.com/symfony/ClassLoader
-[submodule "vendor/Doctrine"]
- path = vendor/Doctrine
- url = https://github.com/doctrine/common
-[submodule "vendor/Monolog"]
- path = vendor/Monolog
- url = https://github.com/Seldaek/monolog.git
View
8 .travis.yml
@@ -3,10 +3,8 @@ php:
- 5.3
- 5.4
before_script:
- - git submodule update --init
+ - wget --quiet http://getcomposer.org/composer.phar
+ - php composer.phar install --install-suggests
- cp phpunit.xml.dist phpunit.xml
- - ~/.nvm/v0.6.1/bin/node tests/Guzzle/Tests/Http/server.js &
+ - ~/.nvm/nvm.sh run default tests/Guzzle/Tests/Http/server.js &
script: sudo phpunit
-notifications:
- email:
- - michael@guzzlephp.org
View
2 LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2011 Michael Dowling <michael@guzzlephp.org>
+Copyright (c) 2011 Michael Dowling, https://github.com/mtdowling <mtdowling@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
View
34 README.md
@@ -1,7 +1,7 @@
Guzzle, PHP HTTP client and webservice framework
-===============================================
+================================================
-Guzzle is a game changer in the world of PHP HTTP clients. Guzzle allows you to truly reap the benefits of the HTTP/1.1 spec. No other library provides persistent connection management or makes it easier to send requests in parallel.</p>
+Guzzle is a game changer in the world of PHP HTTP clients. Guzzle allows you to truly reap the benefits of the HTTP/1.1 spec. No other library makes it easier to manage persistent connections or send requests in parallel.</p>
In addition to taking the pain out of HTTP, Guzzle provides a lightweight framework for creating web service clients. Most web service clients follow a specific pattern: create a client class, create methods for each action, create and execute a cURL handle, parse the response, implement error handling, and return the result. Guzzle takes the redundancy out of this process and gives you the tools you need to quickly build a web service client.
@@ -37,7 +37,7 @@ HTTP basics
```php
<?php
-use Guzzle\Service\Client;
+use Guzzle\Http\Client;
$client = new Client('http://www.example.com/api/v1/key/{{key}}', array(
'key' => '***'
@@ -102,18 +102,30 @@ Send requests in parallel
```php
<?php
-use Guzzle\Service\Client;
-
try {
- $responses = $client->batch(array(
- $client->get('http://www.google.com/'),
- $client->head('http://www.google.com/'),
- $client->get('https://www.github.com/')
+ $client = new Guzzle\Http\Client('http://www.myapi.com/api/v1');
+ $responses = $client->send(array(
+ $client->get('users'),
+ $client->head('messages/123'),
+ $client->delete('orders/123')
));
-} catch (PoolRequestException $e) {
+} catch (Guzzle\Common\ExceptionCollection $e) {
echo "The following requests encountered an exception: \n";
foreach ($e as $exception) {
echo $exception->getRequest() . "\n" . $exception->getMessage() . "\n";
}
}
-```
+```
+
+Testing Guzzle
+--------------
+
+Here's how to install Guzzle from source to run the unit tests:
+
+```
+git clone git@github.com:guzzle/guzzle.git
+cd guzzle
+composer.phar install --install-suggests
+cp phpunit.xml.dist phpunit.xml
+phpunit
+```
View
24 autoload.php
@@ -0,0 +1,24 @@
+<?php
+
+$namespaces = array(
+ 'Guzzle' => 'phar://' . __FILE__ . '/src',
+ 'Symfony\\Component\\Validator' => 'phar://' . __FILE__ . '/vendor/symfony/validator',
+ 'Symfony\\Component\\EventDispatcher' => 'phar://' . __FILE__ . '/vendor/symfony/event-dispatcher',
+ 'Doctrine' => 'phar://' . __FILE__ . '/vendor/doctrine/common/lib',
+ 'Monolog' => 'phar://' . __FILE__ . '/vendor/monolog/monolog/src'
+);
+
+if (DIRECTORY_SEPARATOR == '/') {
+ require_once 'phar://' . __FILE__ . '/vendor/symfony/class-loader/Symfony/Component/ClassLoader/UniversalClassLoader.php';
+} else {
+ require_once 'phar://' . __FILE__ . '\\vendor\\symfony\\class-loader\\Symfony\\Component\\ClassLoader\\UniversalClassLoader.php';
+ $namespaces = array_filter($namespaces, function($namespace) {
+ return str_replace('phar:\\\\', 'phar://', str_replace('/', '\\', $namespace));
+ });
+}
+
+$classLoader = new Symfony\Component\ClassLoader\UniversalClassLoader();
+$classLoader->registerNamespaces($namespaces);
+$classLoader->register();
+
+__HALT_COMPILER();
View
42 build.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="guzzle" default="phar">
+ <target name="phar" description="Create a phar with an autoloader">
+ <if>
+ <equals arg1="${min}" arg2="true" />
+ <then>
+ <pharpackage
+ destfile="./guzzle-min.phar"
+ basedir="."
+ alias="Guzzle"
+ signature="md5">
+ <fileset dir=".">
+ <include name="src/**/*.php" />
+ </fileset>
+ <metadata>
+ <element name="version" value="2.0.0" />
+ </metadata>
+ </pharpackage>
+ </then>
+ <else>
+ <pharpackage
+ destfile="./guzzle.phar"
+ basedir="."
+ stub="autoload.php"
+ alias="Guzzle"
+ signature="md5">
+ <fileset dir=".">
+ <include name="src/**/*.php" />
+ <include name="vendor/symfony/class-loader/Symfony/Component/ClassLoader/UniversalClassLoader.php" />
+ <include name="vendor/symfony/event-dispatcher/**/*.php" />
+ <include name="vendor/symfony/validator/**/*.php" />
+ <include name="vendor/doctrine/common/lib/Doctrine/Common/Cache/*.php" />
+ <include name="vendor/monolog/monolog/src/**/*.php" />
+ </fileset>
+ <metadata>
+ <element name="version" value="2.0.0" />
+ </metadata>
+ </pharpackage>
+ </else>
+ </if>
+ </target>
+</project>
View
22 build/autoload.php
@@ -1,22 +0,0 @@
-<?php
-/**
- * Autoloader stub for guzzle.phar to autoload Guzzle\* classes.
- *
- * Note: this autoloader does not load other PSR-0 libraries. If you need to
- * autoload other libraries, we recommend the Symfony ClassLoader component.
- */
-
-spl_autoload_register(function($class) {
- if (0 === strpos($class, 'Guzzle\\')) {
- if ('\\' != DIRECTORY_SEPARATOR) {
- $class = 'phar://' . __FILE__ . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
- } else {
- $class = 'phar://' . __FILE__ . DIRECTORY_SEPARATOR . $class . '.php';
- }
- if (file_exists($class)) {
- require $class;
- }
- }
-});
-
-__HALT_COMPILER();
View
53 build/build.xml
@@ -1,53 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<project name="guzzle" default="init">
-
- <target name="init-git" description="Initialize git submodules">
- <echo msg="Initializing git submodules" />
- <exec command="git submodule update --init" dir="./.." />
- </target>
-
- <target name="init-test" description="Initialize for unit testing">
- <echo msg="Copying ./phpunit.xml.dist to ./phpunit.xml" />
- <copy file="../phpunit.xml.dist" tofile="../phpunit.xml" />
- </target>
-
- <target name="init" depends="init-git,init-test" />
-
- <target name="phar" description="Create a phar with an autoloader">
- <if>
- <equals arg1="${autoload}" arg2="false" />
- <then>
- <pharpackage
- destfile="./guzzle-na.phar"
- basedir="../src"
- alias="Guzzle"
- signature="sha1">
- <fileset dir="../src">
- <include name="**/*.php" />
- <exclude name="**/Tests/**" />
- </fileset>
- <metadata>
- <element name="version" value="1.0.1" />
- </metadata>
- </pharpackage>
- </then>
- <else>
- <pharpackage
- destfile="./guzzle.phar"
- basedir="../src"
- stub="./autoload.php"
- alias="Guzzle"
- signature="sha1">
- <fileset dir="../src">
- <include name="**/*.php" />
- <exclude name="**/Tests/**" />
- </fileset>
- <metadata>
- <element name="version" value="1.0.1" />
- </metadata>
- </pharpackage>
- </else>
- </if>
- </target>
-</project>
View
65 composer.json
@@ -2,21 +2,66 @@
"name": "guzzle/guzzle",
"type": "library",
"description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients",
- "keywords": ["framework", "http", "rest"],
+ "keywords": ["framework", "http", "rest", "web service"],
"homepage": "http://www.guzzlephp.org/",
"license": "MIT",
- "authors": [
- {
- "name": "Michael Dowling",
- "email": "michael@guzzlephp.org"
+ "authors": [{
+ "name": "Michael Dowling",
+ "email": "mtdowling@gmail.com",
+ "homepage": "https://github.com/mtdowling"
+ },
+ {
+ "name": "Guzzle Community",
+ "homepage": "https://github.com/guzzle/guzzle/contributors"
+ }],
+ "repositories": {
+ "zend-log": {
+ "package": {
+ "name": "zend/zend-log",
+ "version": "2.0.0",
+ "autoload": { "psr-0": { "Zend\\Log": "" } },
+ "target-dir": "Zend/Log",
+ "dist": {
+ "url": "https://github.com/KnpLabs/zend-log/zipball/master",
+ "type": "zip"
+ },
+ "source": {
+ "url": "https://github.com/KnpLabs/zend-log.git",
+ "type": "git",
+ "reference": "master"
+ }
+ }
},
- {
- "name": "Guzzle Community",
- "homepage": "https://github.com/guzzle/guzzle/contributors"
+ "zend-cache": {
+ "package": {
+ "name": "zend/zend-cache",
+ "version": "2.0.0",
+ "autoload": { "psr-0": { "Zend\\Cache": "" } },
+ "target-dir": "Zend/Cache",
+ "dist": {
+ "url": "https://github.com/KnpLabs/zend-cache/zipball/master",
+ "type": "zip"
+ },
+ "source": {
+ "url": "https://github.com/KnpLabs/zend-cache.git",
+ "type": "git",
+ "reference": "master"
+ }
+ }
}
- ],
+ },
"require": {
- "php": ">=5.3.2"
+ "php": ">=5.3.2",
+ "ext-curl": "*",
+ "symfony/event-dispatcher": "*",
+ "symfony/validator": "*"
+ },
+ "suggest": {
+ "symfony/class-loader": "*",
+ "doctrine/common": "*",
+ "monolog/monolog": "*",
+ "zend/zend-cache": "*",
+ "zend/zend-log": "*"
},
"autoload": {
"psr-0": { "Guzzle": "src/" }
View
2 phpunit.xml.dist
@@ -20,8 +20,6 @@
<directory suffix=".php">./src/Guzzle</directory>
<exclude>
<directory suffix="Interface.php">./src/Guzzle</directory>
- <file>./src/Guzzle/Common/Event/Subject.php</file>
- <file>./src/Guzzle/Common/GuzzleException.php</file>
<file>./src/Guzzle/Http/HttpException.php</file>
</exclude>
</whitelist>
View
55 src/Guzzle/Common/AbstractHasDispatcher.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace Guzzle\Common;
+
+use Symfony\Component\EventDispatcher\EventDispatcher;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+
+/**
+ * Class that holds an event dispatcher
+ */
+class AbstractHasDispatcher implements HasDispatcherInterface
+{
+ /**
+ * @var EventDispatcherInterface
+ */
+ protected $eventDispatcher;
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getAllEvents()
+ {
+ return array();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setEventDispatcher(EventDispatcherInterface $eventDispatcher)
+ {
+ $this->eventDispatcher = $eventDispatcher;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getEventDispatcher()
+ {
+ if (!$this->eventDispatcher) {
+ $this->eventDispatcher = new EventDispatcher();
+ }
+
+ return $this->eventDispatcher;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function dispatch($eventName, array $context = array())
+ {
+ $this->getEventDispatcher()->dispatch($eventName, new Event($context));
+ }
+}
View
10 src/Guzzle/Common/Cache/AbstractCacheAdapter.php
@@ -4,21 +4,13 @@
/**
* Abstract cache adapter
- *
- * @link http://www.doctrine-project.org/
- * @author Michael Dowling <michael@guzzlephp.org>
*/
abstract class AbstractCacheAdapter implements CacheAdapterInterface
{
- /**
- * @var mixed Cache object that is wrapped by the adapter
- */
protected $cache;
/**
- * Get the cache object
- *
- * @return mixed
+ * {@inheritdoc}
*/
public function getCacheObject()
{
View
2 src/Guzzle/Common/Cache/CacheAdapterInterface.php
@@ -10,8 +10,6 @@
*
* The CacheAdapter interface was inspired by the Doctrine 2 ORM:
* @link http://www.doctrine-project.org/
- *
- * @author Michael Dowling <michael@guzzlephp.org>
*/
interface CacheAdapterInterface
{
View
36 src/Guzzle/Common/Cache/DoctrineCacheAdapter.php
@@ -7,15 +7,12 @@
/**
* Doctrine 2 cache adapter
*
- * @link http://www.doctrine-project.org/
- * @author Michael Dowling <michael@guzzlephp.org>
+ * @link http://www.doctrine-project.org/
*/
class DoctrineCacheAdapter extends AbstractCacheAdapter
{
/**
- * Constructor
- *
- * @param Cache $cacheObject Object to wrap and adapt
+ * {@inheritdoc}
*/
public function __construct(Cache $cache)
{
@@ -23,12 +20,7 @@ public function __construct(Cache $cache)
}
/**
- * Test if an entry exists in the cache.
- *
- * @param string $id cache id The cache id of the entry to check for.
- *
- * @return bool TRUE if a cache entry exists for the given cache id,
- * FALSE otherwise.
+ * {@inheritdoc}
*/
public function contains($id)
{
@@ -36,11 +28,7 @@ public function contains($id)
}
/**
- * Deletes a cache entry.
- *
- * @param string $id cache id
- *
- * @return bool TRUE on success, FALSE on failure
+ * {@inheritdoc}
*/
public function delete($id)
{
@@ -48,12 +36,7 @@ public function delete($id)
}
/**
- * Fetches an entry from the cache.
- *
- * @param string $id cache id The id of the cache entry to fetch.
- *
- * @return string The cached data or FALSE, if no cache entry exists for
- * the given id.
+ * {@inheritdoc}
*/
public function fetch($id)
{
@@ -61,14 +44,7 @@ public function fetch($id)
}
/**
- * Puts data into the cache.
- *
- * @param string $id The cache id.
- * @param string $data The cache entry/data.
- * @param int $lifeTime The lifetime. If != false, sets a specific lifetime
- * for this cache entry (null => infinite lifeTime).
- *
- * @return bool TRUE on success, FALSE on failure
+ * {@inheritdoc}
*/
public function save($id, $data, $lifeTime = false)
{
View
47 src/Guzzle/Common/Cache/ZendCacheAdapter.php
@@ -2,31 +2,27 @@
namespace Guzzle\Common\Cache;
+use Zend\Cache\Backend;
+
/**
- * Zend Framework 1.x cache adapter
- *
- * @link http://www.doctrine-project.org/
- * @author Michael Dowling <michael@guzzlephp.org>
+ * ZF1 / ZF2 cache adapter
*/
class ZendCacheAdapter extends AbstractCacheAdapter
{
/**
- * Constructor
- *
- * @param Zend_Cache_Backend $cacheObject Object to wrap and adapt
+ * {@inheritdoc}
*/
- public function __construct(\Zend_Cache_Backend $cache)
+ public function __construct($cache)
{
+ if (!($cache instanceof Backend) && !($cache instanceof \Zend_Cache_Backend)) {
+ throw new \InvalidArgumentException('$cache must be an instance of '
+ . 'Zend\\Log\\Backend or Zend_Cache_Backend');
+ }
$this->cache = $cache;
}
/**
- * Test if an entry exists in the cache.
- *
- * @param string $id cache id The cache id of the entry to check for.
- *
- * @return bool TRUE if a cache entry exists for the given cache id,
- * FALSE otherwise.
+ * {@inheritdoc}
*/
public function contains($id)
{
@@ -34,11 +30,7 @@ public function contains($id)
}
/**
- * Deletes a cache entry.
- *
- * @param string $id cache id
- *
- * @return bool TRUE on success, FALSE on failure
+ * {@inheritdoc}
*/
public function delete($id)
{
@@ -46,12 +38,7 @@ public function delete($id)
}
/**
- * Fetches an entry from the cache.
- *
- * @param string $id cache id The id of the cache entry to fetch.
- *
- * @return string The cached data or FALSE, if no cache entry exists for
- * the given id.
+ * {@inheritdoc}
*/
public function fetch($id)
{
@@ -59,15 +46,7 @@ public function fetch($id)
}
/**
- * Puts data into the cache.
- *
- * @param string $id The cache id.
- * @param string $data The cache entry/data.
- * @param int $lifeTime The lifetime. If != false, sets a specific lifetime
- * for this cache entry (null => infinite lifeTime).
- *
- * @return bool TRUE if the entry was successfully stored in the cache,
- * FALSE otherwise.
+ * {@inheritdoc}
*/
public function save($id, $data, $lifeTime = false)
{
View
15 src/Guzzle/Common/Collection.php
@@ -4,8 +4,6 @@
/**
* Key value pair collection object
- *
- * @author Michael Dowling <michael@guzzlephp.org>
*/
class Collection implements \ArrayAccess, \IteratorAggregate, \Countable
{
@@ -16,7 +14,7 @@ class Collection implements \ArrayAccess, \IteratorAggregate, \Countable
/**
* @var array Data associated with the object.
*/
- protected $data = array();
+ protected $data;
/**
* Constructor
@@ -25,9 +23,7 @@ class Collection implements \ArrayAccess, \IteratorAggregate, \Countable
*/
public function __construct(array $data = null)
{
- if ($data) {
- $this->data = $data;
- }
+ $this->data = $data ?: array();
}
/**
@@ -291,8 +287,8 @@ public function hasValue($value)
*/
public function map(\Closure $closure, array $context = array(), $static = true)
{
- $collection = ($static) ? new static() : new self();
- foreach ($this->getIterator() as $key => $value) {
+ $collection = $static ? new static() : new self();
+ foreach ($this as $key => $value) {
$collection->add($key, $closure($key, $value, $context));
}
@@ -383,8 +379,7 @@ public function offsetUnset($offset)
public function remove($key, $match = self::MATCH_EXACT)
{
foreach ((array) $key as $k) {
- $matched = $this->hasKey($k, $match);
- if ($matched !== false) {
+ if (false !== $matched = $this->hasKey($k, $match)) {
unset($this->data[$matched]);
}
}
View
66 src/Guzzle/Common/Event.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace Guzzle\Common;
+
+use Symfony\Component\EventDispatcher\Event as SymfonyEvent;
+
+/**
+ * Default event for Guzzle notifications
+ */
+class Event extends SymfonyEvent implements \ArrayAccess, \IteratorAggregate
+{
+ /**
+ * @var array
+ */
+ private $context;
+
+ /**
+ * Constructor
+ *
+ * @param array $context Contextual information
+ */
+ public function __construct(array $context = array())
+ {
+ $this->context = $context;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getIterator()
+ {
+ return new \ArrayIterator($this->context);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function offsetGet($offset)
+ {
+ return array_key_exists($offset, $this->context) ? $this->context[$offset] : null;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function offsetSet($offset, $value)
+ {
+ $this->context[$offset] = $value;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function offsetExists($offset)
+ {
+ return array_key_exists($offset, $this->context);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function offsetUnset($offset)
+ {
+ unset($this->context[$offset]);
+ }
+}
View
30 src/Guzzle/Common/Event/AbstractSubject.php
@@ -1,30 +0,0 @@
-<?php
-
-namespace Guzzle\Common\Event;
-
-/**
- * Abstract subject class
- *
- * @author Michael Dowling <michael@guzzlephp.org>
- */
-abstract class AbstractSubject implements Subject
-{
- /**
- * @var EventManager
- */
- protected $eventManager;
-
- /**
- * Get the subject mediator associated with the subject
- *
- * @return EventManager
- */
- public function getEventManager()
- {
- if (!$this->eventManager) {
- $this->eventManager = new EventManager($this);
- }
-
- return $this->eventManager;
- }
-}
View
234 src/Guzzle/Common/Event/EventManager.php
@@ -1,234 +0,0 @@
-<?php
-
-namespace Guzzle\Common\Event;
-
-/**
- * Connects {@see Subject} objects and {@see Observer} objects by emitting
- * signals from the subject to the observer. Contextual information can be
- * sent to observers to give more context on how to react to a signal.
- *
- * @author Michael Dowling <michael@guzzlephp.org>
- */
-class EventManager
-{
- /**
- * @var Subject Mediated {@see Subject} to connect with {@see Observer}s
- */
- protected $subject;
-
- /**
- * @var array Array of {@see Observer} objects.
- */
- protected $observers = array();
-
- /**
- * @var array Array of observer priorities
- */
- protected $priorities = array();
-
- /**
- * Construct a new EventManager
- *
- * @param Subject Subject colleague object
- */
- public function __construct(Subject $subject)
- {
- $this->subject = $subject;
- }
-
- /**
- * Attach a new observer.
- *
- * @param Observer|Closure $observer Object that observes the subject.
- * @param int $priority (optional) Priority to attach to the subject. The
- * higher the priority, the sooner it will be notified
- *
- * @return Observer|Closure Returns the $observer that was attached
- * @throws InvalidArgumentException if the observer is not a Closure or Observer
- */
- public function attach($observer, $priority = 0)
- {
- if (!($observer instanceof \Closure) && !($observer instanceof Observer)) {
- throw new \InvalidArgumentException(
- 'Observer must be a Closure or Observer object'
- );
- }
-
- if (!$this->hasObserver($observer)) {
- $hash = spl_object_hash($observer);
- $this->observers[$hash] = $observer;
- $this->priorities[$hash] = $priority;
- $priorities = $this->priorities;
- // Sort the events by priority
- uasort($this->observers, function($a, $b) use ($priorities) {
- $priority1 = $priorities[spl_object_hash($a)];
- $priority2 = $priorities[spl_object_hash($b)];
- if ($priority1 === $priority2) {
- return 0;
- } else if ($priority1 > $priority2) {
- return -1;
- } else {
- return 1;
- }
- });
- // Notify the observer that it is being attached to the subject
- $this->notifyObserver($observer, 'event.attach');
- }
-
- return $observer;
- }
-
- /**
- * Detach an observer.
- *
- * @param Observer|Closure $observer Observer to detach.
- *
- * @return Observer Returns the $observer that was detached.
- */
- public function detach($observer)
- {
- if (is_object($observer)) {
- $hash = spl_object_hash($observer);
- if (isset($this->observers[$hash])) {
- // Notify the observer that it is being detached
- $this->notifyObserver($observer, 'event.detach');
- unset($this->priorities[$hash]);
- unset($this->observers[$hash]);
- }
- }
-
- return $observer;
- }
-
- /**
- * Detach all observers.
- *
- * @return array Returns an array of the detached observers
- */
- public function detachAll()
- {
- $detached = array_values($this->observers);
- foreach ($detached as $o) {
- $this->detach($o);
- }
-
- return $detached;
- }
-
- /**
- * Notify all observers of an event
- *
- * @param string $event (optional) Event signal to emit
- * @param mixed $context (optional) Context of the event
- * @param bool $until (optional) Set to TRUE to stop event propagation when
- * one of the observers returns TRUE
- *
- * @return array Returns an array containing the response of each observer
- */
- public function notify($event, $context = null, $until = false)
- {
- $responses = array();
-
- foreach ($this->observers as $observer) {
- $result = $this->notifyObserver($observer, $event, $context);
- if ($result) {
- $responses[] = $result;
- if ($until == true) {
- break;
- }
- }
- }
-
- return $responses;
- }
-
- /**
- * Get all attached observers.
- *
- * @param string $byName (optional) Pass the name of a class to retrieve
- * only observers that are an instance of a particular class.
- *
- * @return array Returns an array containing the matching observers. The
- * returned array may or may not be empty.
- */
- public function getAttached($byName = null)
- {
- if (!$byName) {
- return array_values($this->observers);
- }
-
- return array_values(array_filter($this->observers, function($o) use ($byName) {
- return $o instanceof $byName;
- }));
- }
-
- /**
- * Get the mediated {@see Subject} or NULL if no Subject has been associated
- *
- * @return Subject|null
- */
- public function getSubject()
- {
- return $this->subject;
- }
-
- /**
- * Check if a certain observer or type of observer is attached
- *
- * @param string|Observer|Closure $observer Observer to check for. Pass the
- * name of an observer, a concrete {@see Observer}, or Closure
- *
- * @return bool
- */
- public function hasObserver($observer)
- {
- if (is_object($observer)) {
- return isset($this->observers[spl_object_hash($observer)]);
- } else if (is_string($observer)) {
- foreach ($this->observers as $item) {
- if ($item instanceOf $observer) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- /**
- * Get the priority level that an observer was attached at
- *
- * @param object $observer Observer to get the priority level of
- *
- * @return int|null Returns the priortity level or NULl if not attached
- */
- public function getPriority($observer)
- {
- if (is_object($observer)) {
- $hash = spl_object_hash($observer);
- if (array_key_exists($hash, $this->priorities)) {
- return $this->priorities[$hash];
- }
- }
-
- return null;
- }
-
- /**
- * Notify a single observer of an event
- *
- * @param Closure|Observer $observer Observer to notify
- * @param string $event Event signal to send to the observer
- * @param mixed $context (optional) Context about the event
- *
- * @return mixed
- */
- protected function notifyObserver($observer, $event, $context = null)
- {
- if ($observer instanceof Observer) {
- return $observer->update($this->subject, $event, $context);
- } else {
- return $observer($this->subject, $event, $context);
- }
- }
-}
View
22 src/Guzzle/Common/Event/Observer.php
@@ -1,22 +0,0 @@
-<?php
-
-namespace Guzzle\Common\Event;
-
-/**
- * Guzzle Observer class
- *
- * @author Michael Dowling <michael@guzzlephp.org>
- */
-interface Observer
-{
- /**
- * Receive notifications from a EventManager
- *
- * @param Subject $subject Subject emitting the event
- * @param string $event Event signal state
- * @param mixed $context (optional) Contextual information
- *
- * @return null|bool|mixed
- */
- function update(Subject $subject, $event, $context = null);
-}
View
18 src/Guzzle/Common/Event/Subject.php
@@ -1,18 +0,0 @@
-<?php
-
-namespace Guzzle\Common\Event;
-
-/**
- * Guzzle subject interface
- *
- * @author Michael Dowling <michael@guzzlephp.org>
- */
-interface Subject
-{
- /**
- * Get the subject mediator associated with the subject
- *
- * @return EventManager
- */
- function getEventManager();
-}
View
58 src/Guzzle/Common/ExceptionCollection.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Guzzle\Common;
+
+/**
+ * Collection of exceptions
+ */
+class ExceptionCollection extends \Exception implements GuzzleExceptionInterface, \IteratorAggregate, \Countable
+{
+ /**
+ * @var array Array of Exceptions
+ */
+ protected $exceptions = array();
+
+ /**
+ * Add exceptions to the collection
+ *
+ * @param ExceptionCollection|Exception $e Exception to add
+ *
+ * @return ExceptionCollection;
+ */
+ public function add($e)
+ {
+ if ($e instanceof self) {
+ foreach ($e as $exception) {
+ $this->exceptions[] = $exception;
+ }
+ } else if ($e instanceof \Exception) {
+ $this->exceptions[] = $e;
+ }
+
+ $this->message = implode("\n", array_map(function($e) {
+ return $e->getMessage();
+ }, $this->exceptions));
+
+ return $this;
+ }
+
+ /**
+ * Get the total number of request exceptions
+ *
+ * @return int
+ */
+ public function count()
+ {
+ return count($this->exceptions);
+ }
+
+ /**
+ * Allows array-like iteration over the request exceptions
+ *
+ * @return ArrayIterator
+ */
+ public function getIterator()
+ {
+ return new \ArrayIterator($this->exceptions);
+ }
+}
View
77 src/Guzzle/Common/Filter/AbstractFilter.php
@@ -1,77 +0,0 @@
-<?php
-
-namespace Guzzle\Common\Filter;
-
-use Guzzle\Common\Collection;
-use Guzzle\Common\GuzzleException;
-
-/**
- * An intercepting filter.
- *
- * @author michael@guzzlephp.org
- */
-abstract class AbstractFilter extends Collection implements FilterInterface
-{
- /**
- * Create a new filter object.
- *
- * @param array|Collection $parameters (optional) Optional parameters to
- * pass to the filter for processing.
- *
- * @throws GuzzleException if the $parameters argument is not an array or an
- * instance of {@see Collection}
- */
- public function __construct($parameters = null)
- {
- if ($parameters instanceof Collection) {
- $this->data = $parameters->getAll();
- } else {
- parent::__construct($parameters);
- }
-
- $this->init();
- }
-
- /**
- * Process the command object.
- *
- * @param mixed $command Value to process. The command can be any type of
- * variable. It is the responsibility of concrete filters to ensure
- * that the passed command is of the correct type.
- *
- * @return bool Returns TRUE on success or FALSE on failure.
- */
- public function process($command)
- {
- $typeHint = $this->get('type_hint');
- if ($typeHint && !($command instanceof $typeHint)) {
- return false;
- }
-
- return $this->filterCommand($command);
- }
-
- /**
- * Filter the request and handle as needed.
- *
- * This method is a hook to be implemented in subclasses
- *
- * @param mixed $command The object to process
- *
- * @return bool Returns TRUE on success or FALSE on failure
- */
- abstract protected function filterCommand($command);
-
- /**
- * Initialize the filter.
- *
- * This method is a hook to be implemented in subclasses that handles
- * initializing the filter.
- *
- * @return void
- */
- protected function init()
- {
- return;
- }
-}
View
24 src/Guzzle/Common/Filter/ArrayFilter.php
@@ -1,24 +0,0 @@
-<?php
-
-namespace Guzzle\Common\Filter;
-
-/**
- * Check if the supplied variable is an array
- *
- * @author Michael Dowling <michael@guzzlephp.org>
- */
-class ArrayFilter extends AbstractFilter
-{
- /**
- * {@inheritdoc}
- */
- protected function filterCommand($command)
- {
- if (!is_array($command)) {
- return 'The supplied value is not an array: ' . gettype($command)
- . ' supplied';
- }
-
- return true;
- }
-}
View
33 src/Guzzle/Common/Filter/BooleanFilter.php
@@ -1,33 +0,0 @@
-<?php
-
-namespace Guzzle\Common\Filter;
-
-/**
- * Check if the supplied variable is Boolean
- *
- * @author Michael Dowling <michael@guzzlephp.org>
- */
-class BooleanFilter extends AbstractFilter
-{
- /**
- * {@inheritdoc}
- */
- protected function filterCommand($command)
- {
- if (!($command === 1 || $command === 0 || $command === true
- || $command === false || $command === 'true'
- || $command === 'false')) {
-
- if (is_scalar($command)) {
-
- return 'The supplied value is not a Boolean: '
- . (string) $command . ' supplied';
- }
-
- return 'The supplied value is not a Boolean: ' . gettype($command)
- . ' supplied';
- }
-
- return true;
- }
-}
View
40 src/Guzzle/Common/Filter/ClassFilter.php
@@ -1,40 +0,0 @@
-<?php
-
-namespace Guzzle\Common\Filter;
-
-/**
- * Check if the supplied variable is an instance of the supplied class
- *
- * @author Michael Dowling <michael@guzzlephp.org>
- */
-class ClassFilter extends AbstractFilter
-{
- /**
- * {@inheritdoc}
- */
- protected function filterCommand($command)
- {
- if ($this->get(0) && is_string($this->get(0))) {
- $class = $this->get(0);
- $valid = ($command instanceof $class);
- } else {
- $valid = is_object($command);
- $class = 'stdClass';
- }
-
- if (!$valid) {
- $error = 'The supplied value is not an instance of ' . $class
- . ': %s supplied';
-
- if (!is_object($command)) {
- $error = sprintf($error, '<' . gettype($command) . ':' . (string) $command . '>');
- } else {
- $error = sprintf($error, get_class($command));
- }
-
- return $error;
- }
-
- return true;
- }
-}
View
34 src/Guzzle/Common/Filter/ClosureFilter.php
@@ -1,34 +0,0 @@
-<?php
-
-namespace Guzzle\Common\Filter;
-
-/**
- * An implementation of an intercepting filter using a closure as the processing
- * method.
- *
- * @author Michael Dowling <michael@guzzlephp.org>
- */
-class ClosureFilter extends AbstractFilter
-{
- /**
- * @var Closure closure method used to process the command
- */
- private $closure;
-
- /**
- * Create a new closure filter
- */
- public function __construct(\Closure $closure)
- {
- parent::__construct();
- $this->closure = $closure;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function filterCommand($command)
- {
- return call_user_func($this->closure, $command);
- }
-}
View
36 src/Guzzle/Common/Filter/DateFilter.php
@@ -1,36 +0,0 @@
-<?php
-
-namespace Guzzle\Common\Filter;
-
-/**
- * Check if the supplied variable is a Date
- *
- * @author Michael Dowling <michael@guzzlephp.org>
- */
-class DateFilter extends AbstractFilter
-{
- /**
- * {@inheritdoc}
- */
- protected function filterCommand($command)
- {
- if (!is_scalar($command)) {
-
- return 'The supplied value is not a valid date: '
- . gettype($command) . ' supplied';
-
- } else {
-
- $s = strtotime($command);
-
- if (false === $s
- || !checkdate(date('m', $s), date('d', $s), date('Y', $s))) {
-
- return 'The supplied value is not a valid date: '
- . (string) $command . ' supplied';
- }
- }
-
- return true;
- }
-}
View
39 src/Guzzle/Common/Filter/EnumFilter.php
@@ -1,39 +0,0 @@
-<?php
-
-namespace Guzzle\Common\Filter;
-
-/**
- * Check if the supplied variable is in the supplied enumerable list
- *
- * @author Michael Dowling <michael@guzzlephp.org>
- */
-class EnumFilter extends AbstractFilter
-{
- /**
- * {@inheritdoc}
- */
- protected function filterCommand($command)
- {
- $filter = true;
-
- if ($this->get(0)) {
- $list = array_map('trim', explode(',', $this->get(0)));
-
- if (!in_array($command, $list)) {
-
- $error = 'The supplied argument was not found in the list of '
- . 'acceptable values (' . implode(', ', $list)
- . '): %s supplied';
-
- if (is_scalar($command)) {
- $filter = sprintf($error, '<' . gettype($command) . ':'
- . $command . '>');
- } else {
- $filter = sprintf($error, gettype($command));
- }
- }
- }
-
- return $filter;
- }
-}
View
22 src/Guzzle/Common/Filter/FilterInterface.php
@@ -1,22 +0,0 @@
-<?php
-
-namespace Guzzle\Common\Filter;
-
-/**
- * An intercepting filter interface
- *
- * @author Michael Dowling <michael@guzzlephp.org>
- */
-interface FilterInterface
-{
- /**
- * Process the command object.
- *
- * @param mixed $command Value to process. The command can be any type of
- * variable. It is the responsibility of concrete filters to ensure
- * that the passed command is of the correct type.
- *
- * @return bool Returns TRUE on success or FALSE on failure.
- */
- function process($command);
-}
View
25 src/Guzzle/Common/Filter/FloatFilter.php
@@ -1,25 +0,0 @@
-<?php
-
-namespace Guzzle\Common\Filter;
-
-/**
- * Check if the supplied variable is a Float
- *
- * @author Michael Dowling <michael@guzzlephp.org>
- */
-class FloatFilter extends AbstractFilter
-{
- /**
- * {@inheritdoc}
- */
- protected function filterCommand($command)
- {
- if (!is_numeric($command)) {
-
- return 'The supplied value is not a valid float: '
- . gettype($command) . ' supplied';
- }
-
- return true;
- }
-}
View
25 src/Guzzle/Common/Filter/IntegerFilter.php
@@ -1,25 +0,0 @@
-<?php
-
-namespace Guzzle\Common\Filter;
-
-/**
- * Check if the supplied variable is an Integer
- *
- * @author Michael Dowling <michael@guzzlephp.org>
- */
-class IntegerFilter extends AbstractFilter
-{
- /**
- * {@inheritdoc}
- */
- protected function filterCommand($command)
- {
- if (!is_numeric($command) || strpos($command, '.') !== false) {
-
- return 'The supplied value is not a valid integer: '
- . (string) $command . ' supplied';
- }
-
- return true;
- }
-}
View
36 src/Guzzle/Common/Filter/RegexFilter.php
@@ -1,36 +0,0 @@
-<?php
-
-namespace Guzzle\Common\Filter;
-
-/**
- * Check if the supplied variable matches a regular expression
- *
- * @author Michael Dowling <michael@guzzlephp.org>
- */
-class RegexFilter extends AbstractFilter
-{
- /**
- * {@inheritdoc}
- */
- protected function filterCommand($command)
- {
- if (!is_string($command)) {
-
- return 'The supplied argument must be a string to match the '
- . 'RegexFilter: ' . gettype($command) . ' supplied';
- }
-
- $regex = $this->get(0);
- if (!$regex || !is_string($regex)) {
- return true;
- }
-
- if (!preg_match($regex, $command)) {
-
- return 'The supplied argument did not match the regular expression '
- . $regex . ': ' . $command . ' supplied';
- }
-
- return true;
- }
-}
View
25 src/Guzzle/Common/Filter/StringFilter.php
@@ -1,25 +0,0 @@
-<?php
-
-namespace Guzzle\Common\Filter;
-
-/**
- * Check if the supplied variable is a string
- *
- * @author Michael Dowling <michael@guzzlephp.org>
- */
-class StringFilter extends AbstractFilter
-{
- /**
- * {@inheritdoc}
- */
- protected function filterCommand($command)
- {
- if (!is_string($command)) {
-
- return 'The supplied value is not a string: ' . gettype($command)
- . ' supplied';
- }
-
- return true;
- }
-}
View
31 src/Guzzle/Common/Filter/TimestampFilter.php
@@ -1,31 +0,0 @@
-<?php
-
-namespace Guzzle\Common\Filter;
-
-/**
- * Check if the supplied variable is a timestamp
- *
- * @author Michael Dowling <michael@guzzlephp.org>
- */
-class TimestampFilter extends AbstractFilter
-{
- /**
- * {@inheritdoc}
- */
- protected function filterCommand($command)
- {
- $timestamp = is_numeric($command) && $command > 0 ? date('Y-m-d', (int) $command) : false;
-
- if (false === $timestamp) {
- if (is_scalar($command)) {
- return 'The supplied value is not a valid timestamp: '
- . (string) $command . ' supplied';
- } else {
- return 'The supplied value is not a valid timestamp: '
- . gettype($command) . ' supplied';
- }
- }
-
- return true;
- }
-}
View
12 src/Guzzle/Common/GuzzleException.php
@@ -1,12 +0,0 @@
-<?php
-
-namespace Guzzle\Common;
-
-/**
- * Guzzle exception
- *
- * @author Michael Dowling <michael@guzzlephp.org>
- */
-interface GuzzleException
-{
-}
View
10 src/Guzzle/Common/GuzzleExceptionInterface.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Guzzle\Common;
+
+/**
+ * Guzzle exception
+ */
+interface GuzzleExceptionInterface
+{
+}
View
42 src/Guzzle/Common/HasDispatcherInterface.php
@@ -0,0 +1,42 @@
+<?php
+
+namespace Guzzle\Common;
+
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+
+/**
+ * Holds an event dispatcher
+ */
+interface HasDispatcherInterface
+{
+ /**
+ * Get a list of all of the events emitted from the class
+ *
+ * @return array
+ */
+ static function getAllEvents();
+
+ /**
+ * Set the EventDispatcher of the request
+ *
+ * @param EventDispatcherInterface $eventDispatcher
+ *
+ * @return HasDispatcherInterface
+ */
+ function setEventDispatcher(EventDispatcherInterface $eventDispatcher);
+
+ /**
+ * Get the EventDispatcher of the request
+ *
+ * @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());
+}
View
102 src/Guzzle/Common/Inflector.php
@@ -1,102 +0,0 @@
-<?php
-
-namespace Guzzle\Common;
-
-/**
- * Guzzle inflector class to transform snake_case to CamelCase and vice-versa.
- *
- * Previously computed values are cached internally using a capped array. When
- * the cache is filled, the first 10% of the cached array will be removed.
- *
- * @author Michael Dowling <michael@guzzlephp.org>
- */
-class Inflector
-{
- /**
- * @var int Cap each internal cache
- */
- const MAX_ENTRIES_PER_CACHE = 1000;
-
- /**
- * @var array snake_case transformation cache
- */
- protected static $snakeCache = array();
-
- /**
- * @var array CamelCase transformation cache
- */
- protected static $camelCache = array();
-
- /**
- * Converts strings from camel case to snake case
- * (e.g. CamelCase camel_case)
- *
- * Borrowed from Magento
- *
- * @param string $word Word to convert to snake case
- *
- * @return string
- */
- public static function snake($word)
- {
- static $cached = 0;
-
- if (isset(self::$snakeCache[$word])) {
- return self::$snakeCache[$word];
- }
-
- if (strtolower($word) == $word) {
- $result = $word;
- } else {
- $result = strtolower(preg_replace('/(.)([A-Z])/', "$1_$2", $word));
- }
-
- if (++$cached > self::MAX_ENTRIES_PER_CACHE) {
- $toRemove = self::MAX_ENTRIES_PER_CACHE * 0.1;
- self::$snakeCache = array_slice(self::$snakeCache, $toRemove);
- $cached -= $toRemove;
- }
-
- return self::$snakeCache[$word] = $result;
- }
-
- /**
- * Converts strings from snake_case to upper CamelCase
- *
- * @param string $word Value to convert into upper CamelCase
- *
- * @return string
- */
- public static function camel($word)
- {
- static $cached = 0;
-
- if (isset(self::$camelCache[$word])) {
- return self::$camelCache[$word];
- }
-
- $result = str_replace(' ', '', ucwords(strtr($word, '_-', ' ')));
-
- if (++$cached > self::MAX_ENTRIES_PER_CACHE) {
- $toRemove = self::MAX_ENTRIES_PER_CACHE * 0.1;
- self::$camelCache = array_slice(self::$camelCache, $toRemove);
- $cached -= $toRemove;
- }
-
- return self::$camelCache[$word] = $result;
- }
-
- /**
- * Get cache information from the inflector
- *
- * @return array Returns an array containing a snake and camel key, and each
- * value of each cache in a sub-array
- */
- public static function getCache()
- {
- return array(
- 'snake' => self::$snakeCache,
- 'camel' => self::$camelCache
- );
- }
-}
View
0 src/Guzzle/Common/Inspector.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
9 src/Guzzle/Common/Log/AbstractLogAdapter.php
@@ -6,20 +6,13 @@
* Adapter class that allows Guzzle to log dato to various logging
* implementations so that you may use the log classes of your favorite
* framework.
- *
- * @author Michael Dowling <michael@guzzlephp.org>
*/
abstract class AbstractLogAdapter implements LogAdapterInterface
{
- /**
- * @var mixed Concrete wrapped log object
- */
protected $log;
/**
- * Get the wrapped log object
- *
- * @return mixed
+ * {@inheritdoc}
*/
public function getLogObject()
{
View
9 src/Guzzle/Common/Log/ClosureLogAdapter.php
@@ -5,16 +5,11 @@
/**
* Allows Closures to be called when messages are logged. Closures combined
* with filtering can trigger application events based on log messages.
- *
- * @author Michael Dowling <michael@guzzlephp.org>
*/
class ClosureLogAdapter extends AbstractLogAdapter
{
/**
- * Adapt a callable function
- *
- * @param mixed $logObject Log object to adapt
- * @throws InvalidArgumentException if the $logObject is not callable
+ * {@inheritdoc}
*/
public function __construct($logObject)
{
@@ -31,7 +26,5 @@ public function __construct($logObject)
public function log($message, $priority = LOG_INFO, $extras = null)
{
call_user_func($this->log, $message, $priority, $extras);
-
- return $this;
}
}
View
6 src/Guzzle/Common/Log/LogAdapterInterface.php
@@ -3,11 +3,9 @@
namespace Guzzle\Common\Log;
/**
- * Adapter class that allows Guzzle to log dato to various logging
+ * Adapter class that allows Guzzle to log data to various logging
* implementations so that you may use the log classes of your favorite
* framework.
- *
- * @author Michael Dowling <michael@guzzlephp.org>
*/
interface LogAdapterInterface
{
@@ -35,8 +33,6 @@ function getLogObject();
* @param string $message Message to log
* @param integer $priority (optional) Priority of message (use the \LOG_* constants of 0 - 7)
* @param mixed $extras (optional) Extra information to log in event
- *
- * @return LogAdapterInterface
*/
function log($message, $priority = LOG_INFO, $extras = null);
}
View
8 src/Guzzle/Common/Log/MonologLogAdapter.php
@@ -7,16 +7,12 @@
/**
* Monolog log adapter
*
- * @author Michael Dowling <michael@guzzlephp.org>
* @link https://github.com/Seldaek/monolog
*/
class MonologLogAdapter extends AbstractLogAdapter
{
/**
- * Adapt a Monolog Logger object
- *
- * @param Logger $logObject Log object to adapt
- * @throws InvalidArgumentException
+ * {@inheritdoc}
*/
public function __construct($logObject)
{
@@ -35,7 +31,5 @@ public function __construct($logObject)
public function log($message, $priority = LOG_INFO, $extras = null)
{
$this->log->addRecord($priority, $message);
-
- return $this;
}
}
View
19 src/Guzzle/Common/Log/ZendLogAdapter.php
@@ -2,24 +2,21 @@
namespace Guzzle\Common\Log;
+use Zend\Log\Logger;
+
/**
- * Adapts the Zend_Log class to the Guzzle framework
- *
- * @author Michael Dowling <michael@guzzlephp.org>
+ * Adapts a ZF2 Logger object
*/
class ZendLogAdapter extends AbstractLogAdapter
{
/**
- * Adapt a Zend_Log object
- *
- * @param Zend_Log $logObject Log object to adapt
- * @throws InvalidArgumentException
+ * {@inheritdoc}
*/