当前位置: 首页>>代码示例>>PHP>>正文


PHP Routing\Router类代码示例

本文整理汇总了PHP中Symfony\Component\Routing\Router的典型用法代码示例。如果您正苦于以下问题:PHP Router类的具体用法?PHP Router怎么用?PHP Router使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Router类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct(Session $session, Router $router, $environement, $merchant_pos_id, $pos_auth_key, $client_id, $client_secret, $signature_key)
 {
     $this->session = $session;
     $this->session->start();
     $this->environment = $environement;
     $this->merchantPosId = $merchant_pos_id;
     $this->posAuthKey = $pos_auth_key;
     $this->clientId = $client_id;
     $this->clientSecret = $client_secret;
     $this->signatureKey = $signature_key;
     $this->currencyCode = 'PLN';
     // TODO: from configuration
     $this->orderType = self::ORDER_TYPE_VIRTUAL;
     \OpenPayU_Configuration::setEnvironment($this->environment);
     \OpenPayU_Configuration::setMerchantPosId($this->merchantPosId);
     \OpenPayU_Configuration::setPosAuthKey($this->posAuthKey);
     \OpenPayU_Configuration::setClientId($this->clientId);
     \OpenPayU_Configuration::setClientSecret($this->clientSecret);
     \OpenPayU_Configuration::setSignatureKey($this->signatureKey);
     $this->authUrl = \OpenPayU_Configuration::$authUrl;
     $this->summaryUrl = \OpenPayU_Configuration::$summaryUrl;
     $this->notifyUrl = $router->generate('webultdPayuPaymentBundle_status', array(), true);
     $this->cancelUrl = $router->generate('webultdPayuPaymentBundle_cancel', array(), true);
     $this->completeUrl = $router->generate('webultdPayuPaymentBundle_success', array(), true);
 }
开发者ID:webultd,项目名称:webultdpayupaymentbundle,代码行数:25,代码来源:Api.php

示例2: createSubjectTreeView

 /**
  * @param $type
  * @param Router $router
  * @param ArrayCollection|Subject[] $subjects
  * @param int|null $parentId
  * @return string
  */
 public static function createSubjectTreeView($type, $router, $subjects, $parentId = null)
 {
     $tree = '<ul>%s</ul>';
     $item = '<li>%s</li>';
     $link = '<a href="%s">%s</a>';
     $items = "";
     /**
      * @var Subject $subject
      * @var ArrayCollection $children
      */
     foreach ($subjects as $subject) {
         if ($subject->getParent() === null || $subject->getParent()->getId() === $parentId) {
             if ($type == TreeHelper::SUBJECT_ADMIN) {
                 $path = $router->generate('ojs_admin_subject_show', ['id' => $subject->getId()]);
             } else {
                 $path = $router->generate('ojs_search_index', ['subject_filters' => $subject->getSubject()]);
             }
             $content = sprintf($link, $path, $subject->getSubject());
             $children = $subject->getChildren();
             if ($children->count() > 0) {
                 $content = $content . TreeHelper::createSubjectTreeView($type, $router, $children, $subject->getId());
             }
             $items = $items . sprintf($item, $content);
         }
     }
     return sprintf($tree, $items);
 }
开发者ID:ulakjira,项目名称:ojs,代码行数:34,代码来源:TreeHelper.php

示例3: matchRoute

 private function matchRoute($routePath)
 {
     $locator = new FileLocator(array($this->container->getParameter('configDir')));
     $router = new Router(new YamlFileLoader($locator), 'routes.yml', array('cache_dir' => null), $this->requestContext);
     $parameters = $router->match($routePath);
     return $parameters;
 }
开发者ID:pascal-c,项目名称:groupfony-framework,代码行数:7,代码来源:Routing.php

示例4: route

 public function route($url)
 {
     try {
         $context = new RequestContext();
         $context->fromRequest($this->_request);
         $closure = function () {
             return $this->_container->get('routes');
         };
         $arrpar = array();
         if (!DEVELOPMENT_ENVIRONMENT) {
             $arrpar['cache_dir'] = ROUTECACHE;
         } else {
             \Debug::addRoutes($closure);
         }
         $router = new SymfonyRouter(new ClosureLoader(), $closure, $arrpar, $context);
         $parameters = $router->match($url);
         $this->_controller = $parameters["controller"];
         $this->_method = $parameters["action"];
         $this->_route = $parameters["_route"];
         unset($parameters["controller"]);
         unset($parameters["action"]);
         unset($parameters["_route"]);
         $this->_args = $parameters;
     } catch (ResourceNotFoundException $e) {
         $this->_route = "";
     } catch (\Symfony\Component\Routing\Exception\MethodNotAllowedException $ema) {
         $this->_route = "";
         throw new \GL\Core\Exception\MethodNotAllowedException();
     }
     return $this->_route != "";
 }
开发者ID:kletellier,项目名称:mvc,代码行数:31,代码来源:Router.php

示例5: __construct

 public function __construct(Request $request, Router $router)
 {
     parent::__construct();
     $this->setCurrentUri($request->getRequestUri());
     $this->addChild('Song Library', $router->generate('song'));
     $this->addChild('Add Song to Library', $router->generate('song_create'));
 }
开发者ID:rogchap,项目名称:Diakonia,代码行数:7,代码来源:SongMenu.php

示例6: doWebPayment

 /**
  * @see : 3.1.1 PAYLINE-GUIDE-Descriptif des appels webservices.
  * @param Order $order
  * @return RedirectResponse
  * @throws \Exception
  */
 public function doWebPayment(Order $order)
 {
     /** @var Customer $subscriber */
     $customer = $order->getCustomer();
     $array['version'] = self::VERSION;
     $array['returnURL'] = $this->frontRouter->generate('order.placed', ['order_id' => $order->getId()], true);
     $array['cancelURL'] = $this->frontRouter->generate('order.failed', ['order_id' => $order->getId(), 'message' => 'payline'], true);
     $array['notificationURL'] = $this->paylineRouter->generate('payline_notify', ['orderId' => $order->getId()], true);
     $amount = (double) $order->getTotalAmount() * 100;
     $currency = CurrencyNumericCodeQuery::create()->findPk($order->getCurrency()->getCode())->getNumericCode();
     $array['payment']['amount'] = $amount;
     $array['payment']['currency'] = $currency;
     $array['payment']['action'] = '100';
     $array['payment']['mode'] = 'CPT';
     $array['payment']['contractNumber'] = $this->config->getContractNumber();
     $array['order']['ref'] = $order->getRef();
     $array['order']['amount'] = $amount;
     $array['order']['currency'] = $currency;
     $array['order']['date'] = $order->getUpdatedAt()->format('d/m/Y H:m');
     $array['buyer']['lastName'] = $customer->getLastName();
     $array['buyer']['firstName'] = $customer->getFirstName();
     $array['buyer']['email'] = $customer->getEmail();
     $array['securityMode'] = 'SSL';
     $response = $this->payline->doWebPayment($array);
     $code = $response['result']['code'];
     if ($code !== '00000') {
         $message = isset($response['result']['longMessage']) ? $response['result']['longMessage'] : 'Error undefined';
         $this->logger->error($message);
         throw new \Exception($message);
     }
     return new RedirectResponse($response['redirectURL']);
 }
开发者ID:Alban-io,项目名称:Payline,代码行数:38,代码来源:PaylineManager.php

示例7: register

 /**
  * {@inheritdoc}
  */
 public function register(Container $app)
 {
     /**
      * Holds information about the current request
      *
      * @return RequestContext
      */
     $app['request_context'] = function () use($app) {
         $context = new RequestContext();
         // set default http & https ports if not set
         $context->setHttpPort(isset($app['request.http_port']) ? $app['request.http_port'] : 80);
         $context->setHttpsPort(isset($app['request.https_port']) ? $app['request.https_port'] : 443);
         return $context;
     };
     /**
      * Matches URL based on a set of routes.
      *
      * @return UrlMatcher
      */
     $app['matcher'] = function () use($app) {
         return new UrlMatcher($app['router'], $app['request_context']);
     };
     /**
      * Router
      */
     $options = array('cache_dir' => true === $app['use_cache'] ? __DIR__ . '/' . self::CACHE_DIRECTORY : null, 'debug' => true);
     $app['router'] = function () use($app, $options) {
         $router = new Router($app['config.loader'], sprintf(self::CONFIG_ROUTES_FILE, $app['env']), $options);
         return $router->getRouteCollection();
     };
 }
开发者ID:nkstamina,项目名称:framework,代码行数:34,代码来源:RoutingServiceProvider.php

示例8: __construct

 public function __construct(Router $router, ContainerInterface $container)
 {
     $this->routeCollection = $router->getRouteCollection();
     $this->translator = $container->get('translator');
     $this->translationDomain = $container->getParameter('symfonian_id.admin.translation_domain');
     $this->authorizationChecker = $container->get('security.authorization_checker');
 }
开发者ID:deryfebriantara,项目名称:AdminBundle,代码行数:7,代码来源:Builder.php

示例9: Item

 function it_should_create_translations_tools_menu(MenuEvent $menuEvent, Router $router)
 {
     $menuItem = new Item();
     $menuEvent->getMenu()->willReturn($menuItem);
     $router->generate('some_admin_route', array('locale' => 'en', 'element' => 'element'), UrlGeneratorInterface::ABSOLUTE_PATH)->willReturn('/admin/en/list/element');
     $router->generate('some_admin_route', array('locale' => 'pl', 'element' => 'element'), UrlGeneratorInterface::ABSOLUTE_PATH)->willReturn('/admin/pl/list/element');
     $router->generate('some_admin_route', array('locale' => 'de', 'element' => 'element'), UrlGeneratorInterface::ABSOLUTE_PATH)->willReturn('/admin/de/list/element');
     $this->createTranslationLocaleMenu($menuEvent);
     $rootItem = $menuItem->getChildren();
     $translationLocale = $rootItem['translation-locale'];
     expect($translationLocale->getLabel())->toBe('Menu label');
     expect($translationLocale->getOption('attr'))->toHaveOption('id', 'translatable-switcher');
     /** @var \FSi\Bundle\AdminBundle\Menu\Item\RoutableItem[] $subItems */
     $subItems = $translationLocale->getChildren();
     $localePl = $subItems['translation-locale.pl'];
     $localeEn = $subItems['translation-locale.en'];
     $localeDe = $subItems['translation-locale.de'];
     expect($localePl->getLabel())->toBe('Polish');
     expect($localePl->getRoute())->toBe('admin_translatable_list');
     expect($localePl->getRouteParameters())->toBe(array('element' => 'event', 'locale' => 'pl', 'param1' => 'val1', 'redirect_uri' => '/admin/pl/list/element?param=value'));
     expect($translationLocale->getOption('attr'))->toNotHaveOption('class', 'active');
     expect($localeEn->getLabel())->toBe('English');
     expect($localeEn->getRoute())->toBe('admin_translatable_list');
     expect($localeEn->getRouteParameters())->toBe(array('element' => 'event', 'locale' => 'en', 'param1' => 'val1', 'redirect_uri' => '/admin/en/list/element?param=value'));
     expect($translationLocale->getOption('attr'))->toNotHaveOption('class', 'active');
     expect($localeDe->getLabel())->toBe('German');
     expect($localeDe->getRoute())->toBe('admin_translatable_list');
     expect($localeDe->getRouteParameters())->toBe(array('element' => 'event', 'locale' => 'de', 'param1' => 'val1', 'redirect_uri' => '/admin/de/list/element?param=value'));
     expect($translationLocale->getOption('attr'))->toNotHaveOption('class', 'active');
 }
开发者ID:szymach,项目名称:admin-translatable-bundle,代码行数:30,代码来源:TranslationLocaleMenuListenerSpec.php

示例10: __construct

 /**
  * @param RouterInterface $router
  */
 public function __construct(Router $router)
 {
     /**
      * @var UrlGenerator $urlGenerator
      */
     $urlGenerator = $router->getGenerator();
     $this->urlGenerator = $urlGenerator;
 }
开发者ID:cleentfaar,项目名称:simplr-core,代码行数:11,代码来源:ExceptionListener.php

示例11: postGif

 public function postGif(Gif $gif)
 {
     $gifUrl = $this->router->generate('gif', ['permalink' => $gif->getPermalink()], true);
     $gifUrl = Util::fixSymfonyGeneratedURLs($gifUrl);
     $tweetContent = $gif->generateTweet($gifUrl);
     return $this->postTweet($tweetContent);
 }
开发者ID:MrMitch,项目名称:Les-Joies-de-Supinfo,代码行数:7,代码来源:TwitterService.php

示例12: process

 public function process($data)
 {
     $mergedData = array_merge($this->defaults, $data);
     // generating urls
     if (isset($mergedData['url']) && $mergedData['url'] && strpos($mergedData['url'], '/') === false) {
         $url = $this->router->generate($mergedData['url'], array(), true);
         $mergedData['url'] = $url;
     }
     if (isset($mergedData['urlc']) && $mergedData['urlc'] && strpos($mergedData['urlc'], '/') === false) {
         $urlc = $this->router->generate($mergedData['urlc'], array(), true);
         $mergedData['urlc'] = $urlc;
     }
     $form = $this->form;
     $form->bind($mergedData);
     if (!$form->isValid()) {
         $errors = array();
         foreach ($form->getErrors() as $error) {
             /* @var \Symfony\Component\Form\FormError $error */
             $errors[] = $error->getMessageTemplate();
         }
         $logger = $this->logger;
         $logger->err('Params: ' . json_encode($mergedData));
         $logger->err('Errors: ' . json_encode($errors));
         throw new \InvalidArgumentException('Invalid action parameters. Check profiler log information for more details');
     }
     return $form;
 }
开发者ID:hatimeria,项目名称:HatimeriaDotpayBundle,代码行数:27,代码来源:RequestFormHandler.php

示例13: getEntityUrl

 /**
  * Get url for entity
  *
  * @param object $entity
  * @param $item \Oro\Bundle\SearchBundle\Query\Result\Item
  * @return string
  */
 protected function getEntityUrl($entity, $item)
 {
     $name = $item->getEntityName();
     $entityMeta = $this->em->getClassMetadata($name);
     $identifierField = $entityMeta->getSingleIdentifierFieldName($entityMeta);
     if ($this->mapper->getEntityMapParameter($name, 'route')) {
         $routeParameters = $this->mapper->getEntityMapParameter($name, 'route');
         $routeData = array();
         if ($this->isParametersDefined($routeParameters)) {
             /**
              * NOTE: possible to generate url without entity object if only identifier field needed
              */
             $idKey = array_search($identifierField, $routeParameters['parameters']);
             $needToHaveEntity = $idKey === false || count($routeParameters['parameters']) > 1;
             if (!$entity && $needToHaveEntity) {
                 $entity = $this->em->getRepository($name)->find($item->getRecordId());
             }
             foreach ($routeParameters['parameters'] as $parameter => $field) {
                 if ($entity) {
                     $routeData[$parameter] = $this->mapper->getFieldValue($entity, $field);
                 } else {
                     $routeData[$parameter] = $item->getRecordId();
                 }
             }
         }
         return $this->router->generate($routeParameters['name'], $routeData, true);
     }
     return '';
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:36,代码来源:PrepareResultItemListener.php

示例14: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
         return;
     }
     $request = $event->getRequest();
     $fc_form = $this->form_service->guessFcForm($request);
     if (!$fc_form instanceof FcForm) {
         return;
     }
     if ($fc_form->getAction()) {
         return;
     }
     /** @var FormInterface $form */
     $form = $this->form_service->create($fc_form);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $this->form_service->clear($fc_form, array('template' => $data['_template'], 'data' => $this->form_service->initData($data)));
         if ($fc_form->getIsAjax()) {
             return;
         }
         if ($fc_form->getMessage()) {
             $message = $fc_form->getMessage();
         } else {
             $message = $this->translator->trans('fc.message.form.is_valid', array(), 'FenrizbesFormConstructorBundle');
         }
         // TODO: Связывать сообщение с конкретной формой и подчищать старые
         $this->session->getFlashBag()->add('fc_form.success', $message);
         $response = new RedirectResponse($this->router->generate($request->get('_route'), $request->get('_route_params')));
         $event->setResponse($response);
     }
 }
开发者ID:it-blaster,项目名称:form-constructor-bundle,代码行数:33,代码来源:RequestListener.php

示例15: onKernelRequest

 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     // don't redirect in dev
     if ($this->isDebug) {
         return;
     }
     $request = $event->getRequest();
     $locale = $request->attributes->get('_locale');
     // nothing to do here, not a URL that has to do with _locale route param
     if (null === $locale) {
         return;
     }
     // locale exists and is enabled, nothing to do here - return;
     if ($this->manager->isLocaleEnabled($locale)) {
         return;
     }
     $route = $request->attributes->get('_route');
     // no route found, nothing to do here - return; and let the 404 handler do its job
     if (null === $route) {
         return;
     }
     $params = array_replace_recursive($request->attributes->get('_route_params', []), ['_locale' => $this->usePreferredLocale ? $this->manager->getPreferredLocale() : $this->manager->getDefaultLocale()]);
     // generate a url for the same route with the same params, but with the default locale
     $url = $this->router->generate($route, $params, UrlGeneratorInterface::ABSOLUTE_URL);
     // append query string if any
     $qs = $request->getQueryString();
     if ($qs) {
         $url = $url . '?' . $qs;
     }
     $response = new RedirectResponse($url, Response::HTTP_FOUND);
     $event->setResponse($response);
 }
开发者ID:wucdbm,项目名称:locale-bundle,代码行数:35,代码来源:DisabledLocaleRedirectListener.php


注:本文中的Symfony\Component\Routing\Router类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。