/** * {@inheritdoc} */ protected function view($data = null, $statusCode = null, array $headers = []) { $view = parent::view($data, $statusCode, $headers); $context = $view->getSerializationContext(); $context->setGroups(['api', 'Default']); $view->setSerializationContext($context); return $view; }
/** * Creates a new view and sets the serialization context */ protected function view($data = null, $statusCode = null, array $headers = array(), array $serializerGroups = array()) { $view = parent::view($data, $statusCode, $headers); $view->setSerializationContext(SerializationContext::create()); if (0 != count($serializerGroups)) { $view->getSerializationContext()->setGroups($serializerGroups); } return $view; }
/** * Format the view for our API, and return a parent View * * @param mixed $response Response * @param VTExceptionInterface|int|null|string $status * @param array $headers * @param boolean $processActivity do we have to set the lastActivity for the current APIToken ? * * @return FOS\RestBundle\View\View */ protected function view($response = null, $status = VTExceptionInterface::STATUS_OK, array $headers = array(), $processActivity = true) { if (is_array($response)) { } if (empty($response)) { $response = null; } $data = array('response' => $response, 'serverTimestamp' => (new \DateTime())->getTimestamp(), 'status' => $status); return parent::view($data, $this->getStatusCode($status), $headers, $processActivity); }
public function setContainer(ContainerInterface $container = null) { parent::setContainer($container); $this->resourceResolver = new ResourceResolver($this->config); if (null !== $container) { $this->redirectHandler = new RedirectHandler($this->config, $container->get('router')); if (!$this->config->isApiRequest()) { $this->flashHelper = new FlashHelper($this->config, $container->get('translator'), $container->get('session')); } $this->domainManager = new DomainManager($container->get($this->config->getServiceName('manager')), $container->get('event_dispatcher'), $this->config, !$this->config->isApiRequest() ? $this->flashHelper : null); } }
/** * Patch entity field/s data by new values * * @param int $id * @param int $className * * @return Response * * @throws AccessDeniedException * * @Rest\Patch("entity_data/{className}/{id}") * @ApiDoc( * description="Update entity property", * resource=true, * requirements = { * {"name"="id", "dataType"="integer"}, * } * ) */ public function patchAction($className, $id) { $data = json_decode($this->get('request_stack')->getCurrentRequest()->getContent(), true); list($form, $data) = $this->getManager()->patch($className, $id, $data); if ($form->getErrors(true)->count() > 0) { $view = $this->view($form, Codes::HTTP_BAD_REQUEST); } else { $view = $this->view($data, Codes::HTTP_NO_CONTENT); } $response = parent::handleView($view); return $response; }
public function setContainer(ContainerInterface $container = null) { parent::setContainer($container); // Initialize the expression language. // This may not be the best place to put this... AccardLanguage::setExpressionLanguage($container->get('dag.expression_language')); $this->resourceResolver = new ResourceResolver($this->config); if (null !== $container) { $this->redirectHandler = new RedirectHandler($this->config, $container->get('router')); $this->flashHelper = new FlashHelper($this->config, $container->get('translator'), $container->get('session')); $this->domainManager = new DomainManager($container->get($this->config->getServiceName('manager')), $container->get('event_dispatcher'), $this->flashHelper, $this->config); $authChecker = $this->get('security.authorization_checker'); if ($this->getUser() && $authChecker->isGranted('IS_AUTHENTICATED_FULLY')) { $this->actionLogger = new ActionLogger($this->config, $this->getUser(), $container->get('dag.manager.log')); } } }
/** * Get translations. * * @QueryParam( * name="page", * requirements="\d+", * nullable=true, * description="Page number, starting from 1. Defaults to 1." * ) * @QueryParam( * name="limit", * requirements="\d+", * nullable=true, * description="Number of items per page. Defaults to 10." * ) * @QueryParam( * name="domain", * requirements=".+", * nullable=true, * description="The translation domain. Defaults to 'messages'." * ) * @QueryParam( * name="locale", * requirements=".+", * nullable=true, * description="The translation locale." * ) * @ApiDoc( * description="Get translations", * resource=true * ) * * @return Response */ public function cgetAction() { $page = (int) $this->getRequest()->get('page', 1); $limit = (int) $this->getRequest()->get('limit', RestGetController::ITEMS_PER_PAGE); $domain = $this->getRequest()->get('domain', 'messages'); $result = $this->get('translator')->getTranslations([$domain]); $data = []; if (isset($result[$domain]) && is_array($result[$domain])) { $slice = array_slice($result[$domain], $page > 0 ? ($page - 1) * $limit : 0, $limit); foreach ($slice as $key => $val) { $data[] = ['key' => $key, 'value' => $val]; } } $view = $this->view($data, Codes::HTTP_OK); $response = parent::handleView($view); $responseContext = ['result' => $data, 'totalCount' => function () use($result, $domain) { return isset($result[$domain]) && is_array($result[$domain]) ? count($result[$domain]) : 0; }]; $includeHandler = $this->get('oro_soap.handler.include'); $includeHandler->handle(new Context($this, $this->get('request'), $response, RestGetController::ACTION_LIST, $responseContext)); return $response; }
protected function handleView(View $view) { $serializeGroups = $this->get('request')->get('serialize', null); if (is_null($serializeGroups) === false && strlen($serializeGroups) > 0) { $view->setSerializationContext(SerializationContext::create()->setGroups(array($serializeGroups))); } return parent::handleView($view); }
/** * Sets the Container associated with this Controller. * * @param ContainerInterface $container A ContainerInterface instance * * @api */ public function setContainer(ContainerInterface $container = null) { parent::setContainer($container); Hal::setSerializer($this->get('serializer')); Hal::setExpandOptions($this->getExpandOptionsFromMetadata()); $this->setWildcardParams(); }
public function setContainer(\Symfony\Component\DependencyInjection\ContainerInterface $container = null) { parent::setContainer($container); $this->initializeServices(); }
/** * @param \Symfony\Component\DependencyInjection\ContainerInterface $container */ public function setContainer(ContainerInterface $container = null) { parent::setContainer($container); /** * Adiciona o innerEntity na lista de annotations ignoradas */ AnnotationReader::addGlobalIgnoredName('innerEntity'); //$this->get('doctrine.orm.entity_manager')->getConfiguration()->setQuoteStrategy(new OracleQuoteStrategy()); }
/** * Override view method in order to set serialization groups easily * * @param null $data * @param null $statusCode * @param array $headers * @param array $serializationContextGroups * * @return \FOS\RestBundle\View\View */ protected function view($data = null, $statusCode = null, array $headers = array(), array $serializationContextGroups = array('Default')) { return parent::view($data, $statusCode, $headers)->setSerializationContext(SerializationContext::create()->setGroups($serializationContextGroups)); }
public function setContainer(ContainerInterface $container = null) { parent::setContainer($container); $this->em = $this->getDoctrine()->getManager(); }
/** * @param mixed|View $data * @param string $action * @param array $contextValues * @param int $status Used only if data was given in raw format * * @return Response */ protected function buildResponse($data, $action, $contextValues = [], $status = Codes::HTTP_OK) { if ($data instanceof View) { $response = parent::handleView($data); } else { $headers = isset($contextValues['headers']) ? $contextValues['headers'] : []; unset($contextValues['headers']); $response = new JsonResponse($data, $status, $headers); } $includeHandler = $this->get('oro_soap.handler.include'); $includeHandler->handle(new Context($this, $this->get('request'), $response, $action, $contextValues)); return $response; }
public function setContainer(ContainerInterface $container = null) { parent::setContainer($container); $this->handler = new EntityHandler($this->container->get('doctrine.orm.entity_manager'), $this->container->get('event_dispatcher'), $this->get('request')); $this->handler->setParameters($this->parameters); }
/** * @param null $data * @param null $statusCode * @param array $headers * @return \FOS\RestBundle\View\View */ protected function view($data = null, $statusCode = null, array $headers = array()) { return parent::view($data, $statusCode, $headers); }
public function setContainer(ContainerInterface $container = null) { parent::setContainer($container); $this->snapshotService = $container->get('snapshot_service'); }
/** * {@inheritdoc} * * @param null $data * @param null $statusCode * @param array $headers */ protected function view($data = null, $statusCode = null, array $headers = array()) { if ($data instanceof Paginator) { // Get iterator out of Paginator class so that the entities are properly serialized by the serializer $data = $data->getIterator()->getArrayCopy(); } return parent::view($data, $statusCode, $headers); }