Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Commit

Permalink
Merge 3.x into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI committed Feb 15, 2018
2 parents d02ff9d + 9b0e840 commit 2f04b00
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 48 deletions.
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -38,11 +38,12 @@
"zendframework/zenddiagnostics": "^1.0"
},
"conflict": {
"friendsofsymfony/rest-bundle": "<2.1 || >=3.0",
"jms/serializer": "<0.13",
"sonata-project/admin-bundle": "<3.1"
},
"require-dev": {
"friendsofsymfony/rest-bundle": "^1.5 || ^2.1",
"friendsofsymfony/rest-bundle": "^2.1",
"guzzlehttp/guzzle": "^3.8",
"jms/serializer-bundle": "^0.13 || ^1.0",
"liip/monitor-bundle": "^2.0",
Expand Down
45 changes: 6 additions & 39 deletions src/Controller/Api/MessageController.php
Expand Up @@ -13,13 +13,10 @@

namespace Sonata\NotificationBundle\Controller\Api;

use FOS\RestBundle\Context\Context;
use FOS\RestBundle\Controller\Annotations\QueryParam;
use FOS\RestBundle\Controller\Annotations\Route;
use FOS\RestBundle\Controller\Annotations\View;
use FOS\RestBundle\Request\ParamFetcherInterface;
use FOS\RestBundle\View\View as FOSRestView;
use JMS\Serializer\SerializationContext;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Sonata\DatagridBundle\Pager\PagerInterface;
use Sonata\NotificationBundle\Model\MessageInterface;
Expand Down Expand Up @@ -57,36 +54,23 @@ public function __construct(MessageManagerInterface $messageManager, FormFactory
*
* @ApiDoc(
* resource=true,
* output={"class"="Sonata\DatagridBundle\Pager\PagerInterface", "groups"="sonata_api_read"}
* output={"class"="Sonata\DatagridBundle\Pager\PagerInterface", "groups"={"sonata_api_read"}}
* )
*
* @QueryParam(name="page", requirements="\d+", default="1", description="Page for message list pagination")
* @QueryParam(name="count", requirements="\d+", default="10", description="Number of messages by page")
* @QueryParam(name="type", nullable=true, description="Message type filter")
* @QueryParam(name="state", requirements="\d+", strict=true, nullable=true, description="Message status filter")
* @QueryParam(name="orderBy", map=true, requirements="ASC|DESC", nullable=true, strict=true, description="Query groups order by clause (key is field, value is direction)")
*
* @View(serializerGroups="sonata_api_read", serializerEnableMaxDepthChecks=true)
* @View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true)
*
* @param ParamFetcherInterface $paramFetcher
*
* @return PagerInterface
*/
public function getMessagesAction(ParamFetcherInterface $paramFetcher)
{
$orderByQueryParam = new QueryParam();
$orderByQueryParam->name = 'orderBy';
$orderByQueryParam->requirements = 'ASC|DESC';
$orderByQueryParam->nullable = true;
$orderByQueryParam->strict = true;
$orderByQueryParam->description = 'Query groups order by clause (key is field, value is direction)';
if (property_exists($orderByQueryParam, 'map')) {
$orderByQueryParam->map = true;
} else {
$orderByQueryParam->array = true;
}

$paramFetcher->addParam($orderByQueryParam);

$supportedCriteria = [
'state' => '',
'type' => '',
Expand Down Expand Up @@ -124,6 +108,8 @@ public function getMessagesAction(ParamFetcherInterface $paramFetcher)
* }
* )
*
* @View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true)
*
* @Route(requirements={"_format"="json|xml"})
*
* @param Request $request A Symfony request
Expand All @@ -142,28 +128,9 @@ public function postMessageAction(Request $request)

if ($form->isValid()) {
$message = $form->getData();

$this->messageManager->save($message);

$view = FOSRestView::create($message);

if (class_exists(Context::class)) {
$serializationContext = new Context();
if (method_exists($serializationContext, 'enableMaxDepth')) {
$serializationContext->enableMaxDepth();
} else {
$serializationContext->setMaxDepth(10);
}
$serializationContext->setGroups(['sonata_api_read']);
$view->setContext($serializationContext);
} else {
$serializationContext = SerializationContext::create();
$serializationContext->enableMaxDepthChecks();
$serializationContext->setGroups(['sonata_api_read']);
$view->setSerializationContext($serializationContext);
}

return $view;
return $message;
}

return $form;
Expand Down
8 changes: 4 additions & 4 deletions src/Resources/config/backend.xml
@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sonata.notification.backend.runtime" class="Sonata\NotificationBundle\Backend\RuntimeBackend">
<service id="sonata.notification.backend.runtime" class="Sonata\NotificationBundle\Backend\RuntimeBackend" public="true">
<argument type="service" id="sonata.notification.dispatcher"/>
</service>
<service id="sonata.notification.backend.postpone" class="Sonata\NotificationBundle\Backend\PostponeRuntimeBackend">
<service id="sonata.notification.backend.postpone" class="Sonata\NotificationBundle\Backend\PostponeRuntimeBackend" public="true">
<tag name="kernel.event_listener" event="kernel.terminate" method="onEvent"/>
<argument type="service" id="sonata.notification.dispatcher"/>
</service>
<service id="sonata.notification.backend.doctrine" class="Sonata\NotificationBundle\Backend\MessageManagerBackendDispatcher">
<service id="sonata.notification.backend.doctrine" class="Sonata\NotificationBundle\Backend\MessageManagerBackendDispatcher" public="true">
<argument type="service" id="sonata.notification.manager.message"/>
<argument/>
<argument/>
<argument/>
</service>
<service id="sonata.notification.backend.rabbitmq" class="Sonata\NotificationBundle\Backend\AMQPBackendDispatcher">
<service id="sonata.notification.backend.rabbitmq" class="Sonata\NotificationBundle\Backend\AMQPBackendDispatcher" public="true">
<argument/>
<argument/>
<argument/>
Expand Down
8 changes: 4 additions & 4 deletions tests/Controller/Api/MessageControllerTest.php
Expand Up @@ -57,9 +57,9 @@ public function testPostMessageAction(): void
$formFactory = $this->createMock(FormFactoryInterface::class);
$formFactory->expects($this->once())->method('createNamed')->will($this->returnValue($form));

$view = $this->createMessageController(null, $messageManager, $formFactory)->postMessageAction(new Request());
$message = $this->createMessageController(null, $messageManager, $formFactory)->postMessageAction(new Request());

$this->assertInstanceOf(View::class, $view);
$this->assertInstanceOf(MessageInterface::class, $message);
}

public function testPostMessageInvalidAction(): void
Expand All @@ -76,9 +76,9 @@ public function testPostMessageInvalidAction(): void
$formFactory = $this->createMock(FormFactoryInterface::class);
$formFactory->expects($this->once())->method('createNamed')->will($this->returnValue($form));

$view = $this->createMessageController(null, $messageManager, $formFactory)->postMessageAction(new Request());
$form = $this->createMessageController(null, $messageManager, $formFactory)->postMessageAction(new Request());

$this->assertInstanceOf(FormInterface::class, $view);
$this->assertInstanceOf(FormInterface::class, $form);
}

/**
Expand Down

0 comments on commit 2f04b00

Please sign in to comment.