├── tests ├── Guzzle │ └── Tests │ │ ├── TestData │ │ ├── FileBody.txt │ │ ├── description │ │ │ ├── bar.json │ │ │ ├── recursive.json │ │ │ ├── baz.json │ │ │ └── foo.json │ │ ├── mock_response │ │ ├── test_service2.json │ │ ├── services │ │ │ ├── json2.json │ │ │ └── json1.json │ │ └── test_service.json │ │ ├── Mock │ │ ├── MockSubject.php │ │ ├── ExceptionMock.php │ │ ├── MockMulti.php │ │ ├── CustomResponseModel.php │ │ ├── ErrorResponseMock.php │ │ └── MockObserver.php │ │ ├── Service │ │ ├── Mock │ │ │ ├── Command │ │ │ │ ├── Sub │ │ │ │ │ └── Sub.php │ │ │ │ ├── OtherCommand.php │ │ │ │ ├── IterableCommand.php │ │ │ │ └── MockCommand.php │ │ │ ├── Model │ │ │ │ └── MockCommandIterator.php │ │ │ └── MockClient.php │ │ ├── Exception │ │ │ ├── ValidationExceptionTest.php │ │ │ └── InconsistentClientTransferExceptionTest.php │ │ ├── Command │ │ │ ├── AbstractCommandTest.php │ │ │ ├── LocationVisitor │ │ │ │ ├── Response │ │ │ │ │ ├── BodyVisitorTest.php │ │ │ │ │ ├── StatusCodeVisitorTest.php │ │ │ │ │ ├── ReasonPhraseVisitorTest.php │ │ │ │ │ └── AbstractResponseVisitorTest.php │ │ │ │ └── Request │ │ │ │ │ ├── ResponseBodyVisitorTest.php │ │ │ │ │ └── PostFieldVisitorTest.php │ │ │ └── Factory │ │ │ │ └── MapFactoryTest.php │ │ ├── Resource │ │ │ ├── CompositeResourceIteratorFactoryTest.php │ │ │ ├── MapResourceIteratorFactoryTest.php │ │ │ └── ResourceIteratorClassFactoryTest.php │ │ └── CachingConfigLoaderTest.php │ │ ├── Plugin │ │ ├── Cache │ │ │ ├── SkipRevalidationTest.php │ │ │ ├── DenyRevalidationTest.php │ │ │ └── DefaultCanCacheStrategyTest.php │ │ ├── Backoff │ │ │ ├── ConstantBackoffStrategyTest.php │ │ │ ├── LinearBackoffStrategyTest.php │ │ │ ├── ExponentialBackoffStrategyTest.php │ │ │ ├── CallbackBackoffStrategyTest.php │ │ │ ├── TruncatedBackoffStrategyTest.php │ │ │ ├── ReasonPhraseBackoffStrategyTest.php │ │ │ └── CurlBackoffStrategyTest.php │ │ └── CurlAuth │ │ │ └── CurlAuthPluginTest.php │ │ ├── Cache │ │ └── NullCacheAdapterTest.php │ │ ├── Parser │ │ ├── Cookie │ │ │ └── CookieParserTest.php │ │ ├── UriTemplate │ │ │ └── PeclUriTemplateTest.php │ │ ├── ParserRegistryTest.php │ │ └── Message │ │ │ └── PeclHttpMessageParserTest.php │ │ ├── Common │ │ ├── VersionTest.php │ │ └── Exception │ │ │ └── BatchTransferExceptionTest.php │ │ ├── Batch │ │ ├── BatchSizeDivisorTest.php │ │ ├── HistoryBatchTest.php │ │ ├── BatchClosureDivisorTest.php │ │ ├── AbstractBatchDecoratorTest.php │ │ ├── FlushingBatchTest.php │ │ ├── NotifyingBatchTest.php │ │ ├── ExceptionBufferingBatchTest.php │ │ └── BatchClosureTransferTest.php │ │ ├── Log │ │ ├── ArrayLogAdapterTest.php │ │ ├── PsrLogAdapterTest.php │ │ ├── ClosureLogAdapterTest.php │ │ └── Zf2LogAdapterTest.php │ │ ├── Iterator │ │ ├── MapIteratorTest.php │ │ ├── FilterIteratorTest.php │ │ ├── AppendIteratorTest.php │ │ └── MethodProxyIteratorTest.php │ │ ├── Http │ │ ├── Exception │ │ │ └── CurlExceptionTest.php │ │ ├── MimetypesTest.php │ │ ├── QueryAggregator │ │ │ ├── PhpAggregatorTest.php │ │ │ ├── CommaAggregatorTest.php │ │ │ └── DuplicateAggregatorTest.php │ │ ├── Message │ │ │ └── Header │ │ │ │ └── HeaderFactoryTest.php │ │ ├── Curl │ │ │ └── CurlVersionTest.php │ │ ├── IoEmittingEntityBodyTest.php │ │ └── AbstractEntityBodyDecoratorTest.php │ │ └── Inflection │ │ └── InflectorTest.php └── bootstrap.php ├── src └── Guzzle │ ├── Http │ ├── Resources │ │ └── cacert.pem.md5 │ ├── Exception │ │ ├── TooManyRedirectsException.php │ │ ├── ClientErrorResponseException.php │ │ ├── CouldNotRewindStreamException.php │ │ ├── HttpException.php │ │ ├── ServerErrorResponseException.php │ │ └── RequestException.php │ ├── Message │ │ ├── Header │ │ │ ├── HeaderFactoryInterface.php │ │ │ └── HeaderFactory.php │ │ └── PostFileInterface.php │ ├── QueryAggregator │ │ ├── CommaAggregator.php │ │ ├── DuplicateAggregator.php │ │ ├── PhpAggregator.php │ │ └── QueryAggregatorInterface.php │ └── composer.json │ ├── Common │ ├── Exception │ │ ├── GuzzleException.php │ │ ├── RuntimeException.php │ │ ├── BadMethodCallException.php │ │ ├── InvalidArgumentException.php │ │ └── UnexpectedValueException.php │ ├── ToArrayInterface.php │ ├── FromConfigInterface.php │ ├── composer.json │ ├── Version.php │ ├── Event.php │ ├── AbstractHasDispatcher.php │ └── HasDispatcherInterface.php │ ├── Service │ ├── Exception │ │ ├── ServiceNotFoundException.php │ │ ├── CommandException.php │ │ ├── ServiceBuilderException.php │ │ ├── DescriptionBuilderException.php │ │ ├── ResponseClassException.php │ │ ├── ValidationException.php │ │ └── InconsistentClientTransferException.php │ ├── Command │ │ ├── Factory │ │ │ ├── FactoryInterface.php │ │ │ ├── MapFactory.php │ │ │ └── AliasFactory.php │ │ ├── ResponseClassInterface.php │ │ ├── ResponseParserInterface.php │ │ ├── RequestSerializerInterface.php │ │ ├── LocationVisitor │ │ │ ├── Request │ │ │ │ ├── ResponseBodyVisitor.php │ │ │ │ ├── PostFieldVisitor.php │ │ │ │ ├── QueryVisitor.php │ │ │ │ ├── PostFileVisitor.php │ │ │ │ └── RequestVisitorInterface.php │ │ │ └── Response │ │ │ │ ├── BodyVisitor.php │ │ │ │ ├── StatusCodeVisitor.php │ │ │ │ ├── ReasonPhraseVisitor.php │ │ │ │ └── AbstractResponseVisitor.php │ │ ├── CreateResponseClassEvent.php │ │ ├── ClosureCommand.php │ │ └── DefaultResponseParser.php │ ├── ConfigLoaderInterface.php │ ├── composer.json │ ├── Resource │ │ ├── ResourceIteratorFactoryInterface.php │ │ ├── MapResourceIteratorFactory.php │ │ └── AbstractResourceIteratorFactory.php │ ├── Description │ │ └── ValidatorInterface.php │ └── CachingConfigLoader.php │ ├── Plugin │ ├── ErrorResponse │ │ ├── Exception │ │ │ └── ErrorResponseException.php │ │ ├── ErrorResponseExceptionInterface.php │ │ └── composer.json │ ├── Cookie │ │ ├── Exception │ │ │ └── InvalidCookieException.php │ │ └── composer.json │ ├── Cache │ │ ├── CacheKeyProviderInterface.php │ │ ├── DenyRevalidation.php │ │ ├── SkipRevalidation.php │ │ ├── CanCacheStrategyInterface.php │ │ ├── composer.json │ │ ├── RevalidationInterface.php │ │ ├── DefaultCanCacheStrategy.php │ │ ├── CacheStorageInterface.php │ │ └── DefaultCacheKeyProvider.php │ ├── Md5 │ │ └── composer.json │ ├── Backoff │ │ ├── ExponentialBackoffStrategy.php │ │ ├── ReasonPhraseBackoffStrategy.php │ │ ├── composer.json │ │ ├── HttpBackoffStrategy.php │ │ ├── ConstantBackoffStrategy.php │ │ ├── LinearBackoffStrategy.php │ │ ├── CurlBackoffStrategy.php │ │ ├── BackoffStrategyInterface.php │ │ ├── TruncatedBackoffStrategy.php │ │ ├── AbstractErrorCodeBackoffStrategy.php │ │ └── CallbackBackoffStrategy.php │ ├── Mock │ │ └── composer.json │ ├── Async │ │ └── composer.json │ ├── History │ │ └── composer.json │ ├── Oauth │ │ └── composer.json │ ├── CurlAuth │ │ ├── composer.json │ │ └── CurlAuthPlugin.php │ ├── Log │ │ └── composer.json │ └── composer.json │ ├── Batch │ ├── BatchTransferInterface.php │ ├── BatchDivisorInterface.php │ ├── BatchInterface.php │ ├── HistoryBatch.php │ ├── composer.json │ ├── BatchSizeDivisor.php │ ├── NotifyingBatch.php │ ├── BatchClosureDivisor.php │ ├── BatchClosureTransfer.php │ ├── ExceptionBufferingBatch.php │ └── FlushingBatch.php │ ├── Log │ ├── AbstractLogAdapter.php │ ├── Zf2LogAdapter.php │ ├── LogAdapterInterface.php │ ├── Zf1LogAdapter.php │ ├── ClosureLogAdapter.php │ ├── ArrayLogAdapter.php │ ├── composer.json │ ├── MonologLogAdapter.php │ └── PsrLogAdapter.php │ ├── Cache │ ├── AbstractCacheAdapter.php │ ├── NullCacheAdapter.php │ ├── composer.json │ ├── DoctrineCacheAdapter.php │ ├── Zf2CacheAdapter.php │ └── Zf1CacheAdapter.php │ ├── Iterator │ ├── AppendIterator.php │ ├── MethodProxyIterator.php │ ├── README.md │ ├── composer.json │ ├── MapIterator.php │ ├── FilterIterator.php │ └── ChunkedIterator.php │ ├── Parser │ ├── composer.json │ ├── UriTemplate │ │ ├── UriTemplateInterface.php │ │ └── PeclUriTemplate.php │ ├── Url │ │ ├── UrlParserInterface.php │ │ └── UrlParser.php │ ├── Message │ │ ├── MessageParserInterface.php │ │ └── PeclHttpMessageParser.php │ └── Cookie │ │ └── CookieParserInterface.php │ ├── Inflection │ ├── InflectorInterface.php │ ├── composer.json │ └── Inflector.php │ └── Stream │ ├── composer.json │ └── StreamRequestFactoryInterface.php ├── .gitignore ├── phing ├── build.properties.dist ├── build.properties.travis └── imports │ ├── metrics.xml │ └── test.xml ├── phar-stub.php ├── LICENSE └── .travis.yml /tests/Guzzle/Tests/TestData/FileBody.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Guzzle/Http/Resources/cacert.pem.md5: -------------------------------------------------------------------------------- 1 | 349ba2d6964db9ca558c9e1daf38e428 2 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/TestData/description/bar.json: -------------------------------------------------------------------------------- 1 | { 2 | "includes": ["foo.json"] 3 | } -------------------------------------------------------------------------------- /tests/Guzzle/Tests/TestData/mock_response: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Content-Length: 0 3 | 4 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/TestData/description/recursive.json: -------------------------------------------------------------------------------- 1 | { 2 | "includes": ["foo.json"] 3 | } -------------------------------------------------------------------------------- /tests/Guzzle/Tests/TestData/description/baz.json: -------------------------------------------------------------------------------- 1 | { 2 | "includes": ["foo.json", "bar.json"] 3 | } -------------------------------------------------------------------------------- /tests/Guzzle/Tests/TestData/test_service2.json: -------------------------------------------------------------------------------- 1 | { 2 | "operations": { 3 | "abstract": { 4 | "uri": "/abstract" 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Mock/MockSubject.php: -------------------------------------------------------------------------------- 1 | multiHandle; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/TestData/services/json2.json: -------------------------------------------------------------------------------- 1 | { 2 | "services": { 3 | "foo": { 4 | "class": "Guzzle\\Tests\\Service\\Mock\\MockClient", 5 | "extends": "abstract", 6 | "params": { 7 | "baz": "bar" 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Cache/CacheKeyProviderInterface.php: -------------------------------------------------------------------------------- 1 | log; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ingore common cruft 2 | .DS_STORE 3 | coverage 4 | .idea 5 | 6 | # Ignore binary files 7 | guzzle.phar 8 | guzzle-min.phar 9 | 10 | # Ignore potentially sensitive phpunit file 11 | phpunit.xml 12 | 13 | # Ignore composer generated files 14 | composer.phar 15 | composer.lock 16 | composer-test.lock 17 | vendor/ 18 | 19 | # Ignore build files 20 | build/ 21 | phing/build.properties 22 | 23 | # Ignore subsplit working directory 24 | .subsplit 25 | -------------------------------------------------------------------------------- /src/Guzzle/Cache/AbstractCacheAdapter.php: -------------------------------------------------------------------------------- 1 | cache; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /phing/build.properties.dist: -------------------------------------------------------------------------------- 1 | # you may need to update this if you're working on a fork. 2 | guzzle.remote=git@github.com:guzzle/guzzle.git 3 | 4 | # github credentials -- only used by GitHub API calls to create subtree repos 5 | github.basicauth=username:password 6 | # for the subtree split and testing 7 | github.org=guzzle 8 | 9 | # your git path 10 | cmd.git=git 11 | 12 | # your composer command 13 | cmd.composer=composer 14 | 15 | # test server start 16 | cmd.testserver=node -------------------------------------------------------------------------------- /phing/build.properties.travis: -------------------------------------------------------------------------------- 1 | # update this if you're working on a fork. 2 | guzzle.remote=git@github.com:guzzle/guzzle.git 3 | 4 | # github credentials -- only used by GitHub API calls to create subtree repos 5 | github.basicauth=username:password 6 | # for the subtree split and testing 7 | github.org=guzzle 8 | 9 | # your git path 10 | cmd.git=/usr/bin/git 11 | 12 | # your composer command 13 | cmd.composer=composer 14 | 15 | # test server start 16 | cmd.testserver="~/.nvm/nvm.sh run v0.6.14" -------------------------------------------------------------------------------- /src/Guzzle/Log/Zf2LogAdapter.php: -------------------------------------------------------------------------------- 1 | log = $logObject; 15 | } 16 | 17 | public function log($message, $priority = LOG_INFO, $extras = array()) 18 | { 19 | $this->log->log($priority, $message, $extras); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Cache/DenyRevalidation.php: -------------------------------------------------------------------------------- 1 | setErrors($errors); 15 | $this->assertEquals($errors, $e->getErrors()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Service/Command/AbstractCommandTest.php: -------------------------------------------------------------------------------- 1 | setDescription(ServiceDescription::factory(__DIR__ . '/../../TestData/test_service.json')); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/TestData/services/json1.json: -------------------------------------------------------------------------------- 1 | { 2 | "includes": [ "json2.json" ], 3 | "services": { 4 | "abstract": { 5 | "access_key": "xyz", 6 | "secret": "abc" 7 | }, 8 | "mock": { 9 | "class": "Guzzle\\Tests\\Service\\Mock\\MockClient", 10 | "extends": "abstract", 11 | "params": { 12 | "username": "foo", 13 | "password": "baz", 14 | "subdomain": "bar" 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Guzzle/Http/Message/Header/HeaderFactoryInterface.php: -------------------------------------------------------------------------------- 1 | assertEquals($items, $e->getCommands()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Guzzle/Iterator/AppendIterator.php: -------------------------------------------------------------------------------- 1 | getArrayIterator()->append($iterator); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Mock/CustomResponseModel.php: -------------------------------------------------------------------------------- 1 | command = $command; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Command/Factory/FactoryInterface.php: -------------------------------------------------------------------------------- 1 | =5.3.2" 9 | }, 10 | "autoload": { 11 | "psr-0": { "Guzzle\\Parser": "" } 12 | }, 13 | "target-dir": "Guzzle/Parser", 14 | "extra": { 15 | "branch-alias": { 16 | "dev-master": "3.7-dev" 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Guzzle/Common/FromConfigInterface.php: -------------------------------------------------------------------------------- 1 | =5.3.2", 9 | "symfony/event-dispatcher": ">=2.1" 10 | }, 11 | "autoload": { 12 | "psr-0": { "Guzzle\\Common": "" } 13 | }, 14 | "target-dir": "Guzzle/Common", 15 | "extra": { 16 | "branch-alias": { 17 | "dev-master": "3.7-dev" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Command/ResponseParserInterface.php: -------------------------------------------------------------------------------- 1 | assertTrue($skip->revalidate(new Request('GET', 'http://foo.com'), new Response(200))); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Guzzle/Batch/BatchDivisorInterface.php: -------------------------------------------------------------------------------- 1 | assertFalse($deny->revalidate(new Request('GET', 'http://foo.com'), new Response(200))); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Guzzle/Log/Zf1LogAdapter.php: -------------------------------------------------------------------------------- 1 | log = $logObject; 17 | Version::warn(__CLASS__ . ' is deprecated'); 18 | } 19 | 20 | public function log($message, $priority = LOG_INFO, $extras = array()) 21 | { 22 | $this->log->log($message, $priority, $extras); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Command/RequestSerializerInterface.php: -------------------------------------------------------------------------------- 1 | setResponseBody($value); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Cache/NullCacheAdapterTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(false, $c->contains('foo')); 16 | $this->assertEquals(true, $c->delete('foo')); 17 | $this->assertEquals(false, $c->fetch('foo')); 18 | $this->assertEquals(true, $c->save('foo', 'bar')); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Guzzle/Http/QueryAggregator/CommaAggregator.php: -------------------------------------------------------------------------------- 1 | isUrlEncoding()) { 15 | return array($query->encodeValue($key) => implode(',', array_map(array($query, 'encodeValue'), $value))); 16 | } else { 17 | return array($key => implode(',', $value)); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Guzzle/Parser/UriTemplate/UriTemplateInterface.php: -------------------------------------------------------------------------------- 1 | registerNamespaces(array( 9 | 'Guzzle' => 'phar://guzzle.phar/src', 10 | 'Symfony\\Component\\EventDispatcher' => 'phar://guzzle.phar/vendor/symfony/event-dispatcher', 11 | 'Doctrine' => 'phar://guzzle.phar/vendor/doctrine/common/lib', 12 | 'Monolog' => 'phar://guzzle.phar/vendor/monolog/monolog/src' 13 | )); 14 | $classLoader->register(); 15 | 16 | __HALT_COMPILER(); 17 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Command/LocationVisitor/Request/PostFieldVisitor.php: -------------------------------------------------------------------------------- 1 | setPostField($param->getWireName(), $this->prepareValue($value, $param)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Command/LocationVisitor/Request/QueryVisitor.php: -------------------------------------------------------------------------------- 1 | getQuery()->set($param->getWireName(), $this->prepareValue($value, $param)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Parser/Cookie/CookieParserTest.php: -------------------------------------------------------------------------------- 1 | parseCookie('foo=baz+bar', null, null, true); 18 | $this->assertEquals(array( 19 | 'foo' => 'baz bar' 20 | ), $result['cookies']); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Common/VersionTest.php: -------------------------------------------------------------------------------- 1 | isUrlEncoding()) { 17 | return array($query->encodeValue($key) => array_map(array($query, 'encodeValue'), $value)); 18 | } else { 19 | return array($key => $value); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Guzzle/Log/ClosureLogAdapter.php: -------------------------------------------------------------------------------- 1 | log = $logObject; 17 | } 18 | 19 | public function log($message, $priority = LOG_INFO, $extras = array()) 20 | { 21 | call_user_func($this->log, $message, $priority, $extras); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Command/LocationVisitor/Response/BodyVisitor.php: -------------------------------------------------------------------------------- 1 | getName()] = $param->filter($response->getBody()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Exception/ValidationException.php: -------------------------------------------------------------------------------- 1 | errors = $errors; 19 | } 20 | 21 | /** 22 | * Get any validation errors 23 | * 24 | * @return array 25 | */ 26 | public function getErrors() 27 | { 28 | return $this->errors; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Guzzle/Inflection/InflectorInterface.php: -------------------------------------------------------------------------------- 1 | assertEquals(3, $d->getSize()); 20 | $d->setSize(2); 21 | $batches = $d->createBatches($queue); 22 | $this->assertEquals(array(array('foo', 'baz'), array('bar')), $batches); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Command/LocationVisitor/Response/StatusCodeVisitor.php: -------------------------------------------------------------------------------- 1 | getName()] = $response->getStatusCode(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/ErrorResponse/ErrorResponseExceptionInterface.php: -------------------------------------------------------------------------------- 1 | getName()] = $response->getReasonPhrase(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Guzzle/Batch/BatchInterface.php: -------------------------------------------------------------------------------- 1 | stopPropagation(); 21 | } 22 | 23 | /** 24 | * Get the created object 25 | * 26 | * @return mixed 27 | */ 28 | public function getResult() 29 | { 30 | return $this['result']; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Guzzle/Inflection/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guzzle/inflection", 3 | "description": "Guzzle inflection component", 4 | "homepage": "http://guzzlephp.org/", 5 | "keywords": ["inflection", "guzzle"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Michael Dowling", 10 | "email": "mtdowling@gmail.com", 11 | "homepage": "https://github.com/mtdowling" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.3.2" 16 | }, 17 | "autoload": { 18 | "psr-0": { "Guzzle\\Inflection": "" } 19 | }, 20 | "target-dir": "Guzzle/Inflection", 21 | "extra": { 22 | "branch-alias": { 23 | "dev-master": "3.7-dev" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Guzzle/Iterator/MethodProxyIterator.php: -------------------------------------------------------------------------------- 1 | getInnerIterator(); 21 | while ($i instanceof \OuterIterator) { 22 | $i = $i->getInnerIterator(); 23 | } 24 | 25 | return call_user_func_array(array($i, $name), $args); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Guzzle/Http/QueryAggregator/PhpAggregator.php: -------------------------------------------------------------------------------- 1 | $v) { 17 | $k = "{$key}[{$k}]"; 18 | if (is_array($v)) { 19 | $ret = array_merge($ret, self::aggregate($k, $v, $query)); 20 | } else { 21 | $ret[$query->encodeValue($k)] = $query->encodeValue($v); 22 | } 23 | } 24 | 25 | return $ret; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Log/ArrayLogAdapterTest.php: -------------------------------------------------------------------------------- 1 | log('test', \LOG_NOTICE, 'localhost'); 13 | $this->assertEquals(array(array('message' => 'test', 'priority' => \LOG_NOTICE, 'extras' => 'localhost')), $adapter->getLogs()); 14 | } 15 | 16 | public function testClearLog() 17 | { 18 | $adapter = new ArrayLogAdapter(); 19 | $adapter->log('test', \LOG_NOTICE, 'localhost'); 20 | $adapter->clearLogs(); 21 | $this->assertEquals(array(), $adapter->getLogs()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Guzzle/Common/Version.php: -------------------------------------------------------------------------------- 1 | pushHandler($handler); 20 | $adapter = new PsrLogAdapter($log); 21 | $adapter->log('test!', LOG_INFO); 22 | $this->assertTrue($handler->hasInfoRecords()); 23 | $this->assertSame($log, $adapter->getLogObject()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Guzzle/Iterator/README.md: -------------------------------------------------------------------------------- 1 | Guzzle Iterator 2 | =============== 3 | 4 | Provides useful Iterators and Iterator decorators 5 | 6 | - ChunkedIterator: Pulls out chunks from an inner iterator and yields the chunks as arrays 7 | - FilterIterator: Used when PHP 5.4's CallbackFilterIterator is not available 8 | - MapIterator: Maps values before yielding 9 | - MethodProxyIterator: Proxies missing method calls to the innermost iterator 10 | 11 | ### Installing via Composer 12 | 13 | ```bash 14 | # Install Composer 15 | curl -sS https://getcomposer.org/installer | php 16 | 17 | # Add Guzzle as a dependency 18 | php composer.phar require guzzle/iterator:~3.0 19 | ``` 20 | 21 | After installing, you need to require Composer's autoloader: 22 | 23 | ```php 24 | require 'vendor/autoload.php'; 25 | ``` 26 | -------------------------------------------------------------------------------- /src/Guzzle/Log/ArrayLogAdapter.php: -------------------------------------------------------------------------------- 1 | logs[] = array('message' => $message, 'priority' => $priority, 'extras' => $extras); 15 | } 16 | 17 | /** 18 | * Get logged entries 19 | * 20 | * @return array 21 | */ 22 | public function getLogs() 23 | { 24 | return $this->logs; 25 | } 26 | 27 | /** 28 | * Clears logged entries 29 | */ 30 | public function clearLogs() 31 | { 32 | $this->logs = array(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Mock/ErrorResponseMock.php: -------------------------------------------------------------------------------- 1 | command = $command; 22 | $this->response = $response; 23 | $this->message = 'Error from ' . $response; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Guzzle/Http/Message/Header/HeaderFactory.php: -------------------------------------------------------------------------------- 1 | 'Guzzle\Http\Message\Header\CacheControl', 15 | 'link' => 'Guzzle\Http\Message\Header\Link', 16 | ); 17 | 18 | public function createHeader($header, $value = null) 19 | { 20 | $lowercase = strtolower($header); 21 | 22 | return isset($this->mapping[$lowercase]) 23 | ? new $this->mapping[$lowercase]($header, $value) 24 | : new Header($header, $value); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Md5/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guzzle/plugin-md5", 3 | "description": "Guzzle MD5 plugins", 4 | "homepage": "http://guzzlephp.org/", 5 | "keywords": ["plugin", "guzzle"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Michael Dowling", 10 | "email": "mtdowling@gmail.com", 11 | "homepage": "https://github.com/mtdowling" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.3.2", 16 | "guzzle/http": "self.version" 17 | }, 18 | "autoload": { 19 | "psr-0": { "Guzzle\\Plugin\\Md5": "" } 20 | }, 21 | "target-dir": "Guzzle/Plugin/Md5", 22 | "extra": { 23 | "branch-alias": { 24 | "dev-master": "3.7-dev" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Command/Factory/MapFactory.php: -------------------------------------------------------------------------------- 1 | map = $map; 17 | } 18 | 19 | public function factory($name, array $args = array()) 20 | { 21 | if (isset($this->map[$name])) { 22 | $class = $this->map[$name]; 23 | 24 | return new $class($args); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Command/LocationVisitor/Response/AbstractResponseVisitor.php: -------------------------------------------------------------------------------- 1 | assertEquals(range(0, 1000, 10), iterator_to_array($i, false)); 19 | } 20 | 21 | /** 22 | * @expectedException \InvalidArgumentException 23 | */ 24 | public function testValidatesCallable() 25 | { 26 | $i = new MapIterator(new \ArrayIterator(), new \stdClass()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Plugin/Backoff/ConstantBackoffStrategyTest.php: -------------------------------------------------------------------------------- 1 | assertFalse($strategy->makesDecision()); 16 | $request = $this->getMock('Guzzle\Http\Message\Request', array(), array(), '', false); 17 | $this->assertEquals(3.5, $strategy->getBackoffPeriod(0, $request)); 18 | $this->assertEquals(3.5, $strategy->getBackoffPeriod(1, $request)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Backoff/ExponentialBackoffStrategy.php: -------------------------------------------------------------------------------- 1 | =5.3.2", 16 | "guzzle/http": "self.version" 17 | }, 18 | "autoload": { 19 | "psr-0": { "Guzzle\\Plugin\\Cookie": "" } 20 | }, 21 | "target-dir": "Guzzle/Plugin/Cookie", 22 | "extra": { 23 | "branch-alias": { 24 | "dev-master": "3.7-dev" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Mock/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guzzle/plugin-mock", 3 | "description": "Guzzle Mock plugin", 4 | "homepage": "http://guzzlephp.org/", 5 | "keywords": ["mock", "plugin", "guzzle"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Michael Dowling", 10 | "email": "mtdowling@gmail.com", 11 | "homepage": "https://github.com/mtdowling" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.3.2", 16 | "guzzle/http": "self.version" 17 | }, 18 | "autoload": { 19 | "psr-0": { "Guzzle\\Plugin\\Mock": "" } 20 | }, 21 | "target-dir": "Guzzle/Plugin/Mock", 22 | "extra": { 23 | "branch-alias": { 24 | "dev-master": "3.7-dev" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Guzzle/Http/QueryAggregator/QueryAggregatorInterface.php: -------------------------------------------------------------------------------- 1 | =5.3.2", 16 | "guzzle/common": ">=2.8.0" 17 | }, 18 | "autoload": { 19 | "psr-0": { "Guzzle\\Iterator": "/" } 20 | }, 21 | "target-dir": "Guzzle/Log", 22 | "extra": { 23 | "branch-alias": { 24 | "dev-master": "3.7-dev" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Async/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guzzle/plugin-async", 3 | "description": "Guzzle async request plugin", 4 | "homepage": "http://guzzlephp.org/", 5 | "keywords": ["plugin", "guzzle"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Michael Dowling", 10 | "email": "mtdowling@gmail.com", 11 | "homepage": "https://github.com/mtdowling" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.3.2", 16 | "guzzle/http": "self.version" 17 | }, 18 | "autoload": { 19 | "psr-0": { "Guzzle\\Plugin\\Async": "" } 20 | }, 21 | "target-dir": "Guzzle/Plugin/Async", 22 | "extra": { 23 | "branch-alias": { 24 | "dev-master": "3.7-dev" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/History/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guzzle/plugin-history", 3 | "description": "Guzzle history plugin", 4 | "homepage": "http://guzzlephp.org/", 5 | "keywords": ["plugin", "guzzle"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Michael Dowling", 10 | "email": "mtdowling@gmail.com", 11 | "homepage": "https://github.com/mtdowling" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.3.2", 16 | "guzzle/http": "self.version" 17 | }, 18 | "autoload": { 19 | "psr-0": { "Guzzle\\Plugin\\History": "" } 20 | }, 21 | "target-dir": "Guzzle/Plugin/History", 22 | "extra": { 23 | "branch-alias": { 24 | "dev-master": "3.7-dev" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Oauth/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guzzle/plugin-oauth", 3 | "description": "Guzzle OAuth plugin", 4 | "homepage": "http://guzzlephp.org/", 5 | "keywords": ["oauth", "plugin", "guzzle"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Michael Dowling", 10 | "email": "mtdowling@gmail.com", 11 | "homepage": "https://github.com/mtdowling" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.3.2", 16 | "guzzle/http": "self.version" 17 | }, 18 | "autoload": { 19 | "psr-0": { "Guzzle\\Plugin\\Oauth": "" } 20 | }, 21 | "target-dir": "Guzzle/Plugin/Oauth", 22 | "extra": { 23 | "branch-alias": { 24 | "dev-master": "3.7-dev" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Iterator/FilterIteratorTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(range(1, 99, 2), iterator_to_array($i, false)); 19 | } 20 | 21 | /** 22 | * @expectedException \InvalidArgumentException 23 | */ 24 | public function testValidatesCallable() 25 | { 26 | $i = new FilterIterator(new \ArrayIterator(), new \stdClass()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Guzzle/Cache/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guzzle/cache", 3 | "description": "Guzzle cache adapter component", 4 | "homepage": "http://guzzlephp.org/", 5 | "keywords": ["cache", "adapter", "zf", "doctrine", "guzzle"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Michael Dowling", 10 | "email": "mtdowling@gmail.com", 11 | "homepage": "https://github.com/mtdowling" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.3.2", 16 | "guzzle/common": "self.version" 17 | }, 18 | "autoload": { 19 | "psr-0": { "Guzzle\\Cache": "" } 20 | }, 21 | "target-dir": "Guzzle/Cache", 22 | "extra": { 23 | "branch-alias": { 24 | "dev-master": "3.7-dev" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Guzzle/Log/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guzzle/log", 3 | "description": "Guzzle log adapter component", 4 | "homepage": "http://guzzlephp.org/", 5 | "keywords": ["log", "adapter", "guzzle"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Michael Dowling", 10 | "email": "mtdowling@gmail.com", 11 | "homepage": "https://github.com/mtdowling" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.3.2" 16 | }, 17 | "autoload": { 18 | "psr-0": { "Guzzle\\Log": "" } 19 | }, 20 | "suggest": { 21 | "guzzle/http": "self.version" 22 | }, 23 | "target-dir": "Guzzle/Log", 24 | "extra": { 25 | "branch-alias": { 26 | "dev-master": "3.7-dev" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Cache/CanCacheStrategyInterface.php: -------------------------------------------------------------------------------- 1 | 'body', 'name' => 'foo')); 18 | $visitor->visit($this->command, $this->response, $param, $this->value); 19 | $this->assertEquals('Foo', (string) $this->value['foo']); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/CurlAuth/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guzzle/plugin-curlauth", 3 | "description": "Guzzle cURL authorization plugin", 4 | "homepage": "http://guzzlephp.org/", 5 | "keywords": ["plugin", "curl", "guzzle"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Michael Dowling", 10 | "email": "mtdowling@gmail.com", 11 | "homepage": "https://github.com/mtdowling" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.3.2", 16 | "guzzle/http": "self.version" 17 | }, 18 | "autoload": { 19 | "psr-0": { "Guzzle\\Plugin\\CurlAuth": "" } 20 | }, 21 | "target-dir": "Guzzle/Plugin/CurlAuth", 22 | "extra": { 23 | "branch-alias": { 24 | "dev-master": "3.7-dev" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Iterator/AppendIteratorTest.php: -------------------------------------------------------------------------------- 1 | 1, 16 | 'b' => 2 17 | )); 18 | $b = new \ArrayIterator(array()); 19 | $c = new \ArrayIterator(array( 20 | 'c' => 3, 21 | 'd' => 4 22 | )); 23 | $i = new AppendIterator(); 24 | $i->append($a); 25 | $i->append($b); 26 | $i->append($c); 27 | $this->assertEquals(array(1, 2, 3, 4), iterator_to_array($i, false)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Guzzle/Parser/UriTemplate/PeclUriTemplate.php: -------------------------------------------------------------------------------- 1 | errorCodes[$response->getReasonPhrase()]) ? true : null; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Guzzle/Parser/Message/MessageParserInterface.php: -------------------------------------------------------------------------------- 1 | =5.3.2", 16 | "guzzle/http": "self.version", 17 | "guzzle/cache": "self.version" 18 | }, 19 | "autoload": { 20 | "psr-0": { "Guzzle\\Plugin\\Cache": "" } 21 | }, 22 | "target-dir": "Guzzle/Plugin/Cache", 23 | "extra": { 24 | "branch-alias": { 25 | "dev-master": "3.7-dev" 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Batch/HistoryBatchTest.php: -------------------------------------------------------------------------------- 1 | getMock('Guzzle\Batch\BatchTransferInterface'), 17 | $this->getMock('Guzzle\Batch\BatchDivisorInterface') 18 | ); 19 | 20 | $history = new HistoryBatch($batch); 21 | $history->add('foo')->add('baz'); 22 | $this->assertEquals(array('foo', 'baz'), $history->getHistory()); 23 | $history->clearHistory(); 24 | $this->assertEquals(array(), $history->getHistory()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Plugin/Backoff/LinearBackoffStrategyTest.php: -------------------------------------------------------------------------------- 1 | assertFalse($strategy->makesDecision()); 16 | $request = $this->getMock('Guzzle\Http\Message\Request', array(), array(), '', false); 17 | $this->assertEquals(0, $strategy->getBackoffPeriod(0, $request)); 18 | $this->assertEquals(5, $strategy->getBackoffPeriod(1, $request)); 19 | $this->assertEquals(10, $strategy->getBackoffPeriod(2, $request)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/ResponseBodyVisitorTest.php: -------------------------------------------------------------------------------- 1 | getNestedCommand('response_body')->getParam('foo'); 16 | $visitor->visit($this->command, $this->request, $param, sys_get_temp_dir() . '/foo.txt'); 17 | $body = $this->readAttribute($this->request, 'responseBody'); 18 | $this->assertContains('/foo.txt', $body->getUri()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/StatusCodeVisitorTest.php: -------------------------------------------------------------------------------- 1 | 'statusCode', 'name' => 'code')); 18 | $visitor->visit($this->command, $this->response, $param, $this->value); 19 | $this->assertEquals(200, $this->value['code']); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Backoff/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guzzle/plugin-backoff", 3 | "description": "Guzzle backoff retry plugins", 4 | "homepage": "http://guzzlephp.org/", 5 | "keywords": ["plugin", "guzzle"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Michael Dowling", 10 | "email": "mtdowling@gmail.com", 11 | "homepage": "https://github.com/mtdowling" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.3.2", 16 | "guzzle/http": "self.version", 17 | "guzzle/log": "self.version" 18 | }, 19 | "autoload": { 20 | "psr-0": { "Guzzle\\Plugin\\Backoff": "" } 21 | }, 22 | "target-dir": "Guzzle/Plugin/Backoff", 23 | "extra": { 24 | "branch-alias": { 25 | "dev-master": "3.7-dev" 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Command/LocationVisitor/Request/PostFileVisitor.php: -------------------------------------------------------------------------------- 1 | filter($value); 18 | if ($value instanceof PostFileInterface) { 19 | $request->addPostFile($value); 20 | } else { 21 | $request->addPostFile($param->getWireName(), $value); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Parser/UriTemplate/PeclUriTemplateTest.php: -------------------------------------------------------------------------------- 1 | markTestSkipped('uri_template PECL extension must be installed to test PeclUriTemplate'); 16 | } 17 | } 18 | 19 | /** 20 | * @dataProvider templateProvider 21 | */ 22 | public function testExpandsUriTemplates($template, $expansion, $params) 23 | { 24 | $uri = new PeclUriTemplate($template); 25 | $this->assertEquals($expansion, $uri->expand($template, $params)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Log/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guzzle/plugin-log", 3 | "description": "Guzzle log plugin for over the wire logging", 4 | "homepage": "http://guzzlephp.org/", 5 | "keywords": ["plugin", "log", "guzzle"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Michael Dowling", 10 | "email": "mtdowling@gmail.com", 11 | "homepage": "https://github.com/mtdowling" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.3.2", 16 | "guzzle/http": "self.version", 17 | "guzzle/log": "self.version" 18 | }, 19 | "autoload": { 20 | "psr-0": { "Guzzle\\Plugin\\Log": "" } 21 | }, 22 | "target-dir": "Guzzle/Plugin/Log", 23 | "extra": { 24 | "branch-alias": { 25 | "dev-master": "3.7-dev" 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/ReasonPhraseVisitorTest.php: -------------------------------------------------------------------------------- 1 | 'reasonPhrase', 'name' => 'phrase')); 18 | $visitor->visit($this->command, $this->response, $param, $this->value); 19 | $this->assertEquals('OK', $this->value['phrase']); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Guzzle/Log/MonologLogAdapter.php: -------------------------------------------------------------------------------- 1 | Logger::DEBUG, 18 | LOG_INFO => Logger::INFO, 19 | LOG_WARNING => Logger::WARNING, 20 | LOG_ERR => Logger::ERROR, 21 | LOG_CRIT => Logger::CRITICAL, 22 | LOG_ALERT => Logger::ALERT 23 | ); 24 | 25 | public function __construct(Logger $logObject) 26 | { 27 | $this->log = $logObject; 28 | } 29 | 30 | public function log($message, $priority = LOG_INFO, $extras = array()) 31 | { 32 | $this->log->addRecord(self::$mapping[$priority], $message); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/ErrorResponse/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guzzle/plugin-error-response", 3 | "description": "Guzzle errorResponse plugin for creating error exceptions based on a service description", 4 | "homepage": "http://guzzlephp.org/", 5 | "keywords": ["plugin", "guzzle"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Michael Dowling", 10 | "email": "mtdowling@gmail.com", 11 | "homepage": "https://github.com/mtdowling" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.3.2", 16 | "guzzle/service": "self.version" 17 | }, 18 | "autoload": { 19 | "psr-0": { "Guzzle\\Plugin\\ErrorResponse": "" } 20 | }, 21 | "target-dir": "Guzzle/Plugin/ErrorResponse", 22 | "extra": { 23 | "branch-alias": { 24 | "dev-master": "3.7-dev" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/AbstractResponseVisitorTest.php: -------------------------------------------------------------------------------- 1 | value = array(); 22 | $this->command = new MockCommand(); 23 | $this->response = new Response(200, array( 24 | 'X-Foo' => 'bar', 25 | 'Content-Length' => 3, 26 | 'Content-Type' => 'text/plain' 27 | ), 'Foo'); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Guzzle/Stream/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guzzle/stream", 3 | "description": "Guzzle stream wrapper component", 4 | "homepage": "http://guzzlephp.org/", 5 | "keywords": ["stream", "component", "guzzle"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Michael Dowling", 10 | "email": "mtdowling@gmail.com", 11 | "homepage": "https://github.com/mtdowling" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.3.2", 16 | "guzzle/common": "self.version" 17 | }, 18 | "suggest": { 19 | "guzzle/http": "To convert Guzzle request objects to PHP streams" 20 | }, 21 | "autoload": { 22 | "psr-0": { "Guzzle\\Stream": "" } 23 | }, 24 | "target-dir": "Guzzle/Stream", 25 | "extra": { 26 | "branch-alias": { 27 | "dev-master": "3.7-dev" 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Http/Exception/CurlExceptionTest.php: -------------------------------------------------------------------------------- 1 | assertNull($e->getError()); 17 | $this->assertNull($e->getErrorNo()); 18 | $this->assertSame($e, $e->setError('test', 12)); 19 | $this->assertEquals('test', $e->getError()); 20 | $this->assertEquals(12, $e->getErrorNo()); 21 | 22 | $handle = new CurlHandle(curl_init(), array()); 23 | $e->setCurlHandle($handle); 24 | $this->assertSame($handle, $e->getCurlHandle()); 25 | $handle->close(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Guzzle/Service/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guzzle/service", 3 | "description": "Guzzle service component for abstracting RESTful web services", 4 | "homepage": "http://guzzlephp.org/", 5 | "keywords": ["web service", "webservice", "REST", "guzzle"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Michael Dowling", 10 | "email": "mtdowling@gmail.com", 11 | "homepage": "https://github.com/mtdowling" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.3.2", 16 | "guzzle/cache": "self.version", 17 | "guzzle/http": "self.version", 18 | "guzzle/inflection": "self.version" 19 | }, 20 | "autoload": { 21 | "psr-0": { "Guzzle\\Service": "" } 22 | }, 23 | "target-dir": "Guzzle/Service", 24 | "extra": { 25 | "branch-alias": { 26 | "dev-master": "3.7-dev" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Http/MimetypesTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('text/x-php', Mimetypes::getInstance()->fromExtension('php')); 15 | } 16 | 17 | public function testGetsFromFilename() 18 | { 19 | $this->assertEquals('text/x-php', Mimetypes::getInstance()->fromFilename(__FILE__)); 20 | } 21 | 22 | public function testGetsFromCaseInsensitiveFilename() 23 | { 24 | $this->assertEquals('text/x-php', Mimetypes::getInstance()->fromFilename(strtoupper(__FILE__))); 25 | } 26 | 27 | public function testReturnsNullWhenNoMatchFound() 28 | { 29 | $this->assertNull(Mimetypes::getInstance()->fromExtension('foobar')); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Guzzle/Batch/HistoryBatch.php: -------------------------------------------------------------------------------- 1 | history[] = $item; 17 | $this->decoratedBatch->add($item); 18 | 19 | return $this; 20 | } 21 | 22 | /** 23 | * Get the batch history 24 | * 25 | * @return array 26 | */ 27 | public function getHistory() 28 | { 29 | return $this->history; 30 | } 31 | 32 | /** 33 | * Clear the batch history 34 | */ 35 | public function clearHistory() 36 | { 37 | $this->history = array(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Http/QueryAggregator/PhpAggregatorTest.php: -------------------------------------------------------------------------------- 1 | useUrlEncoding(false); 14 | $a = new Ag(); 15 | $key = 't'; 16 | $value = array( 17 | 'v1' => 'a', 18 | 'v2' => 'b', 19 | 'v3' => array( 20 | 'v4' => 'c', 21 | 'v5' => 'd', 22 | ) 23 | ); 24 | $result = $a->aggregate($key, $value, $query); 25 | $this->assertEquals(array( 26 | 't[v1]' => 'a', 27 | 't[v2]' => 'b', 28 | 't[v3][v4]' => 'c', 29 | 't[v3][v5]' => 'd', 30 | ), $result); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | =5.3.2", 16 | "guzzle/common": "self.version", 17 | "guzzle/parser": "self.version", 18 | "guzzle/stream": "self.version" 19 | }, 20 | "suggest": { 21 | "ext-curl": "*" 22 | }, 23 | "autoload": { 24 | "psr-0": { "Guzzle\\Http": "" } 25 | }, 26 | "target-dir": "Guzzle/Http", 27 | "extra": { 28 | "branch-alias": { 29 | "dev-master": "3.7-dev" 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Guzzle/Batch/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "guzzle/batch", 3 | "description": "Guzzle batch component for batching requests, commands, or custom transfers", 4 | "homepage": "http://guzzlephp.org/", 5 | "keywords": ["batch", "HTTP", "REST", "guzzle"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Michael Dowling", 10 | "email": "mtdowling@gmail.com", 11 | "homepage": "https://github.com/mtdowling" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.3.2", 16 | "guzzle/common": "self.version" 17 | }, 18 | "autoload": { 19 | "psr-0": { "Guzzle\\Batch": "" } 20 | }, 21 | "suggest": { 22 | "guzzle/http": "self.version", 23 | "guzzle/service": "self.version" 24 | }, 25 | "target-dir": "Guzzle/Batch", 26 | "extra": { 27 | "branch-alias": { 28 | "dev-master": "3.7-dev" 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Service/Mock/Command/OtherCommand.php: -------------------------------------------------------------------------------- 1 | 'other_command', 13 | 'parameters' => array( 14 | 'test' => array( 15 | 'default' => '123', 16 | 'required' => true, 17 | 'doc' => 'Test argument' 18 | ), 19 | 'other' => array(), 20 | 'arg' => array('type' => 'string'), 21 | 'static' => array('static' => true, 'default' => 'this is static') 22 | ) 23 | )); 24 | } 25 | 26 | protected function build() 27 | { 28 | $this->request = $this->client->getRequest('HEAD'); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Resource/ResourceIteratorFactoryInterface.php: -------------------------------------------------------------------------------- 1 | adapter = new ClosureLogAdapter(function($message, $priority, $extras = null) use ($that, &$modified) { 17 | $modified = array($message, $priority, $extras); 18 | }); 19 | $this->adapter->log('test', LOG_NOTICE, 'localhost'); 20 | $this->assertEquals(array('test', LOG_NOTICE, 'localhost'), $modified); 21 | } 22 | 23 | /** 24 | * @expectedException InvalidArgumentException 25 | */ 26 | public function testThrowsExceptionWhenNotCallable() 27 | { 28 | $this->adapter = new ClosureLogAdapter(123); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Guzzle/Http/Exception/RequestException.php: -------------------------------------------------------------------------------- 1 | request = $request; 26 | 27 | return $this; 28 | } 29 | 30 | /** 31 | * Get the request that caused the exception 32 | * 33 | * @return RequestInterface 34 | */ 35 | public function getRequest() 36 | { 37 | return $this->request; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Parser/ParserRegistryTest.php: -------------------------------------------------------------------------------- 1 | registerParser('foo', $c); 17 | $this->assertSame($c, $r->getParser('foo')); 18 | } 19 | 20 | public function testReturnsNullWhenNotFound() 21 | { 22 | $r = new ParserRegistry(); 23 | $this->assertNull($r->getParser('FOO')); 24 | } 25 | 26 | public function testReturnsLazyLoadedDefault() 27 | { 28 | $r = new ParserRegistry(); 29 | $c = $r->getParser('cookie'); 30 | $this->assertInstanceOf('Guzzle\Parser\Cookie\CookieParser', $c); 31 | $this->assertSame($c, $r->getParser('cookie')); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Guzzle/Stream/StreamRequestFactoryInterface.php: -------------------------------------------------------------------------------- 1 | getMock('Guzzle\Batch\BatchTransferInterface'); 13 | $d = $this->getMock('Guzzle\Batch\BatchDivisorInterface'); 14 | $transferException = new BatchTransferException(array('foo'), array(1, 2), $e, $t, $d); 15 | $this->assertEquals(array('foo'), $transferException->getBatch()); 16 | $this->assertSame($t, $transferException->getTransferStrategy()); 17 | $this->assertSame($d, $transferException->getDivisorStrategy()); 18 | $this->assertSame($e, $transferException->getPrevious()); 19 | $this->assertEquals(array(1, 2), $transferException->getTransferredItems()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Guzzle/Iterator/MapIterator.php: -------------------------------------------------------------------------------- 1 | callback = $callback; 28 | } 29 | 30 | public function current() 31 | { 32 | return call_user_func($this->callback, parent::current()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Cache/RevalidationInterface.php: -------------------------------------------------------------------------------- 1 | 'iterable_command', 13 | 'parameters' => array( 14 | 'page_size' => array('type' => 'integer'), 15 | 'next_token' => array('type' => 'string') 16 | ) 17 | )); 18 | } 19 | 20 | protected function build() 21 | { 22 | $this->request = $this->client->createRequest('GET'); 23 | 24 | // Add the next token and page size query string values 25 | $this->request->getQuery()->set('next_token', $this->get('next_token')); 26 | 27 | if ($this->get('page_size')) { 28 | $this->request->getQuery()->set('page_size', $this->get('page_size')); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Iterator/MethodProxyIteratorTest.php: -------------------------------------------------------------------------------- 1 | append('a'); 18 | $proxy->append('b'); 19 | $this->assertEquals(array('a', 'b'), $i->getArrayCopy()); 20 | $this->assertEquals(array('a', 'b'), $proxy->getArrayCopy()); 21 | } 22 | 23 | public function testUsesInnerIterator() 24 | { 25 | $i = new MethodProxyIterator(new ChunkedIterator(new \ArrayIterator(array(1, 2, 3, 4, 5)), 2)); 26 | $this->assertEquals(3, count(iterator_to_array($i, false))); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Guzzle/Inflection/Inflector.php: -------------------------------------------------------------------------------- 1 | LogLevel::DEBUG, 20 | LOG_INFO => LogLevel::INFO, 21 | LOG_WARNING => LogLevel::WARNING, 22 | LOG_ERR => LogLevel::ERROR, 23 | LOG_CRIT => LogLevel::CRITICAL, 24 | LOG_ALERT => LogLevel::ALERT 25 | ); 26 | 27 | public function __construct(LoggerInterface $logObject) 28 | { 29 | $this->log = $logObject; 30 | } 31 | 32 | public function log($message, $priority = LOG_INFO, $extras = array()) 33 | { 34 | $this->log->log(self::$mapping[$priority], $message, $extras); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Http/QueryAggregator/CommaAggregatorTest.php: -------------------------------------------------------------------------------- 1 | aggregate($key, $value, $query); 17 | $this->assertEquals(array('test%20123' => 'foo%20123,baz,bar'), $result); 18 | } 19 | 20 | public function testEncodes() 21 | { 22 | $query = new QueryString(); 23 | $query->useUrlEncoding(false); 24 | $a = new Ag(); 25 | $key = 'test 123'; 26 | $value = array('foo 123', 'baz', 'bar'); 27 | $result = $a->aggregate($key, $value, $query); 28 | $this->assertEquals(array('test 123' => 'foo 123,baz,bar'), $result); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Plugin/Backoff/ExponentialBackoffStrategyTest.php: -------------------------------------------------------------------------------- 1 | assertFalse($strategy->makesDecision()); 16 | $request = $this->getMock('Guzzle\Http\Message\Request', array(), array(), '', false); 17 | $this->assertEquals(1, $strategy->getBackoffPeriod(0, $request)); 18 | $this->assertEquals(2, $strategy->getBackoffPeriod(1, $request)); 19 | $this->assertEquals(4, $strategy->getBackoffPeriod(2, $request)); 20 | $this->assertEquals(8, $strategy->getBackoffPeriod(3, $request)); 21 | $this->assertEquals(16, $strategy->getBackoffPeriod(4, $request)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Http/Message/Header/HeaderFactoryTest.php: -------------------------------------------------------------------------------- 1 | createHeader('Foo', 'Bar'); 16 | $this->assertInstanceOf('Guzzle\Http\Message\Header', $h); 17 | $this->assertEquals('Foo', $h->getName()); 18 | $this->assertEquals('Bar', (string) $h); 19 | } 20 | 21 | public function testCreatesSpecificHeaders() 22 | { 23 | $f = new HeaderFactory(); 24 | $h = $f->createHeader('Link', '; rel="test"'); 25 | $this->assertInstanceOf('Guzzle\Http\Message\Header\Link', $h); 26 | $this->assertEquals('Link', $h->getName()); 27 | $this->assertEquals('; rel="test"', (string) $h); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Guzzle/Cache/DoctrineCacheAdapter.php: -------------------------------------------------------------------------------- 1 | cache = $cache; 20 | } 21 | 22 | public function contains($id, array $options = null) 23 | { 24 | return $this->cache->contains($id); 25 | } 26 | 27 | public function delete($id, array $options = null) 28 | { 29 | return $this->cache->delete($id); 30 | } 31 | 32 | public function fetch($id, array $options = null) 33 | { 34 | return $this->cache->fetch($id); 35 | } 36 | 37 | public function save($id, $data, $lifeTime = false, array $options = null) 38 | { 39 | return $this->cache->save($id, $data, $lifeTime); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Http/QueryAggregator/DuplicateAggregatorTest.php: -------------------------------------------------------------------------------- 1 | aggregate($key, $value, $query); 17 | $this->assertEquals(array('facet%201' => array('size%20a', 'width%20b')), $result); 18 | } 19 | 20 | public function testEncodes() 21 | { 22 | $query = new QueryString(); 23 | $query->useUrlEncoding(false); 24 | $a = new Ag(); 25 | $key = 'facet 1'; 26 | $value = array('size a', 'width b'); 27 | $result = $a->aggregate($key, $value, $query); 28 | $this->assertEquals(array('facet 1' => array('size a', 'width b')), $result); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Backoff/HttpBackoffStrategy.php: -------------------------------------------------------------------------------- 1 | isSuccessful()) { 24 | return false; 25 | } else { 26 | return isset($this->errorCodes[$response->getStatusCode()]) ? true : null; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Batch/BatchClosureDivisorTest.php: -------------------------------------------------------------------------------- 1 | createBatches($queue); 34 | $this->assertEquals(array(array('foo'), array('baz')), $batches); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Service/Mock/Command/MockCommand.php: -------------------------------------------------------------------------------- 1 | get_called_class() == __CLASS__ ? 'mock_command' : 'sub.sub', 13 | 'httpMethod' => 'POST', 14 | 'parameters' => array( 15 | 'test' => array( 16 | 'default' => 123, 17 | 'required' => true, 18 | 'doc' => 'Test argument' 19 | ), 20 | '_internal' => array( 21 | 'default' => 'abc' 22 | ), 23 | 'foo' => array('filters' => array('strtoupper')) 24 | ) 25 | )); 26 | } 27 | 28 | protected function build() 29 | { 30 | $this->request = $this->client->createRequest(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Cache/DefaultCanCacheStrategy.php: -------------------------------------------------------------------------------- 1 | getMethod() != RequestInterface::GET && $request->getMethod() != RequestInterface::HEAD) { 17 | return false; 18 | } 19 | 20 | // Never cache requests when using no-store 21 | if ($request->hasHeader('Cache-Control') && $request->getHeader('Cache-Control')->hasDirective('no-store')) { 22 | return false; 23 | } 24 | 25 | return true; 26 | } 27 | 28 | public function canCacheResponse(Response $response) 29 | { 30 | return $response->isSuccessful() && $response->canCache(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Backoff/ConstantBackoffStrategy.php: -------------------------------------------------------------------------------- 1 | delay = $delay; 23 | } 24 | 25 | public function makesDecision() 26 | { 27 | return false; 28 | } 29 | 30 | protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null) 31 | { 32 | return $this->delay; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Resource/MapResourceIteratorFactory.php: -------------------------------------------------------------------------------- 1 | map = $map; 19 | } 20 | 21 | public function getClassName(CommandInterface $command) 22 | { 23 | $className = $command->getName(); 24 | 25 | if (isset($this->map[$className])) { 26 | return $this->map[$className]; 27 | } elseif (isset($this->map['*'])) { 28 | // If a wildcard was added, then always use that 29 | return $this->map['*']; 30 | } 31 | 32 | return null; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /phing/imports/metrics.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Backoff/LinearBackoffStrategy.php: -------------------------------------------------------------------------------- 1 | step = $step; 25 | } 26 | 27 | public function makesDecision() 28 | { 29 | return false; 30 | } 31 | 32 | protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null) 33 | { 34 | return $retries * $this->step; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Guzzle/Batch/BatchSizeDivisor.php: -------------------------------------------------------------------------------- 1 | size = $size; 17 | } 18 | 19 | /** 20 | * Set the size of each batch 21 | * 22 | * @param int $size Size of each batch 23 | * 24 | * @return BatchSizeDivisor 25 | */ 26 | public function setSize($size) 27 | { 28 | $this->size = $size; 29 | 30 | return $this; 31 | } 32 | 33 | /** 34 | * Get the size of each batch 35 | * 36 | * @return int 37 | */ 38 | public function getSize() 39 | { 40 | return $this->size; 41 | } 42 | 43 | public function createBatches(\SplQueue $queue) 44 | { 45 | return array_chunk(iterator_to_array($queue, false), $this->size); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Parser/Message/PeclHttpMessageParserTest.php: -------------------------------------------------------------------------------- 1 | markTestSkipped('pecl_http is not available.'); 16 | } 17 | } 18 | 19 | /** 20 | * @dataProvider requestProvider 21 | */ 22 | public function testParsesRequests($message, $parts) 23 | { 24 | $parser = new PeclHttpMessageParser(); 25 | $this->compareRequestResults($parts, $parser->parseRequest($message)); 26 | } 27 | 28 | /** 29 | * @dataProvider responseProvider 30 | */ 31 | public function testParsesResponses($message, $parts) 32 | { 33 | $parser = new PeclHttpMessageParser(); 34 | $this->compareResponseResults($parts, $parser->parseResponse($message)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Service/Mock/Model/MockCommandIterator.php: -------------------------------------------------------------------------------- 1 | nextToken) { 14 | $this->command->set('next_token', $this->nextToken); 15 | } 16 | 17 | $this->command->set('page_size', (int) $this->calculatePageSize()); 18 | $this->command->execute(); 19 | 20 | $data = json_decode($this->command->getResponse()->getBody(true), true); 21 | 22 | $this->nextToken = $data['next_token']; 23 | 24 | return $data['resources']; 25 | } 26 | 27 | public function next() 28 | { 29 | $this->calledNext++; 30 | parent::next(); 31 | } 32 | 33 | public function getResources() 34 | { 35 | return $this->resources; 36 | } 37 | 38 | public function getIteratedCount() 39 | { 40 | return $this->iteratedCount; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Guzzle/Cache/Zf2CacheAdapter.php: -------------------------------------------------------------------------------- 1 | cache = $cache; 20 | } 21 | 22 | public function contains($id, array $options = null) 23 | { 24 | return $this->cache->hasItem($id); 25 | } 26 | 27 | public function delete($id, array $options = null) 28 | { 29 | return $this->cache->removeItem($id); 30 | } 31 | 32 | public function fetch($id, array $options = null) 33 | { 34 | return $this->cache->getItem($id); 35 | } 36 | 37 | public function save($id, $data, $lifeTime = false, array $options = null) 38 | { 39 | return $this->cache->setItem($id, $data); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Backoff/CurlBackoffStrategy.php: -------------------------------------------------------------------------------- 1 | errorCodes[$e->getErrorNo()]) ? true : null; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Description/ValidatorInterface.php: -------------------------------------------------------------------------------- 1 | invalidCommands = $commands; 23 | parent::__construct( 24 | 'Encountered commands in a batch transfer that use inconsistent clients. The batching ' . 25 | 'strategy you use with a command transfer must divide command batches by client.' 26 | ); 27 | } 28 | 29 | /** 30 | * Get the invalid commands 31 | * 32 | * @return array 33 | */ 34 | public function getCommands() 35 | { 36 | return $this->invalidCommands; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Guzzle/Batch/NotifyingBatch.php: -------------------------------------------------------------------------------- 1 | callable = $callable; 28 | parent::__construct($decoratedBatch); 29 | } 30 | 31 | public function flush() 32 | { 33 | $items = $this->decoratedBatch->flush(); 34 | call_user_func($this->callable, $items); 35 | 36 | return $items; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Backoff/BackoffStrategyInterface.php: -------------------------------------------------------------------------------- 1 | callback = $callback; 30 | } 31 | 32 | public function accept() 33 | { 34 | return call_user_func($this->callback, $this->current()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Service/Mock/MockClient.php: -------------------------------------------------------------------------------- 1 | '{scheme}://127.0.0.1:8124/{api_version}/{subdomain}', 30 | 'scheme' => 'http', 31 | 'api_version' => 'v1' 32 | ), array('username', 'password', 'subdomain')); 33 | 34 | return new self($config->get('base_url'), $config); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Backoff/TruncatedBackoffStrategy.php: -------------------------------------------------------------------------------- 1 | max = $maxRetries; 24 | $this->next = $next; 25 | } 26 | 27 | public function makesDecision() 28 | { 29 | return true; 30 | } 31 | 32 | protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null) 33 | { 34 | return $retries < $this->max ? null : false; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Michael Dowling, https://github.com/mtdowling 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Cache/CacheStorageInterface.php: -------------------------------------------------------------------------------- 1 | 'Guzzle\Tests\Service\Mock\Command\MockCommand', 28 | 'test1' => 'Guzzle\Tests\Service\Mock\Command\OtherCommand' 29 | )); 30 | 31 | if (is_null($result)) { 32 | $this->assertNull($factory->factory($key)); 33 | } else { 34 | $this->assertInstanceof($result, $factory->factory($key)); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Guzzle/Cache/Zf1CacheAdapter.php: -------------------------------------------------------------------------------- 1 | cache = $cache; 23 | } 24 | 25 | public function contains($id, array $options = null) 26 | { 27 | return $this->cache->test($id); 28 | } 29 | 30 | public function delete($id, array $options = null) 31 | { 32 | return $this->cache->remove($id); 33 | } 34 | 35 | public function fetch($id, array $options = null) 36 | { 37 | return $this->cache->load($id); 38 | } 39 | 40 | public function save($id, $data, $lifeTime = false, array $options = null) 41 | { 42 | return $this->cache->save($data, $id, array(), $lifeTime); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Batch/AbstractBatchDecoratorTest.php: -------------------------------------------------------------------------------- 1 | getMock('Guzzle\Batch\BatchTransferInterface'), 16 | $this->getMock('Guzzle\Batch\BatchDivisorInterface') 17 | ); 18 | 19 | $decoratorA = $this->getMockBuilder('Guzzle\Batch\AbstractBatchDecorator') 20 | ->setConstructorArgs(array($batch)) 21 | ->getMockForAbstractClass(); 22 | 23 | $decoratorB = $this->getMockBuilder('Guzzle\Batch\AbstractBatchDecorator') 24 | ->setConstructorArgs(array($decoratorA)) 25 | ->getMockForAbstractClass(); 26 | 27 | $decoratorA->add('foo'); 28 | $this->assertFalse($decoratorB->isEmpty()); 29 | $this->assertFalse($batch->isEmpty()); 30 | $this->assertEquals(array($decoratorB, $decoratorA), $decoratorB->getDecorators()); 31 | $this->assertEquals(array(), $decoratorB->flush()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Resource/AbstractResourceIteratorFactory.php: -------------------------------------------------------------------------------- 1 | canBuild($command)) { 16 | throw new InvalidArgumentException('Iterator was not found for ' . $command->getName()); 17 | } 18 | 19 | $className = $this->getClassName($command); 20 | 21 | return new $className($command, $options); 22 | } 23 | 24 | public function canBuild(CommandInterface $command) 25 | { 26 | return (bool) $this->getClassName($command); 27 | } 28 | 29 | /** 30 | * Get the name of the class to instantiate for the command 31 | * 32 | * @param CommandInterface $command Command that is associated with the iterator 33 | * 34 | * @return string 35 | */ 36 | abstract protected function getClassName(CommandInterface $command); 37 | } 38 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Backoff/AbstractErrorCodeBackoffStrategy.php: -------------------------------------------------------------------------------- 1 | errorCodes = array_fill_keys($codes ?: static::$defaultErrorCodes, 1); 23 | $this->next = $next; 24 | } 25 | 26 | /** 27 | * Get the default failure codes to retry 28 | * 29 | * @return array 30 | */ 31 | public static function getDefaultFailureCodes() 32 | { 33 | return static::$defaultErrorCodes; 34 | } 35 | 36 | public function makesDecision() 37 | { 38 | return true; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Command/LocationVisitor/Request/RequestVisitorInterface.php: -------------------------------------------------------------------------------- 1 | getMock('Guzzle\Http\Message\Request', array(), array(), '', false); 23 | $strategy = new CallbackBackoffStrategy(function () { return 10; }, true); 24 | $this->assertTrue($strategy->makesDecision()); 25 | $this->assertEquals(10, $strategy->getBackoffPeriod(0, $request)); 26 | // Ensure it chains correctly when null is returned 27 | $strategy = new CallbackBackoffStrategy(function () { return null; }, false); 28 | $this->assertFalse($strategy->makesDecision()); 29 | $this->assertFalse($strategy->getBackoffPeriod(0, $request)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.3 5 | - 5.4 6 | - 5.5 7 | 8 | before_script: 9 | - curl --version 10 | - pear config-set php_ini ~/.phpenv/versions/`php -r 'echo phpversion();'`/etc/php.ini 11 | - echo 'Installing pecl_http' 12 | - wget --quiet http://pecl.php.net/get/pecl_http-1.7.6.tgz 13 | - tar -xzf pecl_http-1.7.6.tgz 14 | - sh -c "cd pecl_http-1.7.6 && phpize && ./configure && make && sudo make install" > /dev/null 15 | - echo "extension=http.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` 16 | - pecl install uri_template-beta 17 | - pear config-set auto_discover 1 18 | - pear install pear.phing.info/phing 19 | - pear install pear.phpunit.de/phploc 20 | - pear install pear/PHP_CodeSniffer 21 | - pear install pear.pdepend.org/PHP_Depend 22 | - pear install bartlett.laurent-laville.org/PHP_CompatInfo 23 | - pear install pear/PEAR_PackageFileManager2 pear/PEAR_PackageFileManager2_Plugins pear/XML_Serializer-beta 24 | - pear install VersionControl_Git-alpha 25 | - phpenv rehash 26 | - composer install --dev 27 | - cp phing/build.properties.travis phing/build.properties 28 | - echo 'Ensuring the correct version of node is running' 29 | - ~/.nvm/nvm.sh install v0.6.14 30 | 31 | script: phing travisci 32 | -------------------------------------------------------------------------------- /src/Guzzle/Common/Event.php: -------------------------------------------------------------------------------- 1 | context = $context; 21 | } 22 | 23 | public function getIterator() 24 | { 25 | return new \ArrayIterator($this->context); 26 | } 27 | 28 | public function offsetGet($offset) 29 | { 30 | return isset($this->context[$offset]) ? $this->context[$offset] : null; 31 | } 32 | 33 | public function offsetSet($offset, $value) 34 | { 35 | $this->context[$offset] = $value; 36 | } 37 | 38 | public function offsetExists($offset) 39 | { 40 | return isset($this->context[$offset]); 41 | } 42 | 43 | public function offsetUnset($offset) 44 | { 45 | unset($this->context[$offset]); 46 | } 47 | 48 | public function toArray() 49 | { 50 | return $this->context; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Command/Factory/AliasFactory.php: -------------------------------------------------------------------------------- 1 | client = $client; 26 | $this->aliases = $aliases; 27 | } 28 | 29 | public function factory($name, array $args = array()) 30 | { 31 | if (isset($this->aliases[$name])) { 32 | try { 33 | return $this->client->getCommand($this->aliases[$name], $args); 34 | } catch (InvalidArgumentException $e) { 35 | return null; 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Guzzle/Batch/BatchClosureDivisor.php: -------------------------------------------------------------------------------- 1 | callable = $callable; 32 | $this->context = $context; 33 | } 34 | 35 | public function createBatches(\SplQueue $queue) 36 | { 37 | return call_user_func($this->callable, $queue, $this->context); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /phing/imports/test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Http/Curl/CurlVersionTest.php: -------------------------------------------------------------------------------- 1 | getProperty('version'); 20 | $refProperty->setAccessible(true); 21 | $refProperty->setValue($instance, array()); 22 | 23 | $this->assertEquals($info, $instance->getAll()); 24 | $this->assertEquals($info, $instance->getAll()); 25 | 26 | $this->assertEquals($info['version'], $instance->get('version')); 27 | $this->assertFalse($instance->get('foo')); 28 | } 29 | 30 | public function testIsSingleton() 31 | { 32 | $refObject = new \ReflectionClass('Guzzle\Http\Curl\CurlVersion'); 33 | $refProperty = $refObject->getProperty('instance'); 34 | $refProperty->setAccessible(true); 35 | $refProperty->setValue(null, null); 36 | 37 | $this->assertInstanceOf('Guzzle\Http\Curl\CurlVersion', CurlVersion::getInstance()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/PostFieldVisitorTest.php: -------------------------------------------------------------------------------- 1 | getNestedCommand('postField')->getParam('foo'); 16 | $visitor->visit($this->command, $this->request, $param->setSentAs('test'), '123'); 17 | $this->assertEquals('123', (string) $this->request->getPostField('test')); 18 | } 19 | 20 | public function testRecursivelyBuildsPostFields() 21 | { 22 | $command = $this->getCommand('postField'); 23 | $request = $command->prepare(); 24 | $visitor = new Visitor(); 25 | $param = $command->getOperation()->getParam('foo'); 26 | $visitor->visit($command, $request, $param, $command['foo']); 27 | $visitor->after($command, $request); 28 | $this->assertEquals( 29 | 'Foo[test][baz]=1&Foo[test][Jenga_Yall!]=HELLO&Foo[bar]=123', 30 | rawurldecode((string) $request->getPostFields()) 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/TestData/test_service.json: -------------------------------------------------------------------------------- 1 | { 2 | "includes": [ "test_service2.json" ], 3 | "operations": { 4 | "test": { 5 | "uri": "/path" 6 | }, 7 | "concrete": { 8 | "extends": "abstract" 9 | }, 10 | "foo_bar": { 11 | "uri": "/testing", 12 | "parameters": { 13 | "other": { 14 | "location": "json", 15 | "location_key": "Other" 16 | }, 17 | "test": { 18 | "type": "object", 19 | "location": "json", 20 | "properties": { 21 | "baz": { 22 | "type": "boolean", 23 | "default": true 24 | }, 25 | "bar": { 26 | "type": "string", 27 | "filters": [ 28 | { 29 | "method": "strtolower", 30 | "args": ["test", "@value"] 31 | }, 32 | "strtoupper" 33 | ] 34 | } 35 | } 36 | } 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Guzzle/Service/CachingConfigLoader.php: -------------------------------------------------------------------------------- 1 | loader = $loader; 25 | $this->cache = $cache; 26 | } 27 | 28 | public function load($config, array $options = array()) 29 | { 30 | if (!is_string($config)) { 31 | $key = false; 32 | } else { 33 | $key = 'loader_' . crc32($config); 34 | if ($result = $this->cache->fetch($key)) { 35 | return $result; 36 | } 37 | } 38 | 39 | $result = $this->loader->load($config, $options); 40 | if ($key) { 41 | $this->cache->save($key, $result); 42 | } 43 | 44 | return $result; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Plugin/Backoff/TruncatedBackoffStrategyTest.php: -------------------------------------------------------------------------------- 1 | assertTrue($strategy->makesDecision()); 19 | $request = $this->getMock('Guzzle\Http\Message\Request', array(), array(), '', false); 20 | $this->assertFalse($strategy->getBackoffPeriod(0, $request)); 21 | $this->assertFalse($strategy->getBackoffPeriod(1, $request)); 22 | $this->assertFalse($strategy->getBackoffPeriod(2, $request)); 23 | 24 | $response = new Response(500); 25 | $strategy->setNext(new HttpBackoffStrategy(null, new ConstantBackoffStrategy(10))); 26 | $this->assertEquals(10, $strategy->getBackoffPeriod(0, $request, $response)); 27 | $this->assertEquals(10, $strategy->getBackoffPeriod(1, $request, $response)); 28 | $this->assertFalse($strategy->getBackoffPeriod(2, $request, $response)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Guzzle/Batch/BatchClosureTransfer.php: -------------------------------------------------------------------------------- 1 | callable = $callable; 33 | $this->context = $context; 34 | } 35 | 36 | public function transfer(array $batch) 37 | { 38 | return empty($batch) ? null : call_user_func($this->callable, $batch, $this->context); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Batch/FlushingBatchTest.php: -------------------------------------------------------------------------------- 1 | getMock('Guzzle\Batch\BatchTransferInterface', array('transfer')); 16 | $d = $this->getMock('Guzzle\Batch\BatchDivisorInterface', array('createBatches')); 17 | 18 | $batch = new Batch($t, $d); 19 | $queue = $this->readAttribute($batch, 'queue'); 20 | 21 | $d->expects($this->exactly(2)) 22 | ->method('createBatches') 23 | ->will($this->returnCallback(function () use ($queue) { 24 | $items = array(); 25 | foreach ($queue as $item) { 26 | $items[] = $item; 27 | } 28 | return array($items); 29 | })); 30 | 31 | $t->expects($this->exactly(2)) 32 | ->method('transfer'); 33 | 34 | $flush = new FlushingBatch($batch, 3); 35 | $this->assertEquals(3, $flush->getThreshold()); 36 | $flush->setThreshold(2); 37 | $flush->add('foo')->add('baz')->add('bar')->add('bee')->add('boo'); 38 | $this->assertEquals(1, count($flush)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Guzzle/Common/AbstractHasDispatcher.php: -------------------------------------------------------------------------------- 1 | eventDispatcher = $eventDispatcher; 25 | 26 | return $this; 27 | } 28 | 29 | public function getEventDispatcher() 30 | { 31 | if (!$this->eventDispatcher) { 32 | $this->eventDispatcher = new EventDispatcher(); 33 | } 34 | 35 | return $this->eventDispatcher; 36 | } 37 | 38 | public function dispatch($eventName, array $context = array()) 39 | { 40 | return $this->getEventDispatcher()->dispatch($eventName, new Event($context)); 41 | } 42 | 43 | public function addSubscriber(EventSubscriberInterface $subscriber) 44 | { 45 | $this->getEventDispatcher()->addSubscriber($subscriber); 46 | 47 | return $this; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Guzzle/Parser/Message/PeclHttpMessageParser.php: -------------------------------------------------------------------------------- 1 | $parts->requestMethod, 20 | 'protocol' => 'HTTP', 21 | 'version' => number_format($parts->httpVersion, 1), 22 | 'headers' => $parts->headers, 23 | 'body' => $parts->body 24 | ); 25 | 26 | $parsed['request_url'] = $this->getUrlPartsFromMessage($parts->requestUrl, $parsed); 27 | 28 | return $parsed; 29 | } 30 | 31 | public function parseResponse($message) 32 | { 33 | if (!$message) { 34 | return false; 35 | } 36 | 37 | $parts = http_parse_message($message); 38 | 39 | return array( 40 | 'protocol' => 'HTTP', 41 | 'version' => number_format($parts->httpVersion, 1), 42 | 'code' => $parts->responseCode, 43 | 'reason_phrase' => $parts->responseStatus, 44 | 'headers' => $parts->headers, 45 | 'body' => $parts->body 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Plugin/Backoff/ReasonPhraseBackoffStrategyTest.php: -------------------------------------------------------------------------------- 1 | assertEmpty(ReasonPhraseBackoffStrategy::getDefaultFailureCodes()); 17 | $strategy = new ReasonPhraseBackoffStrategy(array('Foo', 'Internal Server Error')); 18 | $this->assertTrue($strategy->makesDecision()); 19 | $request = $this->getMock('Guzzle\Http\Message\Request', array(), array(), '', false); 20 | $response = new Response(200); 21 | $this->assertEquals(false, $strategy->getBackoffPeriod(0, $request, $response)); 22 | $response->setStatus(200, 'Foo'); 23 | $this->assertEquals(0, $strategy->getBackoffPeriod(0, $request, $response)); 24 | } 25 | 26 | public function testIgnoresNonErrors() 27 | { 28 | $strategy = new ReasonPhraseBackoffStrategy(); 29 | $request = $this->getMock('Guzzle\Http\Message\Request', array(), array(), '', false); 30 | $this->assertEquals(false, $strategy->getBackoffPeriod(0, $request)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Guzzle/Batch/ExceptionBufferingBatch.php: -------------------------------------------------------------------------------- 1 | decoratedBatch->isEmpty()) { 21 | try { 22 | $transferredItems = $this->decoratedBatch->flush(); 23 | } catch (BatchTransferException $e) { 24 | $this->exceptions[] = $e; 25 | $transferredItems = $e->getTransferredItems(); 26 | } 27 | $items = array_merge($items, $transferredItems); 28 | } 29 | 30 | return $items; 31 | } 32 | 33 | /** 34 | * Get the buffered exceptions 35 | * 36 | * @return array Array of BatchTransferException objects 37 | */ 38 | public function getExceptions() 39 | { 40 | return $this->exceptions; 41 | } 42 | 43 | /** 44 | * Clear the buffered exceptions 45 | */ 46 | public function clearExceptions() 47 | { 48 | $this->exceptions = array(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Batch/NotifyingBatchTest.php: -------------------------------------------------------------------------------- 1 | getMock('Guzzle\Batch\Batch', array('flush'), array( 16 | $this->getMock('Guzzle\Batch\BatchTransferInterface'), 17 | $this->getMock('Guzzle\Batch\BatchDivisorInterface') 18 | )); 19 | 20 | $batch->expects($this->once()) 21 | ->method('flush') 22 | ->will($this->returnValue(array('foo', 'baz'))); 23 | 24 | $data = array(); 25 | $decorator = new NotifyingBatch($batch, function ($batch) use (&$data) { 26 | $data[] = $batch; 27 | }); 28 | 29 | $decorator->add('foo')->add('baz'); 30 | $decorator->flush(); 31 | $this->assertEquals(array(array('foo', 'baz')), $data); 32 | } 33 | 34 | /** 35 | * @expectedException Guzzle\Common\Exception\InvalidArgumentException 36 | */ 37 | public function testEnsuresCallableIsValid() 38 | { 39 | $batch = new Batch( 40 | $this->getMock('Guzzle\Batch\BatchTransferInterface'), 41 | $this->getMock('Guzzle\Batch\BatchDivisorInterface') 42 | ); 43 | $decorator = new NotifyingBatch($batch, 'foo'); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Command/ClosureCommand.php: -------------------------------------------------------------------------------- 1 | request = $closure($this, $this->operation); 36 | 37 | if (!$this->request || !$this->request instanceof RequestInterface) { 38 | throw new UnexpectedValueException('Closure command did not return a RequestInterface object'); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Plugin/Cache/DefaultCanCacheStrategyTest.php: -------------------------------------------------------------------------------- 1 | assertTrue($strategy->canCacheRequest($request)); 19 | } 20 | 21 | public function testDoesNotCacheNoStore() 22 | { 23 | $strategy = new DefaultCanCacheStrategy(); 24 | $request = new Request('GET', 'http://foo.com', array('cache-control' => 'no-store')); 25 | $this->assertFalse($strategy->canCacheRequest($request)); 26 | } 27 | 28 | public function testCanCacheResponse() 29 | { 30 | $response = $this->getMockBuilder('Guzzle\Http\Message\Response') 31 | ->setMethods(array('canCache')) 32 | ->setConstructorArgs(array(200)) 33 | ->getMock(); 34 | $response->expects($this->once()) 35 | ->method('canCache') 36 | ->will($this->returnValue(true)); 37 | $strategy = new DefaultCanCacheStrategy(); 38 | $this->assertTrue($strategy->canCacheResponse($response)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Service/Resource/CompositeResourceIteratorFactoryTest.php: -------------------------------------------------------------------------------- 1 | assertFalse($factory->canBuild($cmd)); 25 | $factory->build($cmd); 26 | } 27 | 28 | public function testBuildsResourceIterators() 29 | { 30 | $f1 = new ResourceIteratorClassFactory('Guzzle\Tests\Service\Mock\Model'); 31 | $factory = new CompositeResourceIteratorFactory(array()); 32 | $factory->addFactory($f1); 33 | $command = new MockCommand(); 34 | $iterator = $factory->build($command, array('client.namespace' => 'Guzzle\Tests\Service\Mock')); 35 | $this->assertInstanceOf('Guzzle\Tests\Service\Mock\Model\MockCommandIterator', $iterator); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Guzzle/Http/Message/PostFileInterface.php: -------------------------------------------------------------------------------- 1 | =5.3.2", 16 | "guzzle/http": "self.version" 17 | }, 18 | "suggest": { 19 | "guzzle/cache": "self.version", 20 | "guzzle/log": "self.version" 21 | }, 22 | "autoload": { 23 | "psr-0": { "Guzzle\\Plugin": "" } 24 | }, 25 | "target-dir": "Guzzle/Plugin", 26 | "replace": { 27 | "guzzle/plugin-async": "self.version", 28 | "guzzle/plugin-backoff": "self.version", 29 | "guzzle/plugin-cache": "self.version", 30 | "guzzle/plugin-cookie": "self.version", 31 | "guzzle/plugin-curlauth": "self.version", 32 | "guzzle/plugin-error-response": "self.version", 33 | "guzzle/plugin-history": "self.version", 34 | "guzzle/plugin-log": "self.version", 35 | "guzzle/plugin-md5": "self.version", 36 | "guzzle/plugin-mock": "self.version", 37 | "guzzle/plugin-oauth": "self.version" 38 | }, 39 | "extra": { 40 | "branch-alias": { 41 | "dev-master": "3.7-dev" 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Log/Zf2LogAdapterTest.php: -------------------------------------------------------------------------------- 1 | stream = fopen('php://temp', 'r+'); 26 | $this->log = new Logger(); 27 | $this->log->addWriter(new Stream($this->stream)); 28 | $this->adapter = new Zf2LogAdapter($this->log); 29 | 30 | } 31 | 32 | public function testLogsMessagesToAdaptedObject() 33 | { 34 | // Test without a priority 35 | $this->adapter->log('Zend_Test!', \LOG_NOTICE); 36 | rewind($this->stream); 37 | $contents = stream_get_contents($this->stream); 38 | $this->assertEquals(1, substr_count($contents, 'Zend_Test!')); 39 | 40 | // Test with a priority 41 | $this->adapter->log('Zend_Test!', \LOG_ALERT); 42 | rewind($this->stream); 43 | $contents = stream_get_contents($this->stream); 44 | $this->assertEquals(2, substr_count($contents, 'Zend_Test!')); 45 | } 46 | 47 | public function testExposesAdaptedLogObject() 48 | { 49 | $this->assertEquals($this->log, $this->adapter->getLogObject()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Guzzle/Iterator/ChunkedIterator.php: -------------------------------------------------------------------------------- 1 | chunkSize = $chunkSize; 30 | } 31 | 32 | public function rewind() 33 | { 34 | parent::rewind(); 35 | $this->next(); 36 | } 37 | 38 | public function next() 39 | { 40 | $this->chunk = array(); 41 | for ($i = 0; $i < $this->chunkSize && parent::valid(); $i++) { 42 | $this->chunk[] = parent::current(); 43 | parent::next(); 44 | } 45 | } 46 | 47 | public function current() 48 | { 49 | return $this->chunk; 50 | } 51 | 52 | public function valid() 53 | { 54 | return (bool) $this->chunk; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Batch/ExceptionBufferingBatchTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder('Guzzle\Batch\BatchTransferInterface') 17 | ->setMethods(array('transfer')) 18 | ->getMock(); 19 | 20 | $d = new BatchSizeDivisor(1); 21 | $batch = new Batch($t, $d); 22 | 23 | $called = 0; 24 | $t->expects($this->exactly(3)) 25 | ->method('transfer') 26 | ->will($this->returnCallback(function ($batch) use (&$called) { 27 | if (++$called === 2) { 28 | throw new \Exception('Foo'); 29 | } 30 | })); 31 | 32 | $decorator = new ExceptionBufferingBatch($batch); 33 | $decorator->add('foo')->add('baz')->add('bar'); 34 | $result = $decorator->flush(); 35 | 36 | $e = $decorator->getExceptions(); 37 | $this->assertEquals(1, count($e)); 38 | $this->assertEquals(array('baz'), $e[0]->getBatch()); 39 | 40 | $decorator->clearExceptions(); 41 | $this->assertEquals(0, count($decorator->getExceptions())); 42 | 43 | $this->assertEquals(array('foo', 'bar'), $result); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Plugin/Backoff/CurlBackoffStrategyTest.php: -------------------------------------------------------------------------------- 1 | assertNotEmpty(CurlBackoffStrategy::getDefaultFailureCodes()); 18 | $strategy = new CurlBackoffStrategy(); 19 | $this->assertTrue($strategy->makesDecision()); 20 | $request = $this->getMock('Guzzle\Http\Message\Request', array(), array(), '', false); 21 | $e = new CurlException(); 22 | $e->setError('foo', CURLE_BAD_CALLING_ORDER); 23 | $this->assertEquals(false, $strategy->getBackoffPeriod(0, $request, null, $e)); 24 | 25 | foreach (CurlBackoffStrategy::getDefaultFailureCodes() as $code) { 26 | $this->assertEquals(0, $strategy->getBackoffPeriod(0, $request, null, $e->setError('foo', $code))); 27 | } 28 | } 29 | 30 | public function testIgnoresNonErrors() 31 | { 32 | $strategy = new CurlBackoffStrategy(); 33 | $request = $this->getMock('Guzzle\Http\Message\Request', array(), array(), '', false); 34 | $this->assertEquals(false, $strategy->getBackoffPeriod(0, $request, new Response(200))); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Service/Resource/MapResourceIteratorFactoryTest.php: -------------------------------------------------------------------------------- 1 | build(new MockCommand()); 21 | } 22 | 23 | public function testBuildsResourceIterators() 24 | { 25 | $factory = new MapResourceIteratorFactory(array( 26 | 'mock_command' => 'Guzzle\Tests\Service\Mock\Model\MockCommandIterator' 27 | )); 28 | $iterator = $factory->build(new MockCommand()); 29 | $this->assertInstanceOf('Guzzle\Tests\Service\Mock\Model\MockCommandIterator', $iterator); 30 | } 31 | 32 | public function testUsesWildcardMappings() 33 | { 34 | $factory = new MapResourceIteratorFactory(array( 35 | '*' => 'Guzzle\Tests\Service\Mock\Model\MockCommandIterator' 36 | )); 37 | $iterator = $factory->build(new MockCommand()); 38 | $this->assertInstanceOf('Guzzle\Tests\Service\Mock\Model\MockCommandIterator', $iterator); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/CurlAuth/CurlAuthPlugin.php: -------------------------------------------------------------------------------- 1 | getConfig()->setPath('request.options/auth', array('user', 'pass', 'Basic|Digest'); 12 | */ 13 | class CurlAuthPlugin implements EventSubscriberInterface 14 | { 15 | private $username; 16 | private $password; 17 | private $scheme; 18 | 19 | /** 20 | * @param string $username HTTP basic auth username 21 | * @param string $password Password 22 | * @param int $scheme Curl auth scheme 23 | */ 24 | public function __construct($username, $password, $scheme=CURLAUTH_BASIC) 25 | { 26 | Version::warn(__CLASS__ . " is deprecated. Use \$client->getConfig()->setPath('request.options/auth', array('user', 'pass', 'Basic|Digest');"); 27 | $this->username = $username; 28 | $this->password = $password; 29 | $this->scheme = $scheme; 30 | } 31 | 32 | public static function getSubscribedEvents() 33 | { 34 | return array('client.create_request' => array('onRequestCreate', 255)); 35 | } 36 | 37 | /** 38 | * Add basic auth 39 | * 40 | * @param Event $event 41 | */ 42 | public function onRequestCreate(Event $event) 43 | { 44 | $event['request']->setAuth($this->username, $this->password, $this->scheme); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Http/IoEmittingEntityBodyTest.php: -------------------------------------------------------------------------------- 1 | decorated = EntityBody::factory('hello'); 19 | $this->body = new IoEmittingEntityBody($this->decorated); 20 | } 21 | 22 | public function testEmitsReadEvents() 23 | { 24 | $e = null; 25 | $this->body->getEventDispatcher()->addListener('body.read', function ($event) use (&$e) { 26 | $e = $event; 27 | }); 28 | $this->assertEquals('hel', $this->body->read(3)); 29 | $this->assertEquals('hel', $e['read']); 30 | $this->assertEquals(3, $e['length']); 31 | $this->assertSame($this->body, $e['body']); 32 | } 33 | 34 | public function testEmitsWriteEvents() 35 | { 36 | $e = null; 37 | $this->body->getEventDispatcher()->addListener('body.write', function ($event) use (&$e) { 38 | $e = $event; 39 | }); 40 | $this->body->seek(0, SEEK_END); 41 | $this->assertEquals(5, $this->body->write('there')); 42 | $this->assertEquals('there', $e['write']); 43 | $this->assertEquals(5, $e['result']); 44 | $this->assertSame($this->body, $e['body']); 45 | $this->assertEquals('hellothere', (string) $this->body); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Guzzle/Common/HasDispatcherInterface.php: -------------------------------------------------------------------------------- 1 | getEventDispatcher()->addSubscriber($plugin); 20 | $request = $client->get('/'); 21 | $this->assertEquals('michael', $request->getUsername()); 22 | $this->assertEquals('test', $request->getPassword()); 23 | Version::$emitWarnings = true; 24 | } 25 | 26 | public function testAddsDigestAuthentication() 27 | { 28 | Version::$emitWarnings = false; 29 | $plugin = new CurlAuthPlugin('julian', 'test', CURLAUTH_DIGEST); 30 | $client = new Client('http://www.test.com/'); 31 | $client->getEventDispatcher()->addSubscriber($plugin); 32 | $request = $client->get('/'); 33 | $this->assertEquals('julian', $request->getUsername()); 34 | $this->assertEquals('test', $request->getPassword()); 35 | $this->assertEquals('julian:test', $request->getCurlOptions()->get(CURLOPT_USERPWD)); 36 | $this->assertEquals(CURLAUTH_DIGEST, $request->getCurlOptions()->get(CURLOPT_HTTPAUTH)); 37 | Version::$emitWarnings = true; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Guzzle/Parser/Cookie/CookieParserInterface.php: -------------------------------------------------------------------------------- 1 | utf8 = $utf8; 25 | } 26 | 27 | public function parseUrl($url) 28 | { 29 | Version::warn(__CLASS__ . ' is deprecated. Just use parse_url()'); 30 | 31 | static $defaults = array('scheme' => null, 'host' => null, 'path' => null, 'port' => null, 'query' => null, 32 | 'user' => null, 'pass' => null, 'fragment' => null); 33 | 34 | $parts = parse_url($url); 35 | 36 | // Need to handle query parsing specially for UTF-8 requirements 37 | if ($this->utf8 && isset($parts['query'])) { 38 | $queryPos = strpos($url, '?'); 39 | if (isset($parts['fragment'])) { 40 | $parts['query'] = substr($url, $queryPos + 1, strpos($url, '#') - $queryPos - 1); 41 | } else { 42 | $parts['query'] = substr($url, $queryPos + 1); 43 | } 44 | } 45 | 46 | return $parts + $defaults; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Mock/MockObserver.php: -------------------------------------------------------------------------------- 1 | events as $event) { 20 | if ($event->getName() == $eventName) { 21 | return true; 22 | } 23 | } 24 | 25 | return false; 26 | } 27 | 28 | public function getLastEvent() 29 | { 30 | return end($this->events); 31 | } 32 | 33 | public function count() 34 | { 35 | return count($this->events); 36 | } 37 | 38 | public function getGrouped() 39 | { 40 | $events = array(); 41 | foreach ($this->events as $event) { 42 | if (!isset($events[$event->getName()])) { 43 | $events[$event->getName()] = array(); 44 | } 45 | $events[$event->getName()][] = $event; 46 | } 47 | 48 | return $events; 49 | } 50 | 51 | public function getData($event, $key, $occurrence = 0) 52 | { 53 | $grouped = $this->getGrouped(); 54 | if (isset($grouped[$event])) { 55 | return $grouped[$event][$occurrence][$key]; 56 | } 57 | 58 | return null; 59 | } 60 | 61 | public function update(Event $event) 62 | { 63 | $this->events[] = $event; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Batch/BatchClosureTransferTest.php: -------------------------------------------------------------------------------- 1 | itemsTransferred = null; 21 | $itemsTransferred =& $this->itemsTransferred; 22 | 23 | $this->transferStrategy = new BatchClosureTransfer(function (array $batch) use (&$itemsTransferred) { 24 | $itemsTransferred = $batch; 25 | return; 26 | }); 27 | } 28 | 29 | public function testTransfersBatch() 30 | { 31 | $batchedItems = array('foo', 'bar', 'baz'); 32 | $this->transferStrategy->transfer($batchedItems); 33 | 34 | $this->assertEquals($batchedItems, $this->itemsTransferred); 35 | } 36 | 37 | public function testTransferBailsOnEmptyBatch() 38 | { 39 | $batchedItems = array(); 40 | $this->transferStrategy->transfer($batchedItems); 41 | 42 | $this->assertNull($this->itemsTransferred); 43 | } 44 | 45 | /** 46 | * @expectedException Guzzle\Common\Exception\InvalidArgumentException 47 | */ 48 | public function testEnsuresCallableIsCallable() 49 | { 50 | $foo = new BatchClosureTransfer('uh oh!'); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Http/AbstractEntityBodyDecoratorTest.php: -------------------------------------------------------------------------------- 1 | getMockForAbstractClass('Guzzle\Http\AbstractEntityBodyDecorator', array($e)); 16 | 17 | $this->assertSame($e->getStream(), $mock->getStream()); 18 | $this->assertSame($e->getContentLength(), $mock->getContentLength()); 19 | $this->assertSame($e->getSize(), $mock->getSize()); 20 | $this->assertSame($e->getContentMd5(), $mock->getContentMd5()); 21 | $this->assertSame($e->getContentType(), $mock->getContentType()); 22 | $this->assertSame($e->__toString(), $mock->__toString()); 23 | $this->assertSame($e->getUri(), $mock->getUri()); 24 | $this->assertSame($e->getStreamType(), $mock->getStreamType()); 25 | $this->assertSame($e->getWrapper(), $mock->getWrapper()); 26 | $this->assertSame($e->getWrapperData(), $mock->getWrapperData()); 27 | $this->assertSame($e->isReadable(), $mock->isReadable()); 28 | $this->assertSame($e->isWritable(), $mock->isWritable()); 29 | $this->assertSame($e->isConsumed(), $mock->isConsumed()); 30 | $this->assertSame($e->isLocal(), $mock->isLocal()); 31 | $this->assertSame($e->isSeekable(), $mock->isSeekable()); 32 | $this->assertSame($e->getContentEncoding(), $mock->getContentEncoding()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Inflection/InflectorTest.php: -------------------------------------------------------------------------------- 1 | assertSame(Inflector::getDefault(), Inflector::getDefault()); 15 | } 16 | 17 | public function testSnake() 18 | { 19 | $this->assertEquals('camel_case', Inflector::getDefault()->snake('camelCase')); 20 | $this->assertEquals('camel_case', Inflector::getDefault()->snake('CamelCase')); 21 | $this->assertEquals('camel_case_words', Inflector::getDefault()->snake('CamelCaseWords')); 22 | $this->assertEquals('camel_case_words', Inflector::getDefault()->snake('CamelCase_words')); 23 | $this->assertEquals('test', Inflector::getDefault()->snake('test')); 24 | $this->assertEquals('test', Inflector::getDefault()->snake('test')); 25 | $this->assertEquals('expect100_continue', Inflector::getDefault()->snake('Expect100Continue')); 26 | } 27 | 28 | public function testCamel() 29 | { 30 | $this->assertEquals('CamelCase', Inflector::getDefault()->camel('camel_case')); 31 | $this->assertEquals('CamelCaseWords', Inflector::getDefault()->camel('camel_case_words')); 32 | $this->assertEquals('Test', Inflector::getDefault()->camel('test')); 33 | $this->assertEquals('Expect100Continue', ucfirst(Inflector::getDefault()->camel('expect100_continue'))); 34 | // Get from cache 35 | $this->assertEquals('Test', Inflector::getDefault()->camel('test', false)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Service/CachingConfigLoaderTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder('Guzzle\Service\ConfigLoaderInterface') 18 | ->setMethods(array('load')) 19 | ->getMockForAbstractClass(); 20 | $data = array('foo' => 'bar'); 21 | $loader->expects($this->once()) 22 | ->method('load') 23 | ->will($this->returnValue($data)); 24 | $cache = new CachingConfigLoader($loader, $cache); 25 | $this->assertEquals($data, $cache->load('foo')); 26 | $this->assertEquals($data, $cache->load('foo')); 27 | } 28 | 29 | public function testDoesNotCacheArrays() 30 | { 31 | $cache = new DoctrineCacheAdapter(new ArrayCache()); 32 | $loader = $this->getMockBuilder('Guzzle\Service\ConfigLoaderInterface') 33 | ->setMethods(array('load')) 34 | ->getMockForAbstractClass(); 35 | $data = array('foo' => 'bar'); 36 | $loader->expects($this->exactly(2)) 37 | ->method('load') 38 | ->will($this->returnValue($data)); 39 | $cache = new CachingConfigLoader($loader, $cache); 40 | $this->assertEquals($data, $cache->load(array())); 41 | $this->assertEquals($data, $cache->load(array())); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Cache/DefaultCacheKeyProvider.php: -------------------------------------------------------------------------------- 1 | getParams()->get(self::CACHE_KEY); 19 | 20 | if (!$key) { 21 | 22 | $cloned = clone $request; 23 | $cloned->removeHeader('Cache-Control'); 24 | 25 | // Check to see how and if the key should be filtered 26 | foreach (explode(';', $request->getParams()->get(self::CACHE_KEY_FILTER)) as $part) { 27 | $pieces = array_map('trim', explode('=', $part)); 28 | if (isset($pieces[1])) { 29 | foreach (array_map('trim', explode(',', $pieces[1])) as $remove) { 30 | if ($pieces[0] == 'header') { 31 | $cloned->removeHeader($remove); 32 | } elseif ($pieces[0] == 'query') { 33 | $cloned->getQuery()->remove($remove); 34 | } 35 | } 36 | } 37 | } 38 | 39 | $raw = (string) $cloned; 40 | $key = 'GZ' . md5($raw); 41 | $request->getParams()->set(self::CACHE_KEY, $key)->set(self::CACHE_KEY_RAW, $raw); 42 | } 43 | 44 | return $key; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/Guzzle/Tests/Service/Resource/ResourceIteratorClassFactoryTest.php: -------------------------------------------------------------------------------- 1 | registerNamespace('Baz'); 22 | $command = new MockCommand(); 23 | $factory->build($command); 24 | } 25 | 26 | public function testBuildsResourceIterators() 27 | { 28 | $factory = new ResourceIteratorClassFactory('Guzzle\Tests\Service\Mock\Model'); 29 | $command = new MockCommand(); 30 | $iterator = $factory->build($command, array('client.namespace' => 'Guzzle\Tests\Service\Mock')); 31 | $this->assertInstanceOf('Guzzle\Tests\Service\Mock\Model\MockCommandIterator', $iterator); 32 | } 33 | 34 | public function testChecksIfCanBuild() 35 | { 36 | $factory = new ResourceIteratorClassFactory('Guzzle\Tests\Service'); 37 | $this->assertFalse($factory->canBuild(new MockCommand())); 38 | $factory = new ResourceIteratorClassFactory('Guzzle\Tests\Service\Mock\Model'); 39 | $this->assertTrue($factory->canBuild(new MockCommand())); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Guzzle/Batch/FlushingBatch.php: -------------------------------------------------------------------------------- 1 | threshold = $threshold; 23 | parent::__construct($decoratedBatch); 24 | } 25 | 26 | /** 27 | * Set the auto-flush threshold 28 | * 29 | * @param int $threshold The auto-flush threshold 30 | * 31 | * @return FlushingBatch 32 | */ 33 | public function setThreshold($threshold) 34 | { 35 | $this->threshold = $threshold; 36 | 37 | return $this; 38 | } 39 | 40 | /** 41 | * Get the auto-flush threshold 42 | * 43 | * @return int 44 | */ 45 | public function getThreshold() 46 | { 47 | return $this->threshold; 48 | } 49 | 50 | public function add($item) 51 | { 52 | $this->decoratedBatch->add($item); 53 | if (++$this->currentTotal >= $this->threshold) { 54 | $this->currentTotal = 0; 55 | $this->decoratedBatch->flush(); 56 | } 57 | 58 | return $this; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Guzzle/Plugin/Backoff/CallbackBackoffStrategy.php: -------------------------------------------------------------------------------- 1 | callback = $callback; 34 | $this->decision = (bool) $decision; 35 | $this->next = $next; 36 | } 37 | 38 | public function makesDecision() 39 | { 40 | return $this->decision; 41 | } 42 | 43 | protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null) 44 | { 45 | return call_user_func($this->callback, $retries, $request, $response, $e); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Guzzle/Service/Command/DefaultResponseParser.php: -------------------------------------------------------------------------------- 1 | getRequest()->getResponse(); 31 | 32 | // Account for hard coded content-type values specified in service descriptions 33 | if ($contentType = $command['command.expects']) { 34 | $response->setHeader('Content-Type', $contentType); 35 | } else { 36 | $contentType = (string) $response->getHeader('Content-Type'); 37 | } 38 | 39 | return $this->handleParsing($command, $response, $contentType); 40 | } 41 | 42 | protected function handleParsing(CommandInterface $command, Response $response, $contentType) 43 | { 44 | $result = $response; 45 | if ($result->getBody()) { 46 | if (stripos($contentType, 'json') !== false) { 47 | $result = $result->json(); 48 | } if (stripos($contentType, 'xml') !== false) { 49 | $result = $result->xml(); 50 | } 51 | } 52 | 53 | return $result; 54 | } 55 | } 56 | --------------------------------------------------------------------------------