generate() public method

If the generator is not able to generate the url, it must throw the RouteNotFoundException as documented below.
public generate ( string $name, mixed $parameters = [], boolean $absolute = false ) : string
$name string The name of the route
$parameters mixed An array of parameters
$absolute boolean Whether to generate an absolute URL
return string The generated URL
 /**
  * {@inheritdoc}
  */
 public function mapPath($path, $build, $development)
 {
     if (substr($path, 0, 1) === '/') {
         return $path;
     }
     return $this->urlGenerator->generate('tq_extjs_application_resources', ['build' => $build, 'dev' => $development ? '-dev' : '', 'path' => str_replace('..', '~', $path)]);
 }
Exemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function getAuthorizationUrl($redirectUrl)
 {
     if (!preg_match('#^https://.*#', $redirectUrl)) {
         $redirectUrl = $this->generator->generate($redirectUrl, array(), true);
     }
     return parent::getAuthorizationUrl($redirectUrl);
 }
 /**
  * Add Free payment method
  *
  * @param PaymentCollectionEvent $event Event
  */
 public function addFreePaymentPaymentMethod(PaymentCollectionEvent $event)
 {
     if ($this->plugin->isUsable()) {
         $bankwire = new PaymentMethod($this->plugin->getHash(), 'elcodi_plugin.bankwire.name', 'elcodi_plugin.bankwire.description', $this->router->generate('paymentsuite_bankwire_execute'));
         $event->addPaymentMethod($bankwire);
     }
 }
Exemplo n.º 4
0
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->setAction($this->urlGenerator->generate($options['route'], $options['route_parameters']));
     $builder->setMethod('POST');
     $builder->add('locale', 'choice', ['label' => false, 'required' => true, 'widget_addon_prepend' => ['icon' => 'language'], 'choices' => $this->localeChoiceList->create(), 'choices_as_values' => true]);
     $builder->add('switch', 'submit', ['label' => 'stepup_middleware_client.form.switch_locale.switch', 'attr' => ['class' => 'btn btn-default']]);
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function render(GridViewInterface $grid, ColumnInterface $column, $sorting)
 {
     $definition = $grid->getDefinition();
     $name = $column->getName();
     if (!$definition->hasSort($name)) {
         return;
     }
     $sort = $sorting === SorterInterface::ASC ? $name : '-' . $name;
     $routeParameters = [];
     if (($request = $this->requestStack->getMasterRequest()) !== null) {
         $routeParameters = array_merge($request->attributes->get('_route_params', []), $request->query->all());
     }
     if (!isset($routeParameters['grid']['reset']) && isset($routeParameters['grid']['sorting']) && $routeParameters['grid']['sorting'] === $sort) {
         return;
     }
     if ($definition->hasOption('persistent') && $definition->getOption('persistent')) {
         $filters = $this->filterManager->get($definition);
         if (isset($filters['sorting']) && $filters['sorting'] === $sort) {
             return;
         }
     }
     $routeParameters['grid']['sorting'] = $sort;
     unset($routeParameters['grid']['reset']);
     return $this->urlGenerator->generate($definition->getOption('grid_route'), $routeParameters);
 }
Exemplo n.º 6
0
 /**
  * @param Request $request
  *
  * @return JsonResponse
  */
 public function createAction($content, Request $request)
 {
     $this->forward400Unless('json' == $request->getContentType() || 'form' == $request->getContentType());
     $rawPayment = ArrayObject::ensureArrayObject($content);
     $form = $this->formFactory->create('create_payment');
     $form->submit((array) $rawPayment);
     if (false == $form->isValid()) {
         return new JsonResponse($this->formToJsonConverter->convertInvalid($form), 400);
     }
     /** @var Payment $payment */
     $payment = $form->getData();
     $payment->setId(Random::generateToken());
     $storage = $this->payum->getStorage($payment);
     $storage->update($payment);
     $payment->setNumber($payment->getNumber() ?: date('Ymd-' . mt_rand(10000, 99999)));
     $storage->update($payment);
     // TODO
     $payment->setValue('links', 'done', 'http://dev.payum-server.com/client/index.html');
     $payment->setValue('links', 'self', $this->urlGenerator->generate('payment_get', ['id' => $payment->getId()], true));
     $token = $this->payum->getTokenFactory()->createAuthorizeToken($payment->getGatewayName(), $payment, $payment->getValue('links', 'done'), ['payum_token' => null, 'payment' => $payment->getId()]);
     $payment->setValue('links', 'authorize', $token->getTargetUrl());
     $token = $this->payum->getTokenFactory()->createCaptureToken($payment->getGatewayName(), $payment, $payment->getValue('links', 'done'), ['payum_token' => null, 'payment' => $payment->getId()]);
     $payment->setValue('links', 'capture', $token->getTargetUrl());
     $token = $this->payum->getTokenFactory()->createNotifyToken($payment->getGatewayName(), $payment);
     $payment->setValue('links', 'notify', $token->getTargetUrl());
     $storage->update($payment);
     return new JsonResponse(array('payment' => $this->paymentToJsonConverter->convert($payment)), 201, array('Location' => $payment->getValue('links', 'self')));
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}.
  */
 public function guessValues(UrlInformation $urlInformation, $object, $sitemap)
 {
     if ($urlInformation->getLocation()) {
         return;
     }
     $urlInformation->setLocation($this->urlGenerator->generate($object, array(), UrlGeneratorInterface::ABSOLUTE_URL));
 }
Exemplo n.º 8
0
 /**
  * Add PayPal payment method
  *
  * @param PaymentCollectionEvent $event Event
  */
 public function addPaypalPaymentMethod(PaymentCollectionEvent $event)
 {
     if ($this->plugin->isUsable(['business'])) {
         $paypal = new PaymentMethod($this->plugin->getHash(), 'elcodi_plugin.paypal_web_checkout.name', 'elcodi_plugin.paypal_web_checkout.description', $this->router->generate('paymentsuite_paypal_web_checkout_execute'));
         $event->addPaymentMethod($paypal);
     }
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function apply(array &$options, ItemInterface $item)
 {
     if (!empty($options['route'])) {
         $route = (array) $options['route'] + array('', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
         $options['uri'] = $this->generator->generate($route[0], $route[1], $route[2]);
     }
 }
Exemplo n.º 10
0
 /**
  * {@inheritdoc}.
  */
 public function guessValues(UrlInformation $urlInformation, $object, $sitemap)
 {
     if ($urlInformation->getLocation()) {
         return;
     }
     $urlInformation->setLocation($this->urlGenerator->generate($object, array(), true));
 }
Exemplo n.º 11
0
 /**
  * Payment fail action.
  *
  * @param Request $request Request element
  *
  * @return Response
  */
 public function failureAction(Request $request)
 {
     $orderId = $request->query->get('order_id', false);
     $failureRoute = $this->redirectionRoutes->getRedirectionRoute('failure');
     $redirectUrl = $this->urlGenerator->generate($failureRoute->getRoute(), $failureRoute->getRouteAttributes($orderId));
     return new RedirectResponse($redirectUrl);
 }
 private function loadCategories()
 {
     $collection = $this->repository->matching(new Criteria());
     $collection->map(function (CategoryInterface $category) {
         $this->categories[$category->getId()] = ['name' => $category->translate()->getName(), 'route' => $this->generator->generate($category->translate()->getRoute()->getId())];
     });
 }
Exemplo n.º 13
0
 /**
  * Returns the canonical url for the current request,
  * or null if called outside of the request cycle.
  *
  * @return string|null
  */
 public function getUrl()
 {
     if (($request = $this->requestStack->getCurrentRequest()) === null) {
         return null;
     }
     return $this->urlGenerator->generate($request->attributes->get('_route'), $request->attributes->get('_route_params'), UrlGeneratorInterface::ABSOLUTE_URL);
 }
 /**
  * Add new breadcrumb item
  * @param string $linkName
  * @param string|array|null $target
  * @return void
  */
 public function addItem($linkName, $target = null)
 {
     if (is_array($target)) {
         $target = isset($target['params']) ? $this->urlGen->generate($target['route'], $target['params']) : $this->urlGen->generate($target['route']);
     }
     $this->items[] = array("linkName" => $linkName, "target" => $target);
 }
 /**
  * @param string $route
  * @param array $parameters
  * @param string $referenceType
  * @return string
  * @throws MissingDependencyException
  */
 public function generateUrl($route, $parameters = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
 {
     if (null === $this->urlGenerator) {
         throw new MissingDependencyException('No router present.');
     }
     return $this->urlGenerator->generate($route, $parameters, $referenceType);
 }
 /**
  * {@inheritdoc}
  *
  * Makes sure the _locale parameter is always set.
  */
 public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
 {
     if (!isset($parameters['_locale'])) {
         $parameters['_locale'] = $this->app['translate.slug'];
     }
     return $this->wrapped->generate($name, $parameters, $referenceType);
 }
Exemplo n.º 17
0
 /**
  * @param SluggableInterface $sluggable
  * @param array              $parameterList
  *
  * @return string
  */
 public function generate(SluggableInterface $sluggable, array $parameterList = [])
 {
     $configuration = $this->sluggableManager->getConfiguration($sluggable);
     $parameterList[$configuration->getRouteIdParameterName()] = $sluggable->getId();
     $parameterList[$configuration->getRouteSlugParameterName()] = $this->slugger->slug($sluggable);
     return $this->urlGenerator->generate($configuration->getRouteName(), $parameterList);
 }
Exemplo n.º 18
0
 /**
  * Add Free payment method
  *
  * @param PaymentCollectionEvent $event Event
  */
 public function addFreePaymentPaymentMethod(PaymentCollectionEvent $event)
 {
     if ($this->plugin->isUsable()) {
         $freePayment = new PaymentMethod($this->plugin->getHash(), 'elcodi_plugin.free_payment.name', 'elcodi_plugin.free_payment.description', $this->router->generate('freepayment_payment_routes'));
         $event->addPaymentMethod($freePayment);
     }
 }
 /**
  * @depends testUrlGeneratorInterface
  *
  * @param UrlGeneratorInterface $generator
  */
 public function testUrlGenerationWithFragment($generator)
 {
     $path = $generator->generate('foo', ['#' => 'bolt']);
     $this->assertSame('/foo/bar#bolt', $path);
     $path = $generator->generate('foo', ['hello' => 'world', '#' => 'bolt']);
     $this->assertSame('/foo/bar?hello=world#bolt', $path);
 }
Exemplo n.º 20
0
 /**
  * Generates referral program tracking route
  *
  * @param ReferralHashInterface $referralHash Referral hash
  *
  * @return string
  */
 public function generateControllerRoute(ReferralHashInterface $referralHash)
 {
     /**
      * Referral link generation
      */
     return $this->routeGenerator->generate($this->controllerRouteName, array('hash' => $referralHash->getHash()), true);
 }
 /**
  * @param string|null $build
  * @return string
  */
 public function getAppCachePath($build = null)
 {
     $build = $build ?: $this->application->getDefaultBuild();
     if (!$this->application->hasAppCache($build)) {
         return '';
     }
     return $this->generator->generate('tq_extjs_application_appcache', ['build' => $build, 'dev' => $this->application->isDevelopment() ? '-dev' : '']);
 }
Exemplo n.º 22
0
 /**
  * @param int $shoppingListId
  * @param int $entitiesCount
  * @param null|string $transChoiceKey
  * @return string
  */
 public function getSuccessMessage($shoppingListId = null, $entitiesCount = 0, $transChoiceKey = null)
 {
     $message = $this->translator->transChoice($transChoiceKey ?: 'orob2b.shoppinglist.actions.add_success_message', $entitiesCount, ['%count%' => $entitiesCount]);
     if ($shoppingListId && $entitiesCount > 0) {
         $message = sprintf('%s (<a href="%s">%s</a>).', $message, $this->router->generate('orob2b_shopping_list_frontend_view', ['id' => $shoppingListId]), $linkTitle = $this->translator->trans('orob2b.shoppinglist.actions.view'));
     }
     return $message;
 }
Exemplo n.º 23
0
 /**
  * @ApiDoc(
  *     section="Shift",
  *     description="Create a Shift",
  *     input="ShiftBundle\Model\ShiftCreation",
  *     statusCodes={
  *         201 = "Successfully created the shift",
  *     },
  * )
  * @Method("PUT")
  * @Route()
  * @View(statusCode=201)
  * @param ShiftCreationInterface $shiftCreation
  * @param ConstraintViolationListInterface $validationErrors
  * @ParamConverter(name="shiftCreation", converter="fos_rest.request_body", class="ShiftBundle\Model\ShiftCreation")
  * @return Response
  */
 public function createAction(ShiftCreationInterface $shiftCreation, ConstraintViolationListInterface $validationErrors)
 {
     if (count($validationErrors) > 0) {
         throw new ConstraintViolationBadRequestException($validationErrors);
     }
     $shift = $this->shiftHandler->create($shiftCreation);
     return new Response(null, Response::HTTP_CREATED, ['Location' => $this->urlGenerator->generate('shift_shift_details', ['shift' => $shift->getId()])]);
 }
Exemplo n.º 24
0
 private function failRegistration($message, GetResponseUserEvent $event)
 {
     //        throw new \Exception($message);
     /** @var Session $session */
     $session = $event->getRequest()->getSession();
     $session->getFlashBag()->set('error', $message);
     $event->setResponse(new RedirectResponse($this->urlGenerator->generate('fda_dsb_homepage')));
 }
 /**
  * Creates a provider of the given class.
  *
  * @param string $class
  * @param array $options
  * @param string $redirectUri
  * @param array $redirectParams
  * @return mixed
  */
 public function createProvider($class, array $options, $redirectUri, array $redirectParams = [])
 {
     $redirectUri = $this->generator->generate($redirectUri, $redirectParams, UrlGeneratorInterface::ABSOLUTE_URL);
     $options['redirectUri'] = $redirectUri;
     // todo - make this configuration when someone needs this
     $collaborators = [];
     return new $class($options, $collaborators);
 }
Exemplo n.º 26
0
 /**
  * @param PurchaseCompleteEvent $event
  */
 public function abandonCart(PurchaseCompleteEvent $event)
 {
     if (in_array($event->getSubject()->getState(), [PaymentInterface::STATE_PENDING, PaymentInterface::STATE_PROCESSING, PaymentInterface::STATE_COMPLETED])) {
         $this->cartProvider->abandonCart();
         return;
     }
     $event->setResponse(new RedirectResponse($this->router->generate($this->redirectTo)));
 }
Exemplo n.º 27
0
 /**
  * {@inheritdoc}
  */
 public function generate($name, array $parameters, $absolute = false)
 {
     // If is it at least Symfony 2.8 and $absolute is passed as boolean
     if (SymfonyUrlGeneratorInterface::ABSOLUTE_PATH === 1 && is_bool($absolute)) {
         $absolute = $absolute ? SymfonyUrlGeneratorInterface::ABSOLUTE_URL : SymfonyUrlGeneratorInterface::ABSOLUTE_PATH;
     }
     return $this->urlGenerator->generate($name, $parameters, $absolute);
 }
 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if (!$exception instanceof InsufficientStockException) {
         return;
     }
     $this->session->getBag('flashes')->add('notice', $this->translator->trans('sylius.checkout.out_of_stock', ['%quantity%' => $exception->getStockable()->getOnHand(), '%name%' => $exception->getStockable()->getInventoryName()], 'flashes'));
     $event->setResponse(new RedirectResponse($this->router->generate($this->redirectTo)));
 }
 /**
  * {@inheritdoc}
  *
  * @param OriginalRouteReadInterface $content
  */
 public function updateMetadata($content, SeoMetadataInterface $seoMetadata)
 {
     $route = $content->getSeoOriginalRoute();
     try {
         $seoMetadata->setOriginalUrl($this->urlGenerator->generate($route));
     } catch (RouteNotFoundException $e) {
         throw new ExtractorStrategyException('Unable to create a url.', 0, $e);
     }
 }
 /**
  * Generates a dynamic route with replaced parameters
  *
  * @param array $replacements
  *
  * @return string
  */
 public function getDynamicPath(array $replacements = [])
 {
     $route = $this->requestHelper->getAttributesBagParam('_route');
     $currentAttributesParams = $this->requestHelper->getAttributesBagParam('_route_params');
     $currentQueryParams = $this->requestHelper->getCurrentRequest()->query->all();
     $routeParams = array_replace($currentAttributesParams, $replacements);
     $routeParams = array_merge($routeParams, $currentQueryParams);
     return $this->generator->generate($route, $routeParams);
 }