Skip to content

Commit

Permalink
Add support for Laravel 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sebdesign committed Sep 2, 2019
1 parent 007d537 commit 6e77115
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 125 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
language: php

php:
- 5.5.9
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to `artisan-cloudflare` will be documented in this file.

## 2.0.0 - 2019-09-02

- Add support for Laravel 6.0
- Drop support for Laravel <5.5 and PHP <7.1

## 1.3.0 - 2019-02-15

- Add support for Laravel 5.8
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
}
],
"require": {
"php": "^5.5.9|^7.0",
"php": "^7.1",
"guzzlehttp/guzzle": "^6.0",
"illuminate/console": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0",
"illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0"
"illuminate/console": "^5.5|^6.0",
"illuminate/support": "^5.5|^6.0"
},
"require-dev": {
"mockery/mockery": "^0.9|^1.0",
"orchestra/testbench": "3.1.*|3.2.*|3.3.*|3.4.*|3.5.*|3.6.*|3.7.*|3.8.*|3.9.*",
"phpunit/phpunit": "^4.8|^5.0|^6.0|^7.0"
"orchestra/testbench": "^3.5",
"phpunit/phpunit": "^7.0|^8.0"
},
"autoload": {
"psr-4": {
Expand Down
66 changes: 42 additions & 24 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,28 @@ public function __construct(GuzzleClient $client, LoggerInterface $logger)
* The promise waits until all the promises have been resolved or rejected
* and returns the results of each request.
*
* @param \Illuminate\Support\Collection|array[] $parameters
* @return \Illuminate\Support\Collection|\stdClass[]
* @param \Illuminate\Support\Collection<string,\Sebdesign\ArtisanCloudflare\Zone> $zones
* @return \Illuminate\Support\Collection<string,\Sebdesign\ArtisanCloudflare\Zone>
*/
public function purge(Collection $parameters)
public function purge($zones)
{
$promises = $parameters->map(function ($parameters, $identifier) {
return $this->client->deleteAsync("zones/{$identifier}/purge_cache", [
\GuzzleHttp\RequestOptions::JSON => $parameters,
]);
});
return $zones->map(function (Zone $zone, $identifier) {
return $this->delete($identifier, $zone);
})->pipe(function ($promises) {
return $this->settle($promises);
})->wait();
}

return $this->settle($promises)->wait();
/**
* @param string $identifier
* @param \Sebdesign\ArtisanCloudflare\Zone $zone
* @return \GuzzleHttp\Promise\PromiseInterface
*/
protected function delete($identifier, Zone $zone)
{
return $this->client->deleteAsync("zones/{$identifier}/purge_cache", [
\GuzzleHttp\RequestOptions::JSON => $zone,
]);
}

/**
Expand All @@ -67,15 +77,15 @@ public function purge(Collection $parameters)
*
* The returned promise is fulfilled with a collection of results.
*
* @param \Illuminate\Support\Collection|\GuzzleHttp\Promise\PromiseInterface[] $promises
* @param \Illuminate\Support\Collection<string,\GuzzleHttp\Promise\PromiseInterface> $promises
* @return \GuzzleHttp\Promise\PromiseInterface
*/
protected function settle(Collection $promises)
{
$results = collect();
$results = new Collection();

return Promise\each(
$promises->toArray(),
$promises->getIterator(),
$this->onFulfilled($results),
$this->onRejected($results)
)->then(function () use ($results) {
Expand All @@ -86,11 +96,16 @@ protected function settle(Collection $promises)
/**
* Put the body of the fulfilled promise into the results.
*
* @param \Illuminate\Support\Collection|object[] $results
* @param \Illuminate\Support\Collection<string,\Sebdesign\ArtisanCloudflare\Zone> $results
* @return \Closure
*/
protected function onFulfilled(Collection $results)
protected function onFulfilled($results)
{
/**
* @param \Psr\Http\Message\ResponseInterface $response
* @param string $identifier
* @return \Illuminate\Support\Collection<string,\Sebdesign\ArtisanCloudflare\Zone>
*/
return function ($response, $identifier) use ($results) {
return $results->put($identifier, $this->getBody($response));
};
Expand All @@ -99,11 +114,16 @@ protected function onFulfilled(Collection $results)
/**
* Handle the rejected promise and put the errors into the results.
*
* @param \Illuminate\Support\Collection|object[] $results
* @param \Illuminate\Support\Collection<string,\Sebdesign\ArtisanCloudflare\Zone> $results
* @return \Closure
*/
protected function onRejected(Collection $results)
protected function onRejected($results)
{
/**
* @param \GuzzleHttp\Exception\RequestException $reason
* @param string $identifier
* @return \Illuminate\Support\Collection<string,\Sebdesign\ArtisanCloudflare\Zone>
*/
return function ($reason, $identifier) use ($results) {
$this->logger->error($reason->getMessage(), [
'zone' => $identifier,
Expand All @@ -118,7 +138,7 @@ protected function onRejected(Collection $results)
* Transform a request exception into a result object.
*
* @param \GuzzleHttp\Exception\RequestException $e
* @return \stdClass
* @return \Sebdesign\ArtisanCloudflare\Zone
*/
protected function handleException(RequestException $e)
{
Expand All @@ -135,28 +155,26 @@ protected function handleException(RequestException $e)
$message = $e->getMessage();
}

$result = [
return new Zone([
'success' => false,
'errors' => [
(object) [
[
'code' => $e->getCode(),
'message' => $message,
],
],
];

return (object) $result;
]);
}

/**
* Transform the response body into a result object.
*
* @param \Psr\Http\Message\ResponseInterface $response
* @return \stdClass
* @return \Sebdesign\ArtisanCloudflare\Zone
*/
protected function getBody(ResponseInterface $response)
{
return json_decode($response->getBody(), false);
return new Zone(json_decode($response->getBody(), true));
}

/**
Expand Down
Loading

0 comments on commit 6e77115

Please sign in to comment.