Skip to content

WIP: Add events #2329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d8ed153
Add new pre- and post- Read, Serialize and Respond events
Nov 15, 2018
d1f1885
Raise events from Read, Serialize and Respond listeners
Nov 15, 2018
a15c339
Add Symfony’s event-dispatcher dependency
Nov 15, 2018
11babee
Add class to store the events’ names
Nov 15, 2018
bc8f4ec
Convert events to Plain Old PHP Object, made them final classes
Nov 15, 2018
a78263d
Add Write events
Nov 15, 2018
435e08b
Add 'add format' events
Nov 15, 2018
b8117d7
Add deserialize events
Nov 15, 2018
24d8dee
Meeting coding standard
Nov 15, 2018
694ba66
Fix BC break
Nov 15, 2018
e352353
GraphQL: raising the new Pre/PostWriteEvent when mutating item
Nov 16, 2018
530d34a
Remove useless PhpDoc
Nov 16, 2018
5da445e
GraphQL: raising the new Pre/PostReadItem
Nov 16, 2018
3b104ca
GraphQL: raising the new Pre/PostSerializeEvent on normalizing item
Nov 16, 2018
9fe38db
Rename $controllerResult field to $object
Nov 16, 2018
df4b30c
Rename $controllerResult field to $object
Nov 16, 2018
342d010
GraphQL: raising the new events on the collection resolver factory
Nov 16, 2018
3af6732
Remove useless PhpDoc
Nov 16, 2018
e037b11
Sending serialized data instead of the data themselves in the PostSer…
Nov 19, 2018
8ec73fd
Fix the position of the dispatch
Nov 20, 2018
1846257
Dispatching outside the loops
Nov 20, 2018
fe8596c
Rename ApiPlatformEvents class to Events
Dec 5, 2018
0895641
Remove pre-, post- add and respond events based on @dunglas' proposition
Dec 5, 2018
c0b1ca7
Fix various issues after @dunglas' review
Dec 5, 2018
5e98b01
Allow symfony/event-dispatcher v3.4
Dec 5, 2018
a6fad0a
Remove $method field and rename $controllerResult to $data
Dec 5, 2018
b2ad96b
Fix call to PreWriteEvent constructor
Dec 5, 2018
e956c62
Fix unit test
Dec 5, 2018
38c2b18
Fix constructor argument name
Dec 5, 2018
7f28f09
Add unit tests for Deserialize and Read events
Dec 6, 2018
9bf11bd
Add unit tests for Serialize and Write events
Dec 7, 2018
9f5681b
Rename constructor argument
Dec 7, 2018
8b0a2a5
Add Validate event
Dec 7, 2018
2450b8f
Fix PHP CS
Dec 7, 2018
d435b73
Fix typehint error reported by SF Insight
Dec 7, 2018
28d1f2f
Fix PHP stan
Dec 7, 2018
6ff432a
Make event-dispatcher optional
Dec 10, 2018
25cf1af
Move Events class to the right namespace
Dec 10, 2018
b06bef1
Re-order the events
Dec 10, 2018
6b7a434
Fix missing use statements
Dec 10, 2018
5a35028
Drop NAME constants in events, using the Events class' instead
Dec 11, 2018
2addb5d
Add missing `on-invalid` attribute on event dispatchers
Dec 11, 2018
1312d30
Drop AddFormat event
Dec 11, 2018
f24794e
Fix CS
Dec 21, 2018
3fb39a1
Remove useless $dispatcher variable
Jan 3, 2019
03edea2
Dispatch PreValidateEvent
Feb 6, 2019
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
76 changes: 31 additions & 45 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "api-platform/core",
"type": "library",
"description": "Build a fully-featured hypermedia or GraphQL API in minutes",
"keywords": ["REST", "GraphQL", "API", "JSON-LD", "Hydra", "JSONAPI", "OpenAPI", "HAL", "Swagger"],
"description": "The ultimate solution to create web APIs.",
"keywords": ["REST", "API", "JSON", "JSON-LD", "Hydra", "Swagger", "HAL"],
"homepage": "https://api-platform.com",
"license": "MIT",
"authors": [
Expand All @@ -17,10 +17,10 @@
"doctrine/inflector": "^1.0",
"psr/cache": "^1.0",
"psr/container": "^1.0",
"symfony/http-foundation": "^3.4 || ^4.0",
"symfony/http-kernel": "^3.4 || ^4.0",
"symfony/property-access": "^3.4 || ^4.0",
"symfony/property-info": "^3.4 || ^4.0",
"symfony/http-foundation": "^3.1 || ^4.0",
"symfony/http-kernel": "^2.7 || ^3.0 || ^4.0",
"symfony/property-access": "^2.7 || ^3.0 || ^4.0",
"symfony/property-info": "^3.3.11 || ^4.0",
"symfony/serializer": "^4.1",
"symfony/web-link": "^4.1",
"willdurand/negotiation": "^2.0.3"
Expand All @@ -34,61 +34,54 @@
"behatch/contexts": "3.1.0",
"doctrine/annotations": "^1.2",
"doctrine/doctrine-bundle": "^1.8",
"doctrine/doctrine-cache-bundle": "^1.3.5",
"doctrine/mongodb-odm": "^2.0.0@beta",
"doctrine/mongodb-odm-bundle": "^4.0.0@beta",
"doctrine/orm": "^2.6.3",
"elasticsearch/elasticsearch": "^6.0",
"friendsofsymfony/user-bundle": "dev-fix-mongodb-mapping",
"doctrine/orm": "^2.5.2",
"friendsofsymfony/user-bundle": "^2.1",
"guzzlehttp/guzzle": "^6.0",
"justinrainbow/json-schema": "^5.0",
"nelmio/api-doc-bundle": "^2.13.3",
"php-mock/php-mock-phpunit": "^2.0",
"phpdocumentor/reflection-docblock": "^3.0 || ^4.0",
"phpdocumentor/type-resolver": "^0.3 || ^0.4",
"phpspec/prophecy": "^1.8",
"phpunit/phpunit": "^7.5.2",
"phpdocumentor/type-resolver": "^0.2.1 || ^0.3 || 0.4",
"phpunit/phpunit": "^6.1",
"psr/log": "^1.0",
"ramsey/uuid": "^3.7",
"ramsey/uuid-doctrine": "^1.4",
"symfony/asset": "^3.4 || ^4.0",
"symfony/cache": "^3.4 || ^4.0",
"symfony/asset": "^3.3 || ^4.0",
"symfony/cache": "^3.3 || ^4.0",
"symfony/config": "^3.4 || ^4.0",
"symfony/console": "^3.4 || ^4.0",
"symfony/debug": "^3.4 || ^4.0",
"symfony/debug": "^2.8 || ^3.0 || ^4.0",
"symfony/dependency-injection": "^3.4 || ^4.0",
"symfony/doctrine-bridge": "^3.4 || ^4.0",
"symfony/event-dispatcher": "^3.4 || ^4.0",
"symfony/expression-language": "^3.4 || ^4.0",
"symfony/finder": "^3.4 || ^4.0",
"symfony/form": "^3.4 || ^4.0",
"symfony/framework-bundle": "^4.2",
"symfony/doctrine-bridge": "^2.8.12 || ^3.0 || ^4.0",
"symfony/expression-language": "^2.8 || ^3.0 || ^4.0",
"symfony/finder": "^3.3 || ^4.0",
"symfony/form": "^3.3 || ^4.0",
"symfony/framework-bundle": "^3.3 || ^4.0",
"symfony/mercure": "*",
"symfony/mercure-bundle": "*",
"symfony/messenger": "^4.2",
"symfony/phpunit-bridge": "^3.4.5 || ^4.0.5",
"symfony/routing": "^3.4 || ^4.0",
"symfony/security": "^3.4 || ^4.0",
"symfony/messenger": "^4.1",
"symfony/phpunit-bridge": "^3.3 || ^4.0",
"symfony/routing": "^3.3 || ^4.0",
"symfony/security": "^3.0 || ^4.0",
"symfony/security-bundle": "^3.4 || ^4.0",
"symfony/twig-bundle": "^3.4 || ^4.0",
"symfony/validator": "^3.4 || ^4.0",
"symfony/web-profiler-bundle": "^3.4 || ^4.0",
"symfony/yaml": "^3.4 || ^4.0",
"webonyx/graphql-php": ">=0.13 <1.0"
"symfony/validator": "^3.3 || ^4.0",
"symfony/web-profiler-bundle": "^3.3 || ^4.0",
"symfony/yaml": "^3.3 || ^4.0",
"webonyx/graphql-php": ">=0.12 <1.0"
},
"conflict": {
"doctrine/common": "<2.7",
"doctrine/mongodb-odm": "<2.0"
"symfony/dependency-injection": "<3.4"
},
"suggest": {
"doctrine/mongodb-odm-bundle": "To support MongoDB. Only versions 4.0 and later are supported.",
"elasticsearch/elasticsearch": "To support Elasticsearch.",
"friendsofsymfony/user-bundle": "To use the FOSUserBundle bridge.",
"guzzlehttp/guzzle": "To use the HTTP cache invalidation system.",
"phpdocumentor/reflection-docblock": "To support extracting metadata from PHPDoc.",
"psr/cache-implementation": "To use metadata caching.",
"ramsey/uuid": "To support Ramsey's UUID identifiers.",
"symfony/cache": "To have metadata caching when using Symfony integration.",
"symfony/config": "To load XML configuration files.",
"symfony/event-dispatcher": "To handle events",
"symfony/expression-language": "To use authorization features.",
"symfony/security": "To use authorization features.",
"symfony/twig-bundle": "To use the Swagger UI integration.",
Expand All @@ -103,17 +96,10 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.5.x-dev"
"dev-master": "2.4.x-dev"
}
},
"config": {
"sort-packages": true
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/alanpoulain/FOSUserBundle",
"no-api": true
}
]
}
}
7 changes: 7 additions & 0 deletions src/Bridge/Symfony/Bundle/Resources/config/api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
<service id="api_platform.listener.request.add_format" class="ApiPlatform\Core\EventListener\AddFormatListener">
<argument type="service" id="api_platform.negotiator" />
<argument type="service" id="api_platform.formats_provider"></argument>
<argument type="service" id="event_dispatcher" on-invalid="null" />

<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="7" />
</service>
Expand All @@ -149,13 +150,15 @@
<argument type="service" id="api_platform.subresource_data_provider" />
<argument type="service" id="api_platform.serializer.context_builder" />
<argument type="service" id="api_platform.identifier.converter" />
<argument type="service" id="event_dispatcher" on-invalid="null" />

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

<service id="api_platform.listener.view.write" class="ApiPlatform\Core\EventListener\WriteListener">
<argument type="service" id="api_platform.data_persister" />
<argument type="service" id="api_platform.iri_converter" on-invalid="null" />
<argument type="service" id="event_dispatcher" on-invalid="null" />

<tag name="kernel.event_listener" event="kernel.view" method="onKernelView" priority="32" />
</service>
Expand All @@ -164,19 +167,23 @@
<argument type="service" id="api_platform.serializer" />
<argument type="service" id="api_platform.serializer.context_builder" />
<argument type="service" id="api_platform.formats_provider" />
<argument type="service" id="event_dispatcher" on-invalid="null" />

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

<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" />
<argument type="service" id="event_dispatcher" on-invalid="null" />

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

<service id="api_platform.listener.view.respond" class="ApiPlatform\Core\EventListener\RespondListener">
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
<argument type="service" id="event_dispatcher" on-invalid="null" />

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

Expand Down
3 changes: 3 additions & 0 deletions src/Bridge/Symfony/Bundle/Resources/config/graphql.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<argument type="service" id="api_platform.security.resource_access_checker" on-invalid="null" />
<argument type="service" id="request_stack" />
<argument>%api_platform.collection.pagination.enabled%</argument>
<argument type="service" id="event_dispatcher" on-invalid="null" />
</service>

<service id="api_platform.graphql.resolver.factory.item_mutation" class="ApiPlatform\Core\GraphQl\Resolver\Factory\ItemMutationResolverFactory" public="false">
Expand All @@ -27,13 +28,15 @@
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
<argument type="service" id="api_platform.security.resource_access_checker" on-invalid="null" />
<argument type="service" id="api_platform.validator" on-invalid="null" />
<argument type="service" id="event_dispatcher" on-invalid="null" />
</service>

<service id="api_platform.graphql.resolver.item" class="ApiPlatform\Core\GraphQl\Resolver\ItemResolver" public="false">
<argument type="service" id="api_platform.iri_converter" />
<argument type="service" id="serializer" />
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
<argument type="service" id="api_platform.security.resource_access_checker" on-invalid="ignore" />
<argument type="service" id="event_dispatcher" on-invalid="null" />
</service>

<service id="api_platform.graphql.resolver.resource_field" class="ApiPlatform\Core\GraphQl\Resolver\ResourceFieldResolver" public="false">
Expand Down
36 changes: 36 additions & 0 deletions src/Event/PostDeserializeEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Core\Event;

use Symfony\Component\EventDispatcher\Event;

final class PostDeserializeEvent extends Event
{
private $data;

public function __construct($controllerResult)
{
$this->data = $controllerResult;
}

public function getData()
{
return $this->data;
}

public function setData($data): void
{
$this->data = $data;
}
}
36 changes: 36 additions & 0 deletions src/Event/PostReadEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Core\Event;

use Symfony\Component\EventDispatcher\Event;

final class PostReadEvent extends Event
{
private $data;

public function __construct($data)
{
$this->data = $data;
}

public function getData()
{
return $this->data;
}

public function setData($data): void
{
$this->data = $data;
}
}
36 changes: 36 additions & 0 deletions src/Event/PostSerializeEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Core\Event;

use Symfony\Component\EventDispatcher\Event;

final class PostSerializeEvent extends Event
{
private $data;

public function __construct($object)
{
$this->data = $object;
}

public function getData()
{
return $this->data;
}

public function setData($data): void
{
$this->data = $data;
}
}
36 changes: 36 additions & 0 deletions src/Event/PostValidateEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Core\Event;

use Symfony\Component\EventDispatcher\Event;

class PostValidateEvent extends Event
{
private $data;

public function __construct($data)
{
$this->data = $data;
}

public function getData()
{
return $this->data;
}

public function setData($data): void
{
$this->data = $data;
}
}
36 changes: 36 additions & 0 deletions src/Event/PostWriteEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Core\Event;

use Symfony\Component\EventDispatcher\Event;

final class PostWriteEvent extends Event
{
private $data;

public function __construct($data)
{
$this->data = $data;
}

public function getData()
{
return $this->data;
}

public function setData($data): void
{
$this->data = $data;
}
}
Loading