Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 4c46e7701530f45e7893d03537b05073a3ea639e 1 parent 85dae7d
@mtdowling mtdowling authored
Showing with 6,036 additions and 18,599 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
  98. +51 −23 src/Guzzle/Service/Description/ServiceDescription.php
  99. +56 −113 src/Guzzle/Service/Description/XmlDescriptionBuilder.php
  100. +75 −0 src/Guzzle/Service/Inflector.php
  101. +118 −72 src/Guzzle/{Common → Service}/Inspector.php
  102. +29 −29 src/Guzzle/Service/ResourceIterator.php
  103. +25 −17 src/Guzzle/Service/ResourceIteratorApplyBatched.php
  104. +41 −67 src/Guzzle/Service/ServiceBuilder.php
  105. +57 −0 tests/Guzzle/Tests/Common/AbstractHasDispatcherTest.php
  106. +0 −3  tests/Guzzle/Tests/Common/Cache/CacheAdapterTest.php
  107. +12 −7 tests/Guzzle/Tests/Common/Cache/ZendCacheAdapterTest.php
  108. +0 −3  tests/Guzzle/Tests/Common/CollectionTest.php
  109. +0 −23 tests/Guzzle/Tests/Common/Event/AbstractSubjectTest.php
  110. +0 −236 tests/Guzzle/Tests/Common/Event/EventManagerTest.php
  111. +62 −0 tests/Guzzle/Tests/Common/EventTest.php
  112. +46 −0 tests/Guzzle/Tests/Common/ExceptionCollectionTest.php
  113. +0 −151 tests/Guzzle/Tests/Common/Filter/FilterImpTest.php
  114. +0 −87 tests/Guzzle/Tests/Common/Filter/FilterTest.php
  115. +0 −5 tests/Guzzle/Tests/Common/Log/ClosureLogAdapterTest.php
  116. +0 −3  tests/Guzzle/Tests/Common/Log/MonologLogAdapterTest.php
  117. +4 −5 tests/Guzzle/Tests/Common/Log/ZendLogAdapterTest.php
  118. +0 −45 tests/Guzzle/Tests/Common/Mock/MockFilter.php
  119. +0 −14 tests/Guzzle/Tests/Common/Mock/MockFilterCommand.php
  120. +0 −37 tests/Guzzle/Tests/Common/Mock/MockObserver.php
  121. +0 −10 tests/Guzzle/Tests/Common/Mock/MockSubject.php
  122. +0 −3  tests/Guzzle/Tests/Common/NullObjectTest.php
  123. +6 −57 tests/Guzzle/Tests/Common/StreamTest.php
  124. +0 −4 tests/Guzzle/Tests/Common/XmlElementTest.php
  125. +0 −3  tests/Guzzle/Tests/GuzzleTest.php
  126. +55 −7 tests/Guzzle/Tests/GuzzleTestCase.php
  127. +432 −0 tests/Guzzle/Tests/Http/ClientTest.php
  128. +0 −6 tests/Guzzle/Tests/Http/CookieJar/ArrayCookieJarTest.php
  129. +0 −3  tests/Guzzle/Tests/Http/CookieJar/FileCookieJarTest.php
  130. +0 −3  tests/Guzzle/Tests/Http/CookieTest.php
  131. +6 −7 tests/Guzzle/Tests/Http/Curl/CurlExceptionTest.php
  132. +0 −737 tests/Guzzle/Tests/Http/Curl/CurlFactoryTest.php
  133. +326 −170 tests/Guzzle/Tests/Http/Curl/CurlHandleTest.php
  134. +490 −0 tests/Guzzle/Tests/Http/Curl/CurlMultiTest.php
  135. +1 −2  tests/Guzzle/Tests/Http/EntityBodyTest.php
  136. +91 −7 tests/Guzzle/Tests/Http/Message/AbstractMessageTest.php
  137. +173 −77 tests/Guzzle/Tests/Http/Message/EntityEnclosingRequestTest.php
  138. +0 −3  tests/Guzzle/Tests/Http/Message/ExceptionTest.php
  139. +20 −24 tests/Guzzle/Tests/Http/Message/RequestFactoryTest.php
  140. +115 −73 tests/Guzzle/Tests/Http/Message/RequestTest.php
  141. +4 −6 tests/Guzzle/Tests/Http/Message/ResponseTest.php
  142. +22 −0 tests/Guzzle/Tests/Http/Plugin/BasicAuthPluginTest.php
  143. +64 −73 tests/Guzzle/Tests/Http/Plugin/CachePluginTest.php
  144. +31 −22 tests/Guzzle/Tests/Http/Plugin/CookiePluginTest.php
  145. +18 −17 tests/Guzzle/Tests/Http/Plugin/ExponentialBackoffTest.php
  146. +18 −8 tests/Guzzle/Tests/Http/Plugin/HistoryPluginTest.php
  147. +29 −41 tests/Guzzle/Tests/Http/Plugin/LogPluginTest.php
  148. +34 −25 tests/Guzzle/Tests/Http/Plugin/Md5ValidatorPluginTest.php
  149. +42 −40 tests/Guzzle/Tests/{Service → Http}/Plugin/MockPluginTest.php
  150. +0 −14 tests/Guzzle/Tests/Http/Pool/MockPool.php
  151. +0 −252 tests/Guzzle/Tests/Http/Pool/PoolTest.php
  152. +0 −7 tests/Guzzle/Tests/Http/QueryStringTest.php
  153. +13 −8 tests/Guzzle/Tests/Http/Server.php
  154. +0 −3  tests/Guzzle/Tests/Http/UrlTest.php
  155. +6 −1 tests/Guzzle/Tests/Http/server.js
  156. +11 −0 tests/Guzzle/Tests/Mock/MockMulti.php
  157. +70 −0 tests/Guzzle/Tests/Mock/MockObserver.php
  158. +7 −0 tests/Guzzle/Tests/Mock/MockSubject.php
  159. +9 −354 tests/Guzzle/Tests/Service/ClientTest.php
  160. +1 −5 tests/Guzzle/Tests/Service/Command/AbstractCommandTest.php
  161. +1 −19 tests/Guzzle/Tests/Service/Command/ClosureCommandTest.php
  162. +18 −27 tests/Guzzle/Tests/Service/Command/CommandSetTest.php
  163. +4 −11 tests/Guzzle/Tests/Service/Command/CommandTest.php
  164. +26 −18 tests/Guzzle/Tests/Service/Description/ApiCommandTest.php
  165. +18 −27 tests/Guzzle/Tests/Service/Description/DynamicCommandFactoryTest.php
  166. +29 −0 tests/Guzzle/Tests/Service/Description/JsonDescriptionBuilderTest.php
  167. +92 −13 tests/Guzzle/Tests/Service/Description/ServiceDescriptionTest.php
  168. +11 −79 tests/Guzzle/Tests/Service/Description/XmlDescriptionBuilderTest.php
  169. +3 −14 tests/Guzzle/Tests/{Common → Service}/InflectorTest.php
  170. +99 −65 tests/Guzzle/Tests/{Common → Service}/InspectorTest.php
  171. +0 −16 tests/Guzzle/Tests/Service/Mock/Command/MockCommand.php
  172. +0 −2  tests/Guzzle/Tests/Service/Mock/Command/OtherCommand.php
  173. +0 −2  tests/Guzzle/Tests/Service/Mock/Command/Sub/Sub.php
  174. +1 −3 tests/Guzzle/Tests/Service/Mock/MockClient.php
  175. +17 −0 tests/Guzzle/Tests/Service/Mock/MockInflector.php
  176. +0 −3  tests/Guzzle/Tests/Service/Mock/MockResourceIterator.php
  177. +8 −1 tests/Guzzle/Tests/Service/ResourceIteratorApplyBatchedTest.php
  178. +8 −1 tests/Guzzle/Tests/Service/ResourceIteratorTest.php
  179. +49 −38 tests/Guzzle/Tests/Service/ServiceBuilderTest.php
  180. +12 −0 tests/Guzzle/Tests/TestData/test_service.json
  181. +15 −8 tests/Guzzle/Tests/TestData/test_service.xml
  182. +7 −0 tests/Guzzle/Tests/TestData/test_service2.json
  183. +6 −0 tests/Guzzle/Tests/TestData/test_service2.xml
  184. +13 −14 tests/bootstrap.php
  185. +0 −1  vendor/Doctrine
  186. +0 −1  vendor/Monolog
  187. +0 −1  vendor/Symfony/Component/ClassLoader
  188. +0 −250 vendor/Zend/Cache.php
  189. +0 −266 vendor/Zend/Cache/Backend.php
  190. +0 −355 vendor/Zend/Cache/Backend/Apc.php
  191. +0 −250 vendor/Zend/Cache/Backend/BlackHole.php
  192. +0 −126 vendor/Zend/Cache/Backend/ExtendedInterface.php
  193. +0 −1,006 vendor/Zend/Cache/Backend/File.php
  194. +0 −99 vendor/Zend/Cache/Backend/Interface.php
  195. +0 −484 vendor/Zend/Cache/Backend/Libmemcached.php
  196. +0 −504 vendor/Zend/Cache/Backend/Memcached.php
  197. +0 −679 vendor/Zend/Cache/Backend/Sqlite.php
  198. +0 −559 vendor/Zend/Cache/Backend/Static.php
  199. +0 −413 vendor/Zend/Cache/Backend/Test.php
  200. +0 −536 vendor/Zend/Cache/Backend/TwoLevels.php
  201. +0 −221 vendor/Zend/Cache/Backend/Xcache.php
  202. +0 −317 vendor/Zend/Cache/Backend/ZendPlatform.php
  203. +0 −207 vendor/Zend/Cache/Backend/ZendServer.php
  204. +0 −100 vendor/Zend/Cache/Backend/ZendServer/Disk.php
  205. +0 −100 vendor/Zend/Cache/Backend/ZendServer/ShMem.php
  206. +0 −757 vendor/Zend/Cache/Core.php
  207. +0 −32 vendor/Zend/Cache/Exception.php
  208. +0 −88 vendor/Zend/Cache/Frontend/Capture.php
  209. +0 −259 vendor/Zend/Cache/Frontend/Class.php
  210. +0 −218 vendor/Zend/Cache/Frontend/File.php
  211. +0 −180 vendor/Zend/Cache/Frontend/Function.php
  212. +0 −106 vendor/Zend/Cache/Frontend/Output.php
  213. +0 −402 vendor/Zend/Cache/Frontend/Page.php
  214. +0 −298 vendor/Zend/Cache/Manager.php
  215. +0 −96 vendor/Zend/Exception.php
  216. +0 −583 vendor/Zend/Log.php
  217. +0 −33 vendor/Zend/Log/Exception.php
  218. +0 −38 vendor/Zend/Log/FactoryInterface.php
  219. +0 −60 vendor/Zend/Log/Filter/Abstract.php
  220. +0 −40 vendor/Zend/Log/Filter/Interface.php
  221. +0 −85 vendor/Zend/Log/Filter/Message.php
  222. +0 −101 vendor/Zend/Log/Filter/Priority.php
  223. +0 −77 vendor/Zend/Log/Filter/Suppress.php
  224. +0 −50 vendor/Zend/Log/Formatter/Firebug.php
  225. +0 −41 vendor/Zend/Log/Formatter/Interface.php
  226. +0 −86 vendor/Zend/Log/Formatter/Simple.php
  227. +0 −122 vendor/Zend/Log/Formatter/Xml.php
  228. +0 −138 vendor/Zend/Log/Writer/Abstract.php
  229. +0 −145 vendor/Zend/Log/Writer/Db.php
  230. +0 −204 vendor/Zend/Log/Writer/Firebug.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
- );
- }
-}