-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from chernecov/moving-embed-functionality-to-v…
…iew-layer Moving embed functionality to view layer
- Loading branch information
Showing
24 changed files
with
420 additions
and
184 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,7 @@ | |
|
||
namespace Ecentria\Libraries\EcentriaRestBundle\EventListener; | ||
|
||
use Ecentria\Libraries\EcentriaRestBundle\Model\CollectionResponse; | ||
use Ecentria\Libraries\EcentriaRestBundle\Model\Embedded\EmbeddedInterface; | ||
use Ecentria\Libraries\EcentriaRestBundle\Services\Embedded\EmbeddedManager; | ||
use FOS\RestBundle\View\View; | ||
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; | ||
|
||
|
@@ -20,33 +19,40 @@ | |
* | ||
* @author Sergey Chernecov <[email protected]> | ||
*/ | ||
class ResponseListener | ||
class EmbeddedResponseListener | ||
{ | ||
/** | ||
* Let's embed our response | ||
* Embedded manager | ||
* | ||
* @param GetResponseForControllerResultEvent $event Event | ||
* @var EmbeddedManager | ||
*/ | ||
protected $embeddedManager; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param EmbeddedManager $embeddedManager | ||
*/ | ||
public function __construct(EmbeddedManager $embeddedManager) | ||
{ | ||
$this->embeddedManager = $embeddedManager; | ||
} | ||
|
||
/** | ||
* Setting embedded serialization groups for current response | ||
* | ||
* @param GetResponseForControllerResultEvent $event | ||
* | ||
* @return void | ||
*/ | ||
public function onKernelView(GetResponseForControllerResultEvent $event) | ||
{ | ||
$request = $event->getRequest(); | ||
$view = $event->getControllerResult(); | ||
|
||
if (!$view instanceof View) { | ||
return; | ||
} | ||
|
||
$embedded = filter_var($request->get('_embedded'), FILTER_VALIDATE_BOOLEAN); | ||
$data = $view->getData(); | ||
|
||
if ($data instanceof EmbeddedInterface && $data->showAssociations() === null) { | ||
$data->setShowAssociations($embedded); | ||
} | ||
|
||
if ($data instanceof CollectionResponse) { | ||
$data->setInheritedShowAssociations($embedded); | ||
} | ||
$groups = $this->embeddedManager->generateGroups($event->getRequest()); | ||
$view->getSerializationContext()->setGroups($groups); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,16 +10,14 @@ | |
|
||
namespace Ecentria\Libraries\EcentriaRestBundle\Model\CRUD; | ||
|
||
use Ecentria\Libraries\EcentriaRestBundle\Model\Embedded\EmbeddedInterface, | ||
Ecentria\Libraries\EcentriaRestBundle\Model\Timestampable\TimestampableInterface, | ||
Ecentria\Libraries\EcentriaRestBundle\Model\Transactional\TransactionalInterface; | ||
use Ecentria\Libraries\EcentriaRestBundle\Model\Transactional\TransactionalInterface; | ||
|
||
/** | ||
* CRUD entity interface | ||
* | ||
* @author Sergey Chernecov <[email protected]> | ||
*/ | ||
interface CrudEntityInterface extends EmbeddedInterface, TransactionalInterface | ||
interface CrudEntityInterface extends TransactionalInterface | ||
{ | ||
/** | ||
* Primary key getter | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,7 @@ | |
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
|
||
use Ecentria\Libraries\EcentriaRestBundle\Model\Embedded\EmbeddedInterface, | ||
Ecentria\Libraries\EcentriaRestBundle\Model\Embedded\EmbeddedTrait, | ||
Ecentria\Libraries\EcentriaRestBundle\Model\Transactional\TransactionalInterface, | ||
use Ecentria\Libraries\EcentriaRestBundle\Model\Transactional\TransactionalInterface, | ||
Ecentria\Libraries\EcentriaRestBundle\Model\Transactional\TransactionalTrait; | ||
|
||
use JMS\Serializer\Annotation as Serializer; | ||
|
@@ -24,9 +22,8 @@ | |
* | ||
* @author Sergey Chernecov <[email protected]> | ||
*/ | ||
class CollectionResponse implements EmbeddedInterface, TransactionalInterface | ||
class CollectionResponse implements TransactionalInterface | ||
{ | ||
use EmbeddedTrait; | ||
use TransactionalTrait; | ||
|
||
/** | ||
|
@@ -67,20 +64,4 @@ public function getItems() | |
{ | ||
return $this->items; | ||
} | ||
|
||
/** | ||
* Setting association to show | ||
* | ||
* @param mixed $value | ||
* | ||
* @return void | ||
*/ | ||
public function setInheritedShowAssociations($value) | ||
{ | ||
foreach ($this->getItems() as $item) { | ||
if ($item instanceof EmbeddedInterface) { | ||
$item->setShowAssociations((bool) $value); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
parameters: | ||
|
||
ecentria.fos_rest.native_json_encode_serializer.class: Ecentria\Libraries\EcentriaRestBundle\Services\NativeJsonEncodeSerializer | ||
ecentria.utils.embedded_manager.class: Ecentria\Libraries\EcentriaRestBundle\Services\Embedded\EmbeddedManager | ||
|
||
services: | ||
|
||
ecentria.utils.embedded_manager: | ||
class: %ecentria.utils.embedded_manager.class% | ||
|
||
ecentria.fos_rest.native_json_encode_serializer: | ||
class: %ecentria.fos_rest.native_json_encode_serializer.class% |
Oops, something went wrong.