Log API controller responses to enable us to debug #374
This commit is contained in:
parent
e1b27dea9a
commit
1e23f0cd55
3 changed files with 63 additions and 1 deletions
|
|
@ -53,7 +53,7 @@ use DateTime;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
// mobile API
|
// mobile API
|
||||||
class APIController extends Controller
|
class APIController extends Controller implements LoggedController
|
||||||
{
|
{
|
||||||
protected $session;
|
protected $session;
|
||||||
|
|
||||||
|
|
|
||||||
7
src/Controller/LoggedController.php
Normal file
7
src/Controller/LoggedController.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
interface LoggedController
|
||||||
|
{
|
||||||
|
}
|
||||||
55
src/EventSubscriber/LogSubscriber.php
Normal file
55
src/EventSubscriber/LogSubscriber.php
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\EventSubscriber;
|
||||||
|
|
||||||
|
use App\Controller\LoggedController;
|
||||||
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
use Symfony\Component\HttpKernel\Event\ControllerEvent;
|
||||||
|
use Symfony\Component\HttpKernel\Event\ResponseEvent;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||||
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
|
|
||||||
|
class LogSubscriber implements EventSubscriberInterface
|
||||||
|
{
|
||||||
|
protected $allow;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->allow = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onKernelController(ControllerEvent $event)
|
||||||
|
{
|
||||||
|
$controller = $event->getController();
|
||||||
|
|
||||||
|
// when a controller class defines multiple action methods, the controller
|
||||||
|
// is returned as [$controllerInstance, 'methodName']
|
||||||
|
if (is_array($controller))
|
||||||
|
$controller = $controller[0];
|
||||||
|
|
||||||
|
if ($controller instanceof LoggedController)
|
||||||
|
$this->allow = true;
|
||||||
|
else
|
||||||
|
$this->allow = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onKernelResponse(ResponseEvent $event)
|
||||||
|
{
|
||||||
|
if (!$this->allow)
|
||||||
|
return;
|
||||||
|
|
||||||
|
$resp = $event->getResponse();
|
||||||
|
|
||||||
|
$content = $resp->getContent();
|
||||||
|
|
||||||
|
error_log(print_r($content, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getSubscribedEvents()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
KernelEvents::CONTROLLER => 'onKernelController',
|
||||||
|
KernelEvents::RESPONSE => 'onKernelResponse',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue