toArray() public method

public toArray ( )
 public function testCGetActionWithUnexistingAlias()
 {
     $query = ['alias' => 'not_existent_alias'];
     $request = new Request($query);
     $contentNavigationAliasNotFoundException = new ContentNavigationAliasNotFoundException($query['alias'], []);
     $this->contentNavigationCollector->getNavigationItems(Argument::cetera())->willThrow($contentNavigationAliasNotFoundException);
     $exception = new RestException($contentNavigationAliasNotFoundException->getMessage(), 0, $contentNavigationAliasNotFoundException);
     $this->viewHandler->handle(View::create($exception->toArray(), 404))->shouldBeCalled();
     $this->contentNavigationController->cgetAction($request);
 }
 /**
  * Returns the localizations for the given webspace.
  *
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function cgetAction(Request $request)
 {
     $webspaceKey = $request->get('webspace');
     /** @var WebspaceManagerInterface $webspaceManager */
     $webspaceManager = $this->get('sulu_core.webspace.webspace_manager');
     $webspace = $webspaceManager->findWebspaceByKey($webspaceKey);
     if ($webspace) {
         $localizations = new CollectionRepresentation($webspace->getAllLocalizations(), 'localizations');
         $view = $this->view($localizations, 200);
     } else {
         $error = new RestException(sprintf('No webspace found for key \'%s\'', $webspaceKey));
         $view = $this->view($error->toArray(), 400);
     }
     return $this->handleView($view, 200);
 }
 /**
  * Returns all the content navigation items for a given alias.
  *
  * @param Request $request
  *
  * @return Response
  */
 public function cgetAction(Request $request)
 {
     try {
         $alias = $request->get('alias');
         if (!$alias) {
             throw new RestException('The alias attribute is required to load the content navigation');
         }
         $options = $request->query->all();
         $contentNavigationItems = $this->contentNavigationRegistry->getNavigationItems($alias, $options);
         $view = View::create($contentNavigationItems);
     } catch (ContentNavigationAliasNotFoundException $exc) {
         $restException = new RestException($exc->getMessage(), 0, $exc);
         $view = View::create($restException->toArray(), 404);
     } catch (RestException $exc) {
         $view = View::create($exc->toArray(), 400);
     }
     return $this->viewHandler->handle($view);
 }
Example #4
0
 /**
  * Change a filter by the given id.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @param int $id the attribute id
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function putAction(Request $request, $id)
 {
     try {
         $filter = $this->getManager()->save($request->request->all(), $this->getLocale($request), $this->getUser()->getId(), $id);
         $view = $this->view($filter, 200);
     } catch (FilterDependencyNotFoundException $exc) {
         $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
         $view = $this->view($exception->toArray(), 400);
     } catch (FilterNotFoundException $exc) {
         $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
         $view = $this->view($exception->toArray(), 404);
     } catch (MissingFilterException $exc) {
         $exception = new MissingArgumentException(self::$entityName, $exc->getFilter());
         $view = $this->view($exception->toArray(), 400);
     } catch (ConditionGroupMismatchException $exc) {
         $exception = new InvalidArgumentException(self::$groupConditionEntityName, $exc->getId());
         $view = $this->view($exception->toArray(), 400);
     } catch (UnknownContextException $exc) {
         $exception = new RestException($exc->getMessage());
         $view = $this->view($exception->toArray(), 400);
     }
     return $this->handleView($view);
 }
Example #5
0
 /**
  * Change a shipping.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @param integer $id shipping ID
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function putAction(Request $request, $id)
 {
     try {
         $shipping = $this->getManager()->save($request->request->all(), $this->getLocale($request), $this->getUser()->getId(), $id);
         $view = $this->view($shipping, 200);
     } catch (ShippingNotFoundException $exc) {
         $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
         $view = $this->view($exception->toArray(), 404);
     } catch (ShippingDependencyNotFoundException $exc) {
         $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
         $view = $this->view($exception->toArray(), 400);
     } catch (MissingShippingAttributeException $exc) {
         $exception = new MissingArgumentException(self::$shippingEntityName, $exc->getAttribute());
         $view = $this->view($exception->toArray(), 400);
     } catch (ShippingException $exc) {
         $exception = new RestException($exc->getMessage());
         $view = $this->view($exception->toArray(), 400);
     }
     return $this->handleView($view);
 }
Example #6
0
 /**
  * Updates a content item and returns result as JSON String.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function postAction(Request $request)
 {
     try {
         $language = $this->getLanguage($request);
         $webspace = $this->getWebspace($request);
         $template = $this->getRequestParameter($request, 'template', true);
         $isShadow = $this->getRequestParameter($request, 'isShadow', false);
         $shadowBaseLanguage = $this->getRequestParameter($request, 'shadowBaseLanguage', null);
         $parent = $this->getRequestParameter($request, 'parent');
         $state = $this->getRequestParameter($request, 'state');
         if ($state !== null) {
             $state = intval($state);
         }
         $type = $request->query->get('type', Structure::TYPE_PAGE);
         $data = $request->request->all();
         $mapperRequest = ContentMapperRequest::create()->setType($type)->setTemplateKey($template)->setWebspaceKey($webspace)->setUserId($this->getUser()->getId())->setState($state)->setIsShadow($isShadow)->setShadowBaseLanguage($shadowBaseLanguage)->setLocale($language)->setParentUuid($parent)->setData($data);
         $result = $this->getRepository()->saveNodeRequest($mapperRequest);
         return $this->handleView($this->view($result));
     } catch (ResourceLocatorNotValidException $e) {
         $restException = new RestException('The chosen ResourceLocator is not valid');
         return $this->handleView($this->view($restException->toArray(), 409));
     }
 }
 public function toArray()
 {
     $result = parent::toArray();
     return array_merge($result, ['userid' => $this->userId, 'contentuuid' => $this->contentUuid]);
 }