This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Request | |
PUT /posts/1 | |
{ | |
"title": "such a title", | |
"content": "Api Platform is awesome" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Response | |
{ | |
"@context": "/contexts/ConstraintViolationList", | |
"@type": "ConstraintViolationList", | |
"hydra:title": "An error occurred", | |
"hydra:description": "title: You are not allowed to do this stuff !", | |
"violations": [ | |
{ | |
"propertyPath": "title", | |
"message": "You are not allowed to do this stuff !" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"@context": "/contexts/Post", | |
"@id": "/posts/1", | |
"@type": "Post", | |
"id": 1, | |
"title": "such a title", | |
"content": "Api Platform is awesome" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class FooRequestListener | |
{ | |
public function onKernelRequest(RequestEvent $event) | |
{ | |
if ($this->supports($event) { | |
// condition fullfilled do some stuff | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UserSubscriber | |
{ | |
public function postPersist(LifecycleEventArgs $args) | |
{ | |
$entity = $args->getObject(); | |
// if this listener only applies to certain entity types, | |
// add some code to check the entity type as early as possible | |
if (!$this->supports($entity)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class FooRequestListener | |
{ | |
private $enabled = true; | |
// .. | |
public function supports(RequestEvent $event): bool | |
{ | |
return $event->isMasterRequest() && $this->enabled; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UserSubscriber | |
{ | |
private $enabled = true; | |
// ... | |
public function supports($entity): bool | |
{ | |
return $entity instanceof User && $this->enabled; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class DisableListenerEvent | |
{ | |
public const NAME = 'app.disable_listener'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait DisableListenerTrait | |
{ | |
private $enabled = true; | |
public function disable(): void | |
{ | |
$this->enabled = false; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface DisableListenerInterface | |
{ | |
public function disable(): void; | |
} |