Skip to content

Commit

Permalink
Merge 5dfe587 into 88b4e1d
Browse files Browse the repository at this point in the history
  • Loading branch information
gregurco committed Jul 13, 2020
2 parents 88b4e1d + 5dfe587 commit 7722f51
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 80 deletions.
27 changes: 13 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ language: php
sudo: false

php:
- 7.0
- 7.1
- 7.2
- nightly
- 7.3
- 7.4

env:
- SYMFONY_VERSION=2.7.* # LTS
- SYMFONY_VERSION=2.8.* # LTS
- SYMFONY_VERSION=3.2.*
- SYMFONY_VERSION=3.3.*
- SYMFONY_VERSION=3.4.* # LTS
- SYMFONY_VERSION=4.0.*
- SYMFONY_VERSION=4.4.* # LTS (until 11/2023)
- SYMFONY_VERSION=5.0.* # (until 07/2020)
- SYMFONY_VERSION=5.1.* # (until 01/2021)

cache:
directories:
Expand All @@ -27,20 +24,22 @@ before_install:

install:
- composer update
- vendor/bin/simple-phpunit install

script:
- mkdir -p build/logs
- php vendor/bin/phpunit --coverage-text
- composer validate --strict --no-check-lock
- vendor/bin/simple-phpunit --coverage-text --verbose

after_success:
- travis_retry php vendor/bin/coveralls
- travis_retry php vendor/bin/php-coveralls

matrix:
exclude:
- php: 7
env: SYMFONY_VERSION=4.0.* # requires PHP ^7.1.3
- php: 7
env: SYMFONY_VERSION=dev-master # requires PHP ^7.1.3
- php: 7.1
env: SYMFONY_VERSION=5.0.* # requires PHP ^7.2.5
- php: 7.1
env: SYMFONY_VERSION=5.1.* # requires PHP ^7.2.5
allow_failures:
- php: nightly
- env: SYMFONY_VERSION=dev-master
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@

"require": {
"php": "^7.0",
"guzzlehttp/guzzle": "^6.0",
"eightpoints/guzzle-bundle": "~7.0",
"symfony/http-kernel": "~2.7|~3.0|~4.0",
"symfony/config": "~2.7|~3.0|~4.0",
"symfony/dependency-injection": "~2.7|~3.0|~4.0",
"symfony/expression-language": "~2.7|~3.0|~4.0",
"guzzlehttp/guzzle": "~6.0|~7.0",
"eightpoints/guzzle-bundle": "~8.0",
"symfony/http-kernel": "~4.0|~5.0",
"symfony/config": "~4.0|~5.0",
"symfony/dependency-injection": "~4.0|~5.0",
"symfony/expression-language": "~4.0|~5.0",
"kevinrob/guzzle-cache-middleware": "~3.0"
},

"require-dev": {
"phpunit/phpunit": "~6.1",
"satooshi/php-coveralls": "~1.0"
"symfony/phpunit-bridge": "~4.0|~5.0",
"php-coveralls/php-coveralls": "~2.2"
},

"autoload": {
Expand Down
171 changes: 120 additions & 51 deletions src/Event/InvalidateRequestEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,140 @@
namespace Gregurco\Bundle\GuzzleBundleCachePlugin\Event;

use Psr\Http\Message\UriInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\Event as BaseEvent;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Contracts\EventDispatcher\Event as ContractsBaseEvent;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7;
use GuzzleHttp\Psr7\Request;

class InvalidateRequestEvent extends Event
{
/** @var Client */
protected $client;
if (is_subclass_of(EventDispatcher::class, EventDispatcherInterface::class)) {
class InvalidateRequestEvent extends ContractsBaseEvent
{
/** @var Client */
protected $client;

/** @var string */
protected $method;
/** @var string */
protected $method;

/** @var string */
protected $uri;
/** @var string */
protected $uri;

/**
* @param Client $client
* @param string $method
* @param string $uri
*/
public function __construct(Client $client, string $method, string $uri)
{
$this->client = $client;
$this->method = $method;
$this->uri = $uri;
}
/**
* @param Client $client
* @param string $method
* @param string $uri
*/
public function __construct(Client $client, string $method, string $uri)
{
$this->client = $client;
$this->method = $method;
$this->uri = $uri;
}

/**
* @return Client
*/
public function getClient(): Client
{
return $this->client;
}
/**
* @return Client
*/
public function getClient(): Client
{
return $this->client;
}

/**
* @return string
*/
public function getMethod(): string
{
return $this->method;
}
/**
* @return string
*/
public function getMethod(): string
{
return $this->method;
}

/**
* @return string
*/
public function getUri(): string
{
return $this->uri;
}
/**
* @return string
*/
public function getUri(): string
{
return $this->uri;
}

/**
* @return Request
*/
public function getRequest(): Request
{
$baseUri = $this->client->getConfig('base_uri');

/**
* @return Request
*/
public function getRequest(): Request
if ($baseUri instanceof UriInterface) {
$uri = Psr7\UriResolver::resolve($baseUri, Psr7\uri_for($this->uri));
} else {
$uri = $this->uri;
}

return new Request($this->method, $uri);
}
}
} else {
class InvalidateRequestEvent extends BaseEvent
{
$baseUri = $this->client->getConfig('base_uri');
/** @var Client */
protected $client;

/** @var string */
protected $method;

/** @var string */
protected $uri;

/**
* @param Client $client
* @param string $method
* @param string $uri
*/
public function __construct(Client $client, string $method, string $uri)
{
$this->client = $client;
$this->method = $method;
$this->uri = $uri;
}

if ($baseUri instanceof UriInterface) {
$uri = Psr7\UriResolver::resolve($baseUri, Psr7\uri_for($this->uri));
} else {
$uri = $this->uri;
/**
* @return Client
*/
public function getClient(): Client
{
return $this->client;
}

return new Request($this->method, $uri);
/**
* @return string
*/
public function getMethod(): string
{
return $this->method;
}

/**
* @return string
*/
public function getUri(): string
{
return $this->uri;
}

/**
* @return Request
*/
public function getRequest(): Request
{
$baseUri = $this->client->getConfig('base_uri');

if ($baseUri instanceof UriInterface) {
$uri = Psr7\UriResolver::resolve($baseUri, Psr7\uri_for($this->uri));
} else {
$uri = $this->uri;
}

return new Request($this->method, $uri);
}
}
}
10 changes: 5 additions & 5 deletions src/GuzzleBundleCachePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Gregurco\Bundle\GuzzleBundleCachePlugin;

use EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundlePlugin;
use EightPoints\Bundle\GuzzleBundle\PluginInterface;
use Gregurco\Bundle\GuzzleBundleCachePlugin\DependencyInjection\GuzzleCacheExtension;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -11,13 +11,13 @@
use Symfony\Component\ExpressionLanguage\Expression;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class GuzzleBundleCachePlugin extends Bundle implements EightPointsGuzzleBundlePlugin
class GuzzleBundleCachePlugin extends Bundle implements PluginInterface
{
/**
* @param array $configs
* @param ContainerBuilder $container
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$extension = new GuzzleCacheExtension();
$extension->load($configs, $container);
Expand All @@ -29,7 +29,7 @@ public function load(array $configs, ContainerBuilder $container)
* @param string $clientName
* @param Definition $handler
*/
public function loadForClient(array $config, ContainerBuilder $container, string $clientName, Definition $handler)
public function loadForClient(array $config, ContainerBuilder $container, string $clientName, Definition $handler): void
{
if ($config['enabled']) {
$cacheMiddlewareDefinitionName = sprintf('guzzle_bundle_cache_plugin.middleware.%s', $clientName);
Expand Down Expand Up @@ -57,7 +57,7 @@ public function loadForClient(array $config, ContainerBuilder $container, string
/**
* @param ArrayNodeDefinition $pluginNode
*/
public function addConfiguration(ArrayNodeDefinition $pluginNode)
public function addConfiguration(ArrayNodeDefinition $pluginNode): void
{
$pluginNode
->canBeEnabled()
Expand Down
4 changes: 2 additions & 2 deletions tests/GuzzleBundleCachePluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Gregurco\Bundle\GuzzleBundleCachePlugin\Test;

use EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundlePlugin;
use EightPoints\Bundle\GuzzleBundle\PluginInterface;
use Gregurco\Bundle\GuzzleBundleCachePlugin\EventListener\InvalidateRequestSubscriber;
use Gregurco\Bundle\GuzzleBundleCachePlugin\GuzzleBundleCachePlugin;
use GuzzleHttp\Client;
Expand All @@ -28,7 +28,7 @@ public function setUp()

public function testSubClassesOfPlugin()
{
$this->assertInstanceOf(EightPointsGuzzleBundlePlugin::class, $this->plugin);
$this->assertInstanceOf(PluginInterface::class, $this->plugin);
$this->assertInstanceOf(Bundle::class, $this->plugin);
}

Expand Down

0 comments on commit 7722f51

Please sign in to comment.