Skip to content
This repository was archived by the owner on Jun 23, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Api/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,11 @@ public function getMethod()
public function exec()
{
$response = $this->sendRequest();
$this->eventDispatcher->dispatch('chaplean_api_client.request_executed', new RequestExecutedEvent($response, $this->apiName));
if (class_exists(\Symfony\Contracts\EventDispatcher\Event::class)) {
$this->eventDispatcher->dispatch(new RequestExecutedEvent($response, $this->apiName), 'chaplean_api_client.request_executed');
} else {
$this->eventDispatcher->dispatch('chaplean_api_client.request_executed', new RequestExecutedEvent($response, $this->apiName));
}

return $response;
}
Expand Down
8 changes: 8 additions & 0 deletions ChapleanApiClientBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Chaplean\Bundle\ApiClientBundle;

use Chaplean\Bundle\ApiClientBundle\DependencyInjection\Compiler\WireMailerCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
Expand All @@ -14,4 +16,10 @@
*/
class ChapleanApiClientBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);

$container->addCompilerPass(new WireMailerCompilerPass());
}
}
1 change: 1 addition & 0 deletions DependencyInjection/ChapleanApiClientExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Chaplean\Bundle\ApiClientBundle\DependencyInjection;

use Chaplean\Bundle\ApiClientBundle\DependencyInjection\CompilerPass\WireMailerCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
Expand Down
31 changes: 31 additions & 0 deletions DependencyInjection/Compiler/WireMailerCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php


namespace Chaplean\Bundle\ApiClientBundle\DependencyInjection\Compiler;

use Chaplean\Bundle\ApiClientBundle\Utility\EmailUtilityInterface;
use Chaplean\Bundle\ApiClientBundle\Utility\SwiftMailerEmailUtility;
use Chaplean\Bundle\ApiClientBundle\Utility\SymfonyMailerEmailUtility;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class WireMailerCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
// we need to decide which mailer we want to use
if ($container->hasAlias('swiftmailer.mailer.abstract')) {
$container->removeDefinition(SymfonyMailerEmailUtility::class);
$container->setAlias(
EmailUtilityInterface::class,
SwiftMailerEmailUtility::class
);
} else {
$container->removeDefinition(SwiftMailerEmailUtility::class);
$container->setAlias(
EmailUtilityInterface::class,
SymfonyMailerEmailUtility::class
);
}
}
}
17 changes: 15 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('chaplean_api_client');
$treeBuilder = new TreeBuilder('chaplean_api_client');
$rootNode = $this->getRootNode($treeBuilder);

$rootNode->children()
->arrayNode('email_logging')
Expand Down Expand Up @@ -160,4 +160,17 @@ public function addLoggingNode(ArrayNodeDefinition $rootNode, string $nodeName)
->end()
->end();
}

/**
* @param TreeBuilder $treeBuilder
* @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition
*/
protected function getRootNode(TreeBuilder $treeBuilder)
{
if (method_exists($treeBuilder, 'getRootNode')) {
return $treeBuilder->getRootNode();
}

return $treeBuilder->root('chaplean_api_client');;
}
}
130 changes: 91 additions & 39 deletions Event/RequestExecutedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,107 @@
namespace Chaplean\Bundle\ApiClientBundle\Event;

use Chaplean\Bundle\ApiClientBundle\Api\ResponseInterface;
use Symfony\Component\EventDispatcher\Event;

/**
* Class RequestExecutedEvent.
*
* @package Chaplean\Bundle\ApiClientBundle\Event
* @author Matthias - Chaplean <matthias@chaplean.coop>
* @copyright 2018 Chaplean (http://www.chaplean.coop)
* @since 1.0.0
*/
class RequestExecutedEvent extends Event
{
/**
* @var string
*/
protected $apiName;

/**
* @var ResponseInterface
*/
protected $response;

if (class_exists(\Symfony\Contracts\EventDispatcher\Event::class)) {
/**
* RequestExecutedEvent constructor.
* Class RequestExecutedEvent.
*
* @param ResponseInterface $response
* @param string $apiName
* @package Chaplean\Bundle\ApiClientBundle\Event
* @author Matthias - Chaplean <matthias@chaplean.coop>
* @copyright 2018 Chaplean (http://www.chaplean.coop)
* @since 1.0.0
*/
public function __construct(ResponseInterface $response, string $apiName)
class RequestExecutedEvent extends \Symfony\Contracts\EventDispatcher\Event
{
$this->apiName = $apiName;
$this->response = $response;
}
/**
* @var string
*/
protected $apiName;

/**
* @var ResponseInterface
*/
protected $response;

/**
* RequestExecutedEvent constructor.
*
* @param ResponseInterface $response
* @param string $apiName
*/
public function __construct(ResponseInterface $response, string $apiName)
{
$this->apiName = $apiName;
$this->response = $response;
}

/**
* Returns request's response
*
* @return ResponseInterface
*/
public function getResponse(): ResponseInterface
{
return $this->response;
}

/**
* @return string
*/
public function getApiName(): string
{
return $this->apiName;
}
}
} elseif (class_exists(\Symfony\Component\EventDispatcher\Event::class)) {
/**
* Returns request's response
* Class RequestExecutedEvent.
*
* @return ResponseInterface
* @package Chaplean\Bundle\ApiClientBundle\Event
* @author Matthias - Chaplean <matthias@chaplean.coop>
* @copyright 2018 Chaplean (http://www.chaplean.coop)
* @since 1.0.0
*/
public function getResponse(): ResponseInterface
class RequestExecutedEvent extends \Symfony\Component\EventDispatcher\Event
{
return $this->response;
}
/**
* @var string
*/
protected $apiName;

/**
* @return string
*/
public function getApiName(): string
{
return $this->apiName;
/**
* @var ResponseInterface
*/
protected $response;

/**
* RequestExecutedEvent constructor.
*
* @param ResponseInterface $response
* @param string $apiName
*/
public function __construct(ResponseInterface $response, string $apiName)
{
$this->apiName = $apiName;
$this->response = $response;
}

/**
* Returns request's response
*
* @return ResponseInterface
*/
public function getResponse(): ResponseInterface
{
return $this->response;
}

/**
* @return string
*/
public function getApiName(): string
{
return $this->apiName;
}
}
}
8 changes: 4 additions & 4 deletions EventListener/RequestExecutedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Chaplean\Bundle\ApiClientBundle\Event\RequestExecutedEvent;
use Chaplean\Bundle\ApiClientBundle\Utility\ApiLogUtility;
use Chaplean\Bundle\ApiClientBundle\Utility\EmailUtility;
use Chaplean\Bundle\ApiClientBundle\Utility\EmailUtilityInterface;

/**
* Class RequestExecutedListenerTest.
Expand All @@ -22,17 +22,17 @@ class RequestExecutedListener
protected $apiLogUtility;

/**
* @var EmailUtility
* @var EmailUtilityInterface
*/
protected $emailUtility;

/**
* RequestExecutedListener constructor.
*
* @param ApiLogUtility $apiLogUtility
* @param EmailUtility $emailUtility
* @param EmailUtilityInterface $emailUtility
*/
public function __construct(ApiLogUtility $apiLogUtility, EmailUtility $emailUtility)
public function __construct(ApiLogUtility $apiLogUtility, EmailUtilityInterface $emailUtility)
{
$this->apiLogUtility = $apiLogUtility;
$this->emailUtility = $emailUtility;
Expand Down
5 changes: 3 additions & 2 deletions Query/ApiLogQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Chaplean\Bundle\ApiClientBundle\Entity\ApiLog;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bridge\Doctrine\RegistryInterface;

/**
Expand All @@ -24,9 +25,9 @@ class ApiLogQuery
/**
* ApiLogQuery constructor.
*
* @param RegistryInterface $registry
* @param RegistryInterface|ManagerRegistry $registry
*/
public function __construct(RegistryInterface $registry)
public function __construct(/** ManagerRegistry */$registry)
{
$this->em = $registry->getManager();
}
Expand Down
8 changes: 7 additions & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ services:
$parameters: '%chaplean_api_client.config%'
$registry: '@?doctrine'

Chaplean\Bundle\ApiClientBundle\Utility\EmailUtility:
Chaplean\Bundle\ApiClientBundle\Utility\SwiftMailerEmailUtility:
arguments:
$parameters: '%chaplean_api_client.config%'
$mailer: '@?mailer'
$translator: '@?translator'
$templating: '@?templating.engine.twig'

Chaplean\Bundle\ApiClientBundle\Utility\SymfonyMailerEmailUtility:
arguments:
$parameters: '%chaplean_api_client.config%'
$mailer: '@?mailer'
$translator: '@?translator'

Chaplean\Bundle\ApiClientBundle\Command\ChapleanApiLogCleanCommand: ~
2 changes: 1 addition & 1 deletion Tests/Api/AbstractApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AbstractApiTest extends TestCase
/**
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion Tests/Api/FakeApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FakeApiTest extends TestCase
/**
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion Tests/Api/GlobalParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class GlobalParametersTest extends TestCase
/**
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion Tests/Api/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class RouteTest extends TestCase
/**
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion Tests/Command/ChapleanApiLogCleanCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ChapleanApiLogCleanCommandTest extends MockeryTestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
5 changes: 3 additions & 2 deletions Tests/EventListener/RequestExecutedListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Chaplean\Bundle\ApiClientBundle\EventListener\RequestExecutedListener;
use Chaplean\Bundle\ApiClientBundle\Utility\EmailUtility;
use Chaplean\Bundle\ApiClientBundle\Utility\ApiLogUtility;
use Chaplean\Bundle\ApiClientBundle\Utility\SwiftMailerEmailUtility;
use GuzzleHttp\Psr7\Response;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use Mockery\MockInterface;
Expand Down Expand Up @@ -34,10 +35,10 @@ class RequestExecutedListenerTest extends MockeryTestCase
/**
* @return void
*/
public function setUp()
public function setUp(): void
{
$this->apiLogUtility = \Mockery::mock(ApiLogUtility::class);
$this->emailUtility = \Mockery::mock(EmailUtility::class);
$this->emailUtility = \Mockery::mock(SwiftMailerEmailUtility::class);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Tests/Query/ApiLogQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ApiLogQueryTest extends MockeryTestCase
/**
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
Loading