Inheritance: extends Exceptio\Exception
 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);
 }
 public function __construct($route, RouteDocument $routeDocument, CustomUrlDocument $customUrl)
 {
     parent::__construct(sprintf('Cannot delete current route "%s" of custom-url "%s"', $route, $customUrl->getTitle()), 9000);
     $this->route = $route;
     $this->routeDocument = $routeDocument;
     $this->customUrl = $customUrl;
 }
 public function __construct($baseDomain, array $domainParts, $domain)
 {
     parent::__construct(sprintf('Missing domain-part for base-domain "%s" detected. Result domain: "%s"', $baseDomain, $domain), 9003);
     $this->baseDomain = $baseDomain;
     $this->domainParts = $domainParts;
     $this->domain = $domain;
 }
 /**
  * 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);
 }
Exemple #6
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);
 }
 /**
  * @param string $message The error message
  * @param string $field   The field which is not
  * @param int    $code
  */
 public function __construct($message, $field, $code = 0)
 {
     $this->field = $field;
     parent::__construct($message, $code);
 }
 public function __construct(KeywordInterface $keyword)
 {
     parent::__construct(sprintf('The keyword "%s" is used in multiple categories or translations.', $keyword->getKeyword()), 2002);
     $this->keyword = $keyword;
 }
 /**
  * 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);
 }
Exemple #10
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]);
 }
 public function __construct(KeywordInterface $keyword)
 {
     parent::__construct(sprintf('The keyword "%s" is already in use.', $keyword->getKeyword()), 2001);
     $this->keyword = $keyword;
 }
 public function __construct($title)
 {
     parent::__construct(sprintf('Title "%s" already in use', $title), 9001);
     $this->title = $title;
 }