Skip to content

Commit

Permalink
Merge pull request #600 from api-platform/rename_events
Browse files Browse the repository at this point in the history
Rename events
  • Loading branch information
dunglas authored Jul 7, 2016
2 parents 43b7cb2 + 7921edd commit 4774609
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 59 deletions.
13 changes: 7 additions & 6 deletions src/Bridge/Symfony/Bundle/Resources/config/api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,43 +53,44 @@

<!-- Event listeners -->

<service id="api_platform.listener.request.format" class="ApiPlatform\Core\EventListener\FormatListener">
<service id="api_platform.listener.request.add_format" class="ApiPlatform\Core\EventListener\AddFormatListener">
<argument type="service" id="api_platform.negotiator" />
<argument>%api_platform.formats%</argument>

<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="7" />
</service>

<!-- kernel.request piorities must be >8 to be executed after the firewall -->
<service id="api_platform.listener.request.data_provider" class="ApiPlatform\Core\EventListener\DataProviderListener">
<service id="api_platform.listener.request.read" class="ApiPlatform\Core\EventListener\ReadListener">
<argument type="service" id="api_platform.collection_data_provider" />
<argument type="service" id="api_platform.item_data_provider" />

<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="4" />
</service>

<service id="api_platform.listener.request.deserializer" class="ApiPlatform\Core\EventListener\DeserializerListener">
<service id="api_platform.listener.request.deserialize" class="ApiPlatform\Core\EventListener\DeserializeListener">
<argument type="service" id="api_platform.serializer" />
<argument type="service" id="api_platform.serializer.context_builder" />

<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="2" />
</service>

<service id="api_platform.listener.view.validator" class="ApiPlatform\Core\Bridge\Symfony\Validator\EventListener\ValidatorListener">
<service id="api_platform.listener.view.validate" class="ApiPlatform\Core\Bridge\Symfony\Validator\EventListener\ValidateListener">
<argument type="service" id="validator" />
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />

<tag name="kernel.event_listener" event="kernel.view" method="onKernelView" priority="64" />
<tag name="kernel.event_listener" event="kernel.view" method="onKernelView" priority="64" />
</service>

<service id="api_platform.listener.view.serializer" class="ApiPlatform\Core\EventListener\SerializerListener">
<service id="api_platform.listener.view.serialize" class="ApiPlatform\Core\EventListener\SerializeListener">
<argument type="service" id="api_platform.serializer" />
<argument type="service" id="api_platform.serializer.context_builder" />

<tag name="kernel.event_listener" event="kernel.view" method="onKernelView" priority="16" />
</service>

<service id="api_platform.listener.view.responder" class="ApiPlatform\Core\EventListener\ResponderListener">
<service id="api_platform.listener.view.respond" class="ApiPlatform\Core\EventListener\RespondListener">
<tag name="kernel.event_listener" event="kernel.view" method="onKernelView" priority="8" />
</service>

Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Symfony/Bundle/Resources/config/hydra.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<!-- Event listeners -->

<service id="api_platform.hydra.listener.response.link_header" class="ApiPlatform\Core\Hydra\EventListener\LinkHeaderListener">
<service id="api_platform.hydra.listener.response.add_link_header" class="ApiPlatform\Core\Hydra\EventListener\AddLinkHeaderListener">
<argument type="service" id="api_platform.router" />

<tag name="kernel.event_listener" event="kernel.response" method="onKernelResponse" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
final class ValidatorListener
final class ValidateListener
{
private $validator;
private $resourceMetadataFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
final class FormatListener
final class AddFormatListener
{
private $negotiator;
private $formats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
final class DeserializerListener
final class DeserializeListener
{
private $serializer;
private $serializerContextBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
final class DataProviderListener
final class ReadListener
{
private $collectionDataProvider;
private $itemDataProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
final class ResponderListener
final class RespondListener
{
const METHOD_TO_CODE = [
Request::METHOD_POST => Response::HTTP_CREATED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
final class SerializerListener
final class SerializeListener
{
private $serializer;
private $serializerContextBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
final class LinkHeaderListener
final class AddLinkHeaderListener
{
private $urlGenerator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ private function getContainerBuilderProphecy()
'api_platform.iri_converter',
'api_platform.naming.resource_path_naming_strategy.underscore',
'api_platform.naming.resource_path_naming_strategy.dash',
'api_platform.listener.request.format',
'api_platform.listener.request.data_provider',
'api_platform.listener.request.deserializer',
'api_platform.listener.view.serializer',
'api_platform.listener.view.validator',
'api_platform.listener.view.responder',
'api_platform.listener.request.add_format',
'api_platform.listener.request.read',
'api_platform.listener.request.deserialize',
'api_platform.listener.view.serialize',
'api_platform.listener.view.validate',
'api_platform.listener.view.respond',
'api_platform.serializer.context_builder',
'api_platform.doctrine.metadata_factory',
'api_platform.doctrine.orm.collection_data_provider',
Expand Down Expand Up @@ -283,8 +283,8 @@ private function getContainerBuilderProphecy()
'api_platform.swagger.command.swagger_command',
'api_platform.swagger.action.documentation',
'api_platform.hydra.documentation_builder',
'api_platform.hydra.listener.response.add_link_header',
'api_platform.hydra.listener.exception.validation',
'api_platform.hydra.listener.response.link_header',
'api_platform.hydra.listener.exception',
'api_platform.hydra.normalizer.collection',
'api_platform.hydra.normalizer.partial_collection_view',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace ApiPlatform\Core\Tests\Bridge\Symfony\Validator\EventListener;

use ApiPlatform\Core\Bridge\Symfony\Validator\EventListener\ValidatorListener;
use ApiPlatform\Core\Bridge\Symfony\Validator\EventListener\ValidateListener;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
use ApiPlatform\Core\Tests\Fixtures\DummyEntity;
Expand All @@ -24,7 +24,7 @@
/**
* @author Samuel ROZE <samuel.roze@gmail.com>
*/
class ValidatorListenerTest extends \PHPUnit_Framework_TestCase
class ValidateListenerTest extends \PHPUnit_Framework_TestCase
{
public function testValidatorIsCalled()
{
Expand All @@ -37,7 +37,7 @@ public function testValidatorIsCalled()

list($resourceMetadataFactory, $event) = $this->createEventObject($expectedValidationGroups, $data);

$validationViewListener = new ValidatorListener($validator, $resourceMetadataFactory);
$validationViewListener = new ValidateListener($validator, $resourceMetadataFactory);
$validationViewListener->onKernelView($event);
}

Expand All @@ -59,7 +59,7 @@ public function testThrowsValidationExceptionWithViolationsFound()

list($resourceMetadataFactory, $event) = $this->createEventObject($expectedValidationGroups, $data);

$validationViewListener = new ValidatorListener($validator, $resourceMetadataFactory);
$validationViewListener = new ValidateListener($validator, $resourceMetadataFactory);
$validationViewListener->onKernelView($event);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

namespace ApiPlatform\Core\Tests\EventListener;

use ApiPlatform\Core\EventListener\FormatListener;
use ApiPlatform\Core\EventListener\AddFormatListener;
use Negotiation\Negotiator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;

/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class FormatListenerTest extends \PHPUnit_Framework_TestCase
class AddFormatListenerTest extends \PHPUnit_Framework_TestCase
{
public function testNoResourceClass()
{
Expand All @@ -29,7 +29,7 @@ public function testNoResourceClass()
$eventProphecy->getRequest()->willReturn($request)->shouldBeCalled();
$event = $eventProphecy->reveal();

$listener = new FormatListener(new Negotiator(), []);
$listener = new AddFormatListener(new Negotiator(), []);
$listener->onKernelRequest($event);

$this->assertFalse($request->attributes->has('_api_format'));
Expand All @@ -46,7 +46,7 @@ public function testSupportedRequestFormat()
$eventProphecy->getRequest()->willReturn($request)->shouldBeCalled();
$event = $eventProphecy->reveal();

$listener = new FormatListener(new Negotiator(), ['text/xml' => 'xml']);
$listener = new AddFormatListener(new Negotiator(), ['text/xml' => 'xml']);
$listener->onKernelRequest($event);

$this->assertSame('xml', $request->attributes->get('_api_format'));
Expand All @@ -63,7 +63,7 @@ public function testUnsupportedRequestFormat()
$eventProphecy->getRequest()->willReturn($request)->shouldBeCalled();
$event = $eventProphecy->reveal();

$listener = new FormatListener(new Negotiator(), ['application/json' => 'json']);
$listener = new AddFormatListener(new Negotiator(), ['application/json' => 'json']);
$listener->onKernelRequest($event);

$this->assertSame('json', $request->attributes->get('_api_format'));
Expand All @@ -80,7 +80,7 @@ public function testSupportedAcceptHeader()
$eventProphecy->getRequest()->willReturn($request)->shouldBeCalled();
$event = $eventProphecy->reveal();

$listener = new FormatListener(new Negotiator(), ['application/octet-stream' => 'binary', 'application/json' => 'json']);
$listener = new AddFormatListener(new Negotiator(), ['application/octet-stream' => 'binary', 'application/json' => 'json']);
$listener->onKernelRequest($event);

$this->assertSame('json', $request->attributes->get('_api_format'));
Expand All @@ -97,7 +97,7 @@ public function testUnsupportedAcceptHeader()
$eventProphecy->getRequest()->willReturn($request)->shouldBeCalled();
$event = $eventProphecy->reveal();

$listener = new FormatListener(new Negotiator(), ['application/octet-stream' => 'binary', 'application/json' => 'json']);
$listener = new AddFormatListener(new Negotiator(), ['application/octet-stream' => 'binary', 'application/json' => 'json']);
$listener->onKernelRequest($event);

$this->assertSame('binary', $request->attributes->get('_api_format'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace ApiPlatform\Core\Tests\EventListener;

use ApiPlatform\Core\EventListener\DeserializerListener;
use ApiPlatform\Core\EventListener\DeserializeListener;
use ApiPlatform\Core\Serializer\SerializerContextBuilderInterface;
use Prophecy\Argument;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -21,7 +21,7 @@
/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class DeserializerListenerTest extends \PHPUnit_Framework_TestCase
class DeserializeListenerTest extends \PHPUnit_Framework_TestCase
{
public function testDoNotCallWhenRequestMethodIsSafe()
{
Expand All @@ -37,7 +37,7 @@ public function testDoNotCallWhenRequestMethodIsSafe()
$serializerContextBuilderProphecy = $this->prophesize(SerializerContextBuilderInterface::class);
$serializerContextBuilderProphecy->createFromRequest(Argument::type(Request::class), false, Argument::type('array'))->shouldNotBeCalled();

$listener = new DeserializerListener($serializerProphecy->reveal(), $serializerContextBuilderProphecy->reveal());
$listener = new DeserializeListener($serializerProphecy->reveal(), $serializerContextBuilderProphecy->reveal());
$listener->onKernelRequest($eventProphecy->reveal());
}

Expand All @@ -55,7 +55,7 @@ public function testDoNotCallWhenRequestNotManaged()
$serializerContextBuilderProphecy = $this->prophesize(SerializerContextBuilderInterface::class);
$serializerContextBuilderProphecy->createFromRequest(Argument::type(Request::class), false, Argument::type('array'))->shouldNotBeCalled();

$listener = new DeserializerListener($serializerProphecy->reveal(), $serializerContextBuilderProphecy->reveal());
$listener = new DeserializeListener($serializerProphecy->reveal(), $serializerContextBuilderProphecy->reveal());
$listener->onKernelRequest($eventProphecy->reveal());
}

Expand All @@ -78,7 +78,7 @@ public function testDeserialize(string $method, bool $populateObject)
$serializerContextBuilderProphecy = $this->prophesize(SerializerContextBuilderInterface::class);
$serializerContextBuilderProphecy->createFromRequest(Argument::type(Request::class), false, Argument::type('array'))->willReturn([])->shouldBeCalled();

$listener = new DeserializerListener($serializerProphecy->reveal(), $serializerContextBuilderProphecy->reveal());
$listener = new DeserializeListener($serializerProphecy->reveal(), $serializerContextBuilderProphecy->reveal());
$listener->onKernelRequest($eventProphecy->reveal());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
use ApiPlatform\Core\EventListener\DataProviderListener;
use ApiPlatform\Core\EventListener\ReadListener;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;

/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class DataProviderListenerTest extends \PHPUnit_Framework_TestCase
class ReadListenerTest extends \PHPUnit_Framework_TestCase
{
public function testNotAnApiPlatformRequest()
{
Expand All @@ -35,7 +35,7 @@ public function testNotAnApiPlatformRequest()
$event = $this->prophesize(GetResponseEvent::class);
$event->getRequest()->willReturn($request)->shouldBeCalled();

$listener = new DataProviderListener($collectionDataProvider->reveal(), $itemDataProvider->reveal());
$listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal());
$listener->onKernelRequest($event->reveal());
}

Expand All @@ -53,7 +53,7 @@ public function testRetrieveCollectionPost()
$event = $this->prophesize(GetResponseEvent::class);
$event->getRequest()->willReturn($request)->shouldBeCalled();

$listener = new DataProviderListener($collectionDataProvider->reveal(), $itemDataProvider->reveal());
$listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal());
$listener->onKernelRequest($event->reveal());

$this->assertTrue($request->attributes->has('data'));
Expand All @@ -74,7 +74,7 @@ public function testRetrieveCollectionGet()
$event = $this->prophesize(GetResponseEvent::class);
$event->getRequest()->willReturn($request)->shouldBeCalled();

$listener = new DataProviderListener($collectionDataProvider->reveal(), $itemDataProvider->reveal());
$listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal());
$listener->onKernelRequest($event->reveal());

$this->assertSame([], $request->attributes->get('data'));
Expand All @@ -95,7 +95,7 @@ public function testRetrieveItem()
$event = $this->prophesize(GetResponseEvent::class);
$event->getRequest()->willReturn($request)->shouldBeCalled();

$listener = new DataProviderListener($collectionDataProvider->reveal(), $itemDataProvider->reveal());
$listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal());
$listener->onKernelRequest($event->reveal());

$this->assertSame($data, $request->attributes->get('data'));
Expand All @@ -117,7 +117,7 @@ public function testRetrieveItemNotFound()
$event = $this->prophesize(GetResponseEvent::class);
$event->getRequest()->willReturn($request)->shouldBeCalled();

$listener = new DataProviderListener($collectionDataProvider->reveal(), $itemDataProvider->reveal());
$listener = new ReadListener($collectionDataProvider->reveal(), $itemDataProvider->reveal());
$listener->onKernelRequest($event->reveal());
}
}
Loading

0 comments on commit 4774609

Please sign in to comment.