Add TraceableArraySerializer to be able to debug calls

This commit is contained in:
Benoît Burnichon
2016-05-18 11:41:46 +02:00
parent 1682535dfb
commit ee9c766fa1
3 changed files with 120 additions and 2 deletions

View File

@@ -37,6 +37,7 @@ use Alchemy\Phrasea\Fractal\ArraySerializer;
use Alchemy\Phrasea\Fractal\CallbackTransformer; use Alchemy\Phrasea\Fractal\CallbackTransformer;
use Alchemy\Phrasea\Fractal\IncludeResolver; use Alchemy\Phrasea\Fractal\IncludeResolver;
use Alchemy\Phrasea\Fractal\SearchResultTransformerResolver; use Alchemy\Phrasea\Fractal\SearchResultTransformerResolver;
use Alchemy\Phrasea\Fractal\TraceableArraySerializer;
use Alchemy\Phrasea\Model\Entities\ApiOauthToken; use Alchemy\Phrasea\Model\Entities\ApiOauthToken;
use Alchemy\Phrasea\Model\Entities\Basket; use Alchemy\Phrasea\Model\Entities\Basket;
use Alchemy\Phrasea\Model\Entities\BasketElement; use Alchemy\Phrasea\Model\Entities\BasketElement;
@@ -1087,11 +1088,12 @@ class V1Controller extends Controller
$includeResolver = new IncludeResolver($transformerResolver); $includeResolver = new IncludeResolver($transformerResolver);
$fractal = new \League\Fractal\Manager(); $fractal = new \League\Fractal\Manager();
$fractal->setSerializer(new ArraySerializer()); $fractal->setSerializer(new TraceableArraySerializer($this->app['dispatcher']));
$fractal->parseIncludes($this->resolveSearchIncludes($request)); $fractal->parseIncludes($this->resolveSearchIncludes($request));
$result = $this->doSearch($request);
$searchView = $this->buildSearchView( $searchView = $this->buildSearchView(
$this->doSearch($request), $result,
$includeResolver->resolve($fractal), $includeResolver->resolve($fractal),
$this->resolveSubdefUrlTTL($request) $this->resolveSubdefUrlTTL($request)
); );

View File

@@ -0,0 +1,53 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Fractal;
use Symfony\Component\EventDispatcher\Event;
class GetSerializationEvent extends Event
{
private $resourceKey;
private $data;
private $serialization;
public function __construct($resourceKey, $data)
{
$this->resourceKey = $resourceKey;
$this->data = $data;
}
/**
* @return mixed
*/
public function getResourceKey()
{
return $this->resourceKey;
}
/**
* @return mixed
*/
public function getData()
{
return $this->data;
}
public function setSerialization($serialization)
{
$this->serialization = $serialization;
$this->stopPropagation();
}
public function getSerialization()
{
return $this->serialization;
}
}

View File

@@ -0,0 +1,63 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Fractal;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class TraceableArraySerializer extends ArraySerializer
{
/**
* @var EventDispatcherInterface
*/
private $dispatcher;
public function __construct(EventDispatcherInterface $dispatcher)
{
$this->dispatcher = $dispatcher;
}
public function collection($resourceKey, array $data)
{
/** @var GetSerializationEvent $event */
$event = $this->dispatcher->dispatch('fractal.serializer.collection', new GetSerializationEvent($resourceKey, $data));
$serialization = parent::collection($resourceKey, $data);
$event->setSerialization($serialization);
return $serialization;
}
public function item($resourceKey, array $data)
{
/** @var GetSerializationEvent $event */
$event = $this->dispatcher->dispatch('fractal.serializer.item', new GetSerializationEvent($resourceKey, $data));
$serialization = parent::item($resourceKey, $data);
$event->setSerialization($serialization);
return $serialization;
}
public function null($resourceKey)
{
/** @var GetSerializationEvent $event */
$event = $this->dispatcher->dispatch('fractal.serializer.null', new GetSerializationEvent($resourceKey, null));
$serialization = parent::null($resourceKey);
$event->setSerialization($serialization);
return $serialization;
}
}