本文整理汇总了PHP中Symfony\Component\Routing\RouterInterface::generate方法的典型用法代码示例。如果您正苦于以下问题:PHP RouterInterface::generate方法的具体用法?PHP RouterInterface::generate怎么用?PHP RouterInterface::generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\RouterInterface
的用法示例。
在下文中一共展示了RouterInterface::generate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: encode
/**
* @param Url $url
* @return Url|object
* @throws \Doctrine\DBAL\ConnectionException
* @throws \Exception
*/
public function encode(Url $url)
{
$this->em->beginTransaction();
try {
$urlRepository = $this->em->getRepository('Rz\\Bundle\\UrlShortenerBundle\\Entity\\Url');
$entity = $urlRepository->findOneBy(['url' => $url->getUrl()]);
if ($entity) {
/** @var Url $url */
$url = $entity;
} else {
$url->setNew(true);
$this->em->persist($url);
$this->em->flush();
$url->setCode($this->encoder->encode($url->getId()));
$params = ['code' => $url->getCode()];
if (!$url->isDefaultSequence()) {
$params['index'] = $url->getSequence();
}
$url->setShortUrl($this->router->generate(UrlShortenerBundle::URL_GO, $params, UrlGeneratorInterface::ABSOLUTE_URL));
$this->em->persist($url);
$this->em->flush();
}
$this->em->getConnection()->commit();
return $url;
} catch (\Exception $e) {
$this->em->getConnection()->rollBack();
throw $e;
}
}
示例2: serializeRouteArrayToJson
public function serializeRouteArrayToJson(JsonSerializationVisitor $visitor, array $route, array $type, Context $context)
{
if (is_array($route)) {
list($routeName, $routeParameters) = $route;
return $this->router->generate($routeName, $routeParameters);
}
}
示例3: redirectToRoute
/**
* @param string $route
* @param array $data
*
* @return RedirectResponse
*/
public function redirectToRoute($route, array $data = array())
{
if ('referer' === $route) {
return $this->redirectToReferer();
}
return $this->redirect($this->router->generate($route, $data));
}
示例4: onKernelController
public function onKernelController(FilterControllerEvent $event)
{
$controller = $event->getController();
if (!is_array($controller)) {
return;
}
$session = $event->getRequest()->getSession();
/** @var BaseController $ctrl */
$ctrl = $controller[0];
if (!is_object($ctrl) || !$ctrl instanceof BaseController) {
return;
}
// no loop for you, also allow username checking
if ($ctrl instanceof ProfileController && ($controller[1] == 'updateUsernameAction' || $controller[1] == 'checkUsernameAction')) {
return;
}
/** @var User $user */
$user = $ctrl->getUser();
if ($user && $this->isGUID($user->getUsername())) {
$session->getFlashBag()->add('error', "We recently changed our username restrictions. Your previous username is no longer valid. Please create a new one.");
$url = $this->router->generate('reset_username');
$event->setController(function () use($url) {
return new RedirectResponse($url);
});
}
}
示例5: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
$routes = $this->router->getRouteCollection();
$route = $routes->get($request->attributes->get('_route'));
if (!$route->getOption('requires_license')) {
return;
}
if ('active' != $request->get('lic') && $this->kernel->getEnvironment() == 'prod') {
// Checking for whitelisted users
try {
$user = $this->tokenStorage->getToken()->getUser();
$today = date('Y-m-d');
if ($user instanceof UserInterface) {
$whitelist = $this->kernel->getContainer()->getParameter('license_whitelist');
foreach ($whitelist as $allowed) {
if ($allowed['client_key'] == $user->getClientKey() && $today <= $allowed['valid_till']) {
return;
}
}
}
} catch (\Exception $e) {
// Do nothing
}
$url = $this->router->generate('atlassian_connect_unlicensed');
$response = new RedirectResponse($url);
$event->setResponse($response);
}
}
示例6: onLogoutSuccess
/**
* Creates a Response object to send upon a successful logout.
*
* @param Request $request
*
* @return Response never null
*/
public function onLogoutSuccess(Request $request)
{
if ($request->isXmlHttpRequest() or 'json' == $request->getRequestFormat()) {
return new JsonResponse(true);
}
return new RedirectResponse($this->router->generate('homepage'));
}
示例7: createCollection
public function createCollection(QueryBuilder $qb, Request $request, $route, array $routeParams = array())
{
$page = $request->query->get(self::PARAMETER_NAME_PAGE_NUMBER, 1);
$count = $request->query->get(self::PARAMETER_NAME_PAGE_SIZE, self::PAGE_DEFAULT_COUNT);
if ($count > self::MAX_PAGE_COUNT) {
$count = self::MAX_PAGE_COUNT;
}
if ($count <= 0) {
$count = self::PAGE_DEFAULT_COUNT;
}
$adapter = new DoctrineORMAdapter($qb);
$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setMaxPerPage($count);
$pagerfanta->setCurrentPage($page);
$players = [];
foreach ($pagerfanta->getCurrentPageResults() as $result) {
$players[] = $result;
}
$paginatedCollection = new PaginatedCollection($players, $pagerfanta->getNbResults());
// make sure query parameters are included in pagination links
$routeParams = array_merge($routeParams, $request->query->all());
$createLinkUrl = function ($targetPage) use($route, $routeParams) {
return $this->router->generate($route, array_merge($routeParams, array(self::PARAMETER_NAME_PAGE_NUMBER => $targetPage)));
};
$paginatedCollection->addLink('self', $createLinkUrl($page));
$paginatedCollection->addLink('first', $createLinkUrl(1));
$paginatedCollection->addLink('last', $createLinkUrl($pagerfanta->getNbPages()));
if ($pagerfanta->hasNextPage()) {
$paginatedCollection->addLink('next', $createLinkUrl($pagerfanta->getNextPage()));
}
if ($pagerfanta->hasPreviousPage()) {
$paginatedCollection->addLink('prev', $createLinkUrl($pagerfanta->getPreviousPage()));
}
return $paginatedCollection;
}
示例8: __invoke
/**
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
* @throws \Exception
*/
public function __invoke(Request $request)
{
$user = $this->getUser();
if (!$user) {
throw $this->createAccessDeniedException();
}
$createWalletCommand = $this->createCreateWalletCommand();
$createWalletForm = $this->walletFormFactory->createCreateForm($createWalletCommand);
$createWalletForm->handleRequest($request);
if (!$createWalletForm->isValid()) {
$validationMsg = $this->getAllFormErrorMessagesAsString($createWalletForm);
$this->addFlash('error', $this->trans('create_transaction_form.flash.invalid_form') . ' ' . $validationMsg);
} else {
/** @var CreateWalletCommand $createWalletCommand */
$createWalletCommand = $createWalletForm->getData();
$createWalletCommand->setWalletOwnerId($user->getId()->getValue());
$createWalletCommand->setToken($user->getBlockCypherToken());
try {
$commandValidator = new CreateWalletCommandValidator();
$commandValidator->validate($createWalletCommand);
$this->commandBus->handle($createWalletCommand);
$this->addFlash('success', $this->trans('wallet.flash.create_successfully'));
$url = $this->router->generate('bc_app_wallet_wallet.index');
return new RedirectResponse($url);
} catch (\Exception $e) {
$this->addFlash('error', $e->getMessage());
}
}
return $this->renderWalletShowNew($request, $createWalletForm->createView());
}
示例9: finishView
/**
* {@inheritdoc}
*/
public function finishView(FormView $view, FormInterface $form, array $options)
{
$data = $view->parent->vars['value'];
if (is_object($data)) {
$view->vars['grid_url'] = $this->router->generate('oro_entity_relation', ['id' => $data->getId() ? $data->getId() : 0, 'entityName' => str_replace('\\', '_', get_class($data)), 'fieldName' => $form->getName()]);
}
}
示例10: generateForOrderCheckoutState
/**
* {@inheritdoc}
*/
public function generateForOrderCheckoutState(OrderInterface $order, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
{
if (!isset($this->routeCollection[$order->getCheckoutState()]['route'])) {
throw new RouteNotFoundException();
}
return $this->router->generate($this->routeCollection[$order->getCheckoutState()]['route'], $parameters, $referenceType);
}
示例11: generateUrl
/**
* {@inheritdoc}
*/
public function generateUrl(StoredFile $storedFile)
{
$storageKey = $storedFile->getStorageKey();
$storageKey .= '/' . $storedFile->getRepository()->getName();
$storageKey .= '/' . $storedFile->getFilename();
return $this->router->generate($this->routeName, array('storageKey' => $storageKey), RouterInterface::NETWORK_PATH);
}
示例12: configureTabMenu
/**
* @throws InvalidConfigurationException
*/
public function configureTabMenu(AdminInterface $admin, MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
{
if (!($subject = $admin->getSubject())) {
return;
}
if (!$subject instanceof RouteReferrersReadInterface && !$subject instanceof Route) {
throw new InvalidConfigurationException(sprintf('%s can only be used on subjects which implement Symfony\\Cmf\\Component\\Routing\\RouteReferrersReadInterface or Symfony\\Component\\Routing\\Route.', __CLASS__));
}
if ($subject instanceof PrefixInterface && !is_string($subject->getId())) {
// we have an unpersisted dynamic route
return;
}
$defaults = array();
if ($subject instanceof TranslatableInterface) {
if ($locale = $subject->getLocale()) {
$defaults['_locale'] = $locale;
}
}
try {
$uri = $this->router->generate($subject, $defaults);
} catch (RoutingExceptionInterface $e) {
// we have no valid route
return;
}
$menu->addChild($this->translator->trans('admin.menu_frontend_link_caption', array(), 'CmfRoutingBundle'), array('uri' => $uri, 'attributes' => array('class' => 'sonata-admin-menu-item', 'role' => 'menuitem'), 'linkAttributes' => array('class' => 'sonata-admin-frontend-link', 'role' => 'button', 'target' => '_blank', 'title' => $this->translator->trans('admin.menu_frontend_link_title', array(), 'CmfRoutingBundle'))));
}
示例13: onHit
/**
* @param HitEvent $event
*/
public function onHit(HitEvent $event)
{
if ($event->getMetadata()->reflection->getName() !== 'Sulu\\Bundle\\EventBundle\\Entity\\Event') {
return;
}
$locale = $this->requestAnalyzer->getCurrentLocalization()->getLocalization();
$document = $event->getHit()->getDocument();
$eventApiEntity = $this->eventManager->findByIdAndLocale($document->getId(), $locale);
if (!$eventApiEntity) {
return;
}
$startDate = $eventApiEntity->getStartDate();
$endDate = $eventApiEntity->getEndDate();
$categories = $eventApiEntity->getCategories();
$categoryTitles = array();
foreach ($categories as $category) {
$categoryTitles[] = $category->getName();
}
$startDateField = new Field('start_date', $startDate->format('c'), Field::TYPE_STRING);
$document->addField($startDateField);
if ($endDate) {
$endDateField = new Field('end_date', $endDate->format('c'), Field::TYPE_STRING);
$document->addField($endDateField);
}
$categoryTitleField = new Field('category_title', implode(', ', $categoryTitles), Field::TYPE_STRING);
$document->addField($categoryTitleField);
$url = $this->router->generate('sulu_events.detail', array('id' => $eventApiEntity->getId(), 'slug' => $eventApiEntity->getSlug()));
$document->setUrl($url);
}
示例14: createPayment
/**
* @param array $items
* @param $shippingDetails
* @param string $intent
* @throws Exception
* @return null|string
*/
public function createPayment(array $items, Details $shippingDetails, $intent = PaymentConst::INTENT_SALE)
{
$apiContext = $this->connectionService->getApiContext();
$dispatcher = $this->connectionService->getDispatcher();
$dispatcher->dispatch(PaymentEvent::NEW_SETUP);
$successUrl = '';
$cancelUrl = '';
switch ($intent) {
case PaymentConst::INTENT_SALE:
$successUrl = $this->router->generate('paypal_payment_sale_success', array(), true);
$cancelUrl = $this->router->generate('paypal_payment_sale_cancel', array(), true);
break;
case PaymentConst::INTENT_AUTHORIZE:
$successUrl = $this->router->generate('paypal_payment_authorize_success', array(), true);
$cancelUrl = $this->router->generate('paypal_payment_authorize_cancel', array(), true);
break;
}
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($successUrl)->setCancelUrl($cancelUrl);
$payment = PaymentService::create($items, $shippingDetails, $intent, PaymentConst::METHOD_PAYPAL);
$payment->setRedirectUrls($redirectUrls);
$paymentEvent = new PayPalPaymentEvent($payment);
$dispatcher->dispatch(PaymentEvent::NEW_START, $paymentEvent);
$result = $payment->create($apiContext);
$paymentEvent = new PayPalPaymentEvent($result);
$dispatcher->dispatch(PaymentEvent::NEW_END, $paymentEvent);
$payment->create($apiContext);
$approvalUrl = $payment->getApprovalLink();
return $approvalUrl;
}
示例15: onMainTopMenuTools
public function onMainTopMenuTools(HookRenderBlockEvent $event)
{
$isGranted = $this->securityContext->isGranted(["ADMIN"], [], [BoSearch::getModuleCode()], [AccessManager::VIEW]);
if ($isGranted) {
$event->add(['title' => $this->trans('Search product', [], BoSearch::DOMAIN_NAME), 'url' => $this->router->generate('bosearch.product.view')]);
}
}