Skip to content

Commit

Permalink
Merge pull request #117 from hamburgscleanest/feature/upgrade-php8-l8
Browse files Browse the repository at this point in the history
Upgrade to PHP 8 and Laravel 8
  • Loading branch information
timopruesse committed Sep 21, 2021
2 parents d72d88f + f0b01e9 commit d27c636
Show file tree
Hide file tree
Showing 16 changed files with 5,081 additions and 1,948 deletions.
17 changes: 11 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
dist: focal
language: php
php:
- '7.2'
- '7.3'
- '8.0'
- 'nightly'
env:
global:
- XDEBUG_MODE=coverage
matrix:
allow_failures:
- php: nightly
fast_finish: true
services:
- redis
install:
- composer update
script:
./vendor/bin/phpunit --coverage-clover=coverage.clover
after_script:
- if [ "$TRAVIS_PHP_VERSION" == "7.3" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" == "7.3" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
- ./vendor/bin/phpunit --coverage-clover=coverage.clover
after_success:
- if [ "$TRAVIS_PHP_VERSION" == "8.0" ]; then composer global require scrutinizer/ocular; fi
- if [ "$TRAVIS_PHP_VERSION" == "8.0" ]; then composer global exec -v -- "ocular code-coverage:upload --format=php-clover coverage.clover"; fi
67 changes: 52 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,94 @@ All Notable changes to `laravel-guzzle-throttle` will be documented in this file

Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## Next
## Next

### Added

- Nothing

### Deprecated

- Nothing

### Fixed

- Nothing

### Removed

- Nothing

### Security

- Nothing

----------

## 5.0.0

### Added

- PHP 8 support
- Laravel 8 support

### Removed

- PHP 7 support
- Laravel 5/6 support

----------

## 4.1.1

### Security

This fixes a security vulnerabilities in `symfony/http-foundation` and `symfony/http-kernel`:

- https://github.com/FriendsOfPHP/security-advisories/blob/master/symfony/http-foundation/CVE-2019-18888.yaml
- https://github.com/FriendsOfPHP/security-advisories/blob/master/symfony/http-kernel/CVE-2019-18887.yaml
- <https://github.com/FriendsOfPHP/security-advisories/blob/master/symfony/http-foundation/CVE-2019-18888.yaml>
- <https://github.com/FriendsOfPHP/security-advisories/blob/master/symfony/http-kernel/CVE-2019-18887.yaml>

### Other

Set default value of `ttl` to `900` instead of `null` in `ConfigHelper::getRequestLimitRuleset`.

----------

## 4.1.0

### Compatibility

Ensure compatibility to `Laravel 6.0`.

----------

## 4.0.2

### Fixed

The facade was wrongly defined as `GuzzleThrottle` instead of `LaravelGuzzleThrottle` in the `composer.json`.

----------

## 4.0.1

### Security

This fixes a security vulnerability in `symfony/http-foundation`:

https://github.com/FriendsOfPHP/security-advisories/blob/master/symfony/http-foundation/CVE-2019-10913.yaml
<https://github.com/FriendsOfPHP/security-advisories/blob/master/symfony/http-foundation/CVE-2019-10913.yaml>

----------

## 4.0.0

### Added

- Compatibility with Laravel / Illuminate 5.8
- Upgraded PHPUnit to version 8

### Removed

- Dropped support for PHP 7.1

----------
Expand All @@ -91,7 +117,8 @@ Changed visibility of `ConfigHelper::getMiddlewareConfig` to public.
## 3.0.1

### Fixed
The use of new HandlerStack was breaking the possibility to use a shared cookie jar by passing cookies => true in the GuzzleClient constructor (http://docs.guzzlephp.org/en/stable/quickstart.html#cookies).

The use of new HandlerStack was breaking the possibility to use a shared cookie jar by passing cookies => true in the GuzzleClient constructor (<http://docs.guzzlephp.org/en/stable/quickstart.html#cookies>).

Thanks @remipou!

Expand All @@ -106,6 +133,7 @@ This release adds compatibility with Laravel 5.7 (Illuminate).
## 2.0.9

### Improvement

The order of request parameters is now irrelevant for the cache.
If the values of the parameters are the same, the requests will be treated as the same, too.

Expand All @@ -119,57 +147,65 @@ the cache will know that it yields the same response as `/test?b=2&a=1`.
Bump version of `hamburgscleanest/guzzle-advanced-throttle` to include a bugfix.

### Fixed

- The request count was not properly reset because `RateLimiter::getCurrentRequestCount()` wasn't used internally.

Thanks to @huisman303 for finding this!

----------

## 2.0.7
## 2.0.7

### General

- Set the default cache driver to `CACHE_DRIVER` defined in the `.env` file instead of `default`.

----------

## 2.0.6

### Fixed
- Fixed issue in Redis driver

- Fixed issue in Redis driver

----------

## 2.0.5
## 2.0.5

### General

- It's now easier to use the `ConfigHelper` when using `laravel-guzzle-throttle` inside of other packages.

----------

## 2.0.4
## 2.0.4

### Fixed

Example configuration was still in the old format. Updated example configuration to match version 2.0 specifications.

----------

## 2.0.3

### Optimization

- Made sure that the Advanced Guzzle Throttle middleware is executed before any other middleware.

----------

## 2.0.2
## 2.0.2

### Fixed

- Fixed problems with Laravel cache drivers

----------

## 2.0.1

### Fixed

- Fixed problem in composer.json of Advanced Guzzle Throttle

----------
Expand All @@ -179,6 +215,7 @@ Example configuration was still in the old format. Updated example configuration
This version adds support for Guzzle Advanced Throttle 2.0.0.

### Added

- Host wildcards: [WILDCARDS](https://github.com/hamburgscleanest/guzzle-advanced-throttle/blob/master/README.md#wildcards)
- More flexible configuration: [USAGE](https://github.com/hamburgscleanest/guzzle-advanced-throttle#usage)

Expand All @@ -196,9 +233,9 @@ This version adds support for Guzzle Advanced Throttle 2.0.0.

### Added

Also made `ConfigHelper::getConfigName(string $driverName) ` public now.
Also made `ConfigHelper::getConfigName(string $driverName)` public now.

It returns the key (in the subset `stores`) of the Laravel cache configuration.
It returns the key (in the subset `stores`) of the Laravel cache configuration.
Default will return the key of the actual driver that is defined as the default.

----------
Expand All @@ -209,16 +246,16 @@ Default will return the key of the actual driver that is defined as the default.

`ConfigHelper::getConfigForDriver(string $driverName)` is now a public method.

It returns the configuration (cache config file of Laravel) of the given driver.
It is also possible to pass `default` to that method which returns the default driver configuration.
It returns the configuration (cache config file of Laravel) of the given driver.
It is also possible to pass `default` to that method which returns the default driver configuration.

----------

## 1.0.1

### Added

You can now provide a custom ruleset in the constructor.
You can now provide a custom ruleset in the constructor.
It is intended to make it easier to use it within another package without the need of the config file (and to avoid conflicts).

----------
Expand Down
38 changes: 17 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
[![Quality Score][ico-code-quality]][link-code-quality]
[![Total Downloads][ico-downloads]][link-downloads]

A Laravel (>= 5.5) wrapper for [Guzzle Advanced Throttle](https://github.com/hamburgscleanest/guzzle-advanced-throttle).
A Laravel (>= 8.0) wrapper for [Guzzle Advanced Throttle](https://github.com/hamburgscleanest/guzzle-advanced-throttle).

## Install

Via Composer

``` bash
$ composer require hamburgscleanest/laravel-guzzle-throttle
composer require hamburgscleanest/laravel-guzzle-throttle
```


----------

### Automatic Package Discovery
Expand All @@ -31,7 +30,7 @@ Everything is automatically registered for you.
Publish the config to get the example configuration.

``` bash
$ php artisan vendor:publish
php artisan vendor:publish
```

----------
Expand Down Expand Up @@ -76,22 +75,18 @@ $ php artisan vendor:publish
];
```

> Make sure the host name does not end with a trailing slash.
> It should be `https://www.google.com` not `https://www.google.com/`.
----------

### Usage

Using the preconfigured client is super easy.
You just have to instantiate your client like this:
To use the pre-configured client, you have to instantiate your client like this:

``` php
// returns an instance of GuzzleHttp\Client
$client = LaravelGuzzleThrottle::client(['base_uri' => 'https://www.google.com']);
```

After that you can use all off the usual `GuzzleHttp\Client` methods, e.g.
After that, you can use all of the usual `GuzzleHttp\Client` methods, e.g.

``` php
$client->get('/test'));
Expand All @@ -100,7 +95,7 @@ $client->get('/test'));
### Add other middlewares

You can still add other middlewares to the stack, too.
Just define your stack as usual and then pass it to the throttled client:
Define your stack as usual and then pass it to the throttled client:

``` php
$stack = HandlerStack::create(new CurlHandler());
Expand All @@ -119,40 +114,41 @@ The client will 'automatically' add every other middleware to the top of the sta

#### Beforehand

Responses with an error status code `4xx` or `5xx` will not be cached (even with `force-cache` enabled)!
Responses with an error status code `4xx` or `5xx` are not cached (even with `force-cache` enabled)!
Note: Also, `3xx` redirect codes are not cached.

----------

#### Supported drivers

For now the following drivers are officially supported `File`, `Redis` and `Memcached`.
The following drivers are officially supported: [File](https://github.com/hamburgscleanest/guzzle-advanced-throttle#file), [Redis](https://github.com/hamburgscleanest/guzzle-advanced-throttle#redis) and [Memcached](https://github.com/hamburgscleanest/guzzle-advanced-throttle#memcached).

The configuration for the drivers can be seen in the [middleware repository](https://github.com/hamburgscleanest/guzzle-advanced-throttle#laravel-drivers).

----------

#### Options

##### Without caching - `no-cache`

Just throttle the requests. No caching is done. When the limit is exceeded, a `429 - Too Many Requests` exception will be thrown.
Just throttle the requests and don't cache them. When the limit is exceeded, a `429 - Too Many Requests` exception is thrown.

----------

##### With caching (default) - `cache`

Use cached responses when your defined rate limit is exceeded. The middleware will try to fallback to a cached response before throwing `429 - Too Many Requests`.
Use cached responses when your defined rate limit is exceeded. The middleware tries to fall back to a cached response before throwing a `429 - Too Many Requests` exception.

----------

##### With forced caching - `force-cache`

Always use cached responses when available to spare your rate limits. As long as there is a response in cache for the current request it will return the cached response. It will only actually send the request when it is not cached. If there is no cached response and the request limits are exceeded, it will throw `429 - Too Many Requests`.
Always uses the cached responses when available to spare your rate limits. It only sends the request when it is not cached. If there is no cached response and the request limits are exceeded, it falls back to throwing a `429 - Too Many Requests` exception.

----------

### Wildcards

> Available in version 2.x.x and higher
If you want to define the same rules for multiple different hosts, you can use wildcards.
A possible use case can be subdomains:

Expand All @@ -167,7 +163,7 @@ $rules = new RequestLimitRuleset([
]);
```

This `host` will match `https://www.en.mysite.com`, `https://www.de.mysite.com`, `https://www.fr.mysite.com`, etc.
This `host` matches `https://www.en.mysite.com`, `https://www.de.mysite.com`, `https://www.fr.mysite.com`, etc.

----------

Expand All @@ -184,7 +180,7 @@ Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed re
## Testing

``` bash
$ composer test
composer test
```

## Contributing
Expand All @@ -193,7 +189,7 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT

## Security

If you discover any security related issues, please email chroma91@gmail.com instead of using the issue tracker.
If you discover any security-related issues, please email chroma91@gmail.com instead of using the issue tracker.

## Credits

Expand Down
Loading

0 comments on commit d27c636

Please sign in to comment.