/**
  * Adds a message.
  *
  * @ApiDoc(
  *  input={"class"="sonata_notification_api_form_message", "name"="", "groups"={"sonata_api_write"}},
  *  output={"class"="Sonata\NotificationBundle\Model\Message", "groups"={"sonata_api_read"}},
  *  statusCodes={
  *      200="Returned when successful",
  *      400="Returned when an error has occurred while message creation"
  *  }
  * )
  *
  * @Route(requirements={"_format"="json|xml"})
  *
  * @param Request $request A Symfony request
  *
  * @return MessageInterface
  */
 public function postMessageAction(Request $request)
 {
     $message = null;
     $form = $this->formFactory->createNamed(null, 'sonata_notification_api_form_message', $message, array('csrf_protection' => false));
     $form->bind($request);
     if ($form->isValid()) {
         $message = $form->getData();
         $this->messageManager->save($message);
         $view = FOSRestView::create($message);
         $serializationContext = SerializationContext::create();
         $serializationContext->setGroups(array('sonata_api_read'));
         $serializationContext->enableMaxDepthChecks();
         $view->setSerializationContext($serializationContext);
         return $view;
     }
     return $form;
 }
 private function initManager(array $messages, $types, $batchSize)
 {
     $this->manager->expects($this->any())->method('findByTypes')->with($types, MessageInterface::STATE_OPEN, $batchSize)->willReturnCallback(function ($types, $state, $batchSize) use($messages) {
         return array_slice($messages, null, $batchSize);
     });
 }
 /**
  * {@inheritdoc}
  */
 public function cleanup()
 {
     $this->messageManager->cleanup($this->maxAge);
 }
 /**
  * Find open messages.
  *
  * @param array $types
  *
  * @return mixed
  */
 protected function findNextMessages($types)
 {
     return $this->messageManager->findByTypes($types, MessageInterface::STATE_OPEN, $this->batchSize);
 }
 /**
  * Fill the inner buffer
  */
 protected function buffer()
 {
     $this->buffer = $this->messageManager->findByTypes($this->types, MessageInterface::STATE_OPEN, $this->batchSize);
 }