當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Routing\Router類代碼示例

本文整理匯總了PHP中Symfony\Bundle\FrameworkBundle\Routing\Router的典型用法代碼示例。如果您正苦於以下問題:PHP Router類的具體用法?PHP Router怎麽用?PHP Router使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Router類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 /**
  * Constructor
  * Initialize some default items.
  *
  * @param Router $router
  */
 public function __construct(Router $router)
 {
     $this->items = array();
     $this->lastPosition = 0;
     $this->separatorCount = 0;
     $this->add('base.user.menu.admin')->setIcon('gear.png')->setUrl($router->generate('orga_admin'))->end()->add('base.user.menu.members')->setIcon('users.png')->setUrl($router->generate('orga_admin_members'))->end()->add('base.user.menu.logout')->setIcon('control-power.png')->setUrl($router->generate('user_disconnect'))->end()->addSeparator()->add('base.user.menu.help')->setIcon('question.png')->setUrl('')->end();
 }
開發者ID:ChrisdAutume,項目名稱:EtuUTT,代碼行數:13,代碼來源:OrgaMenuBuilder.php

示例2: testPlaceholders

 public function testPlaceholders()
 {
     $routes = new RouteCollection();
     $routes->add('foo', new Route('/foo', array('foo' => '%foo%', 'bar' => '%bar%', 'foobar' => 'foobar', 'foo1' => '%foo', 'foo2' => 'foo%', 'foo3' => 'f%o%o'), array('foo' => '%foo%', 'bar' => '%bar%', 'foobar' => 'foobar', 'foo1' => '%foo', 'foo2' => 'foo%', 'foo3' => 'f%o%o')));
     $sc = $this->getServiceContainer($routes);
     $sc->expects($this->at(1))->method('hasParameter')->will($this->returnValue(false));
     $sc->expects($this->at(2))->method('hasParameter')->will($this->returnValue(true));
     $sc->expects($this->at(3))->method('getParameter')->will($this->returnValue('bar'));
     $sc->expects($this->at(4))->method('hasParameter')->will($this->returnValue(false));
     $sc->expects($this->at(5))->method('hasParameter')->will($this->returnValue(true));
     $sc->expects($this->at(6))->method('getParameter')->will($this->returnValue('bar'));
     $router = new Router($sc, 'foo');
     $route = $router->getRouteCollection()->get('foo');
     $this->assertEquals('%foo%', $route->getDefault('foo'));
     $this->assertEquals('bar', $route->getDefault('bar'));
     $this->assertEquals('foobar', $route->getDefault('foobar'));
     $this->assertEquals('%foo', $route->getDefault('foo1'));
     $this->assertEquals('foo%', $route->getDefault('foo2'));
     $this->assertEquals('f%o%o', $route->getDefault('foo3'));
     $this->assertEquals('%foo%', $route->getRequirement('foo'));
     $this->assertEquals('bar', $route->getRequirement('bar'));
     $this->assertEquals('foobar', $route->getRequirement('foobar'));
     $this->assertEquals('%foo', $route->getRequirement('foo1'));
     $this->assertEquals('foo%', $route->getRequirement('foo2'));
     $this->assertEquals('f%o%o', $route->getRequirement('foo3'));
 }
開發者ID:usefulthink,項目名稱:symfony,代碼行數:26,代碼來源:RouterTest.php

示例3: getLinkForFill

 /**
  * @throws \LogicException
  *
  * @param mixed $data
  *
  * @return string
  */
 public function getLinkForFill($data)
 {
     if (!$this->router instanceof Router) {
         throw new \LogicException('Link cannot be built without a Router');
     }
     return $this->router->generate('fill_filler', ['plugin' => $this->getName(), $this->getForm()->getName() => ['url' => $data]]);
 }
開發者ID:anime-db,項目名稱:catalog-bundle,代碼行數:14,代碼來源:Filler.php

示例4: testPlaceholder

 /**
  * @dataProvider getTestPlaceholderData
  */
 public function testPlaceholder($expected, $parameters)
 {
     $routes = new RouteCollection();
     $routes->add('foo', new Route('/foo/{foo}/', array('foo' => '123'), array()));
     $container = $this->getServiceContainer($routes);
     $router = new Router($container, 'foo', array('generator_class' => 'Hautelook\\TemplatedUriRouter\\Routing\\Generator\\Rfc6570Generator'));
     $this->assertEquals($expected, $router->generate('foo', $parameters));
 }
開發者ID:brookinsconsulting,項目名稱:ezecosystem,代碼行數:11,代碼來源:Rfc6570GeneratorTest.php

示例5: onKernelRequest

 /**
  * Check request to decide if user has access to specific route
  *
  * @param GetResponseEvent $event
  * @throws AccessDeniedException
  * @throws InvalidRouteException
  * @throws UserNotFoundException
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $routeName = $event->getRequest()->get("_route");
     if (strpos($routeName, "app_default_") === 0) {
         throw new InvalidRouteException();
     }
     $routeCollection = $this->router->getRouteCollection();
     $route = $routeCollection->get($routeName);
     if ($route instanceof Route) {
         //Check if need to validate route
         //Sometime we want to allow access without validation: index page, login page
         $accessValidation = $route->getOption('access_validation');
         if ($accessValidation === false) {
             return;
         }
         //Validate current user access to route
         $this->authentication->setCurrentUser($this->request->get("token"));
         $user = $this->authentication->getCurrentUser();
         if (!$user instanceof User) {
             throw new UserNotFoundException();
         }
         $access = $this->accessService->checkPermissions($user, $routeName);
         if ($access === false) {
             throw new AccessDeniedException($user, $routeName);
         }
     }
 }
開發者ID:darijuxs,項目名稱:AuthBundle,代碼行數:35,代碼來源:RequestListener.php

示例6: onKernelRequest

 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (!$this->installed) {
         return;
     }
     $request = $event->getRequest();
     if ($request->attributes->has('_controller') || $event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
         return;
     }
     $slugUrl = $request->getPathInfo();
     if ($slugUrl !== '/') {
         $slugUrl = rtrim($slugUrl, '/');
     }
     /** @var EntityManager $em */
     $em = $this->registry->getManagerForClass('OroB2BRedirectBundle:Slug');
     $slug = $em->getRepository('OroB2BRedirectBundle:Slug')->findOneBy(['url' => $slugUrl]);
     if ($slug) {
         $routeName = $slug->getRouteName();
         $controller = $this->router->getRouteCollection()->get($routeName)->getDefault('_controller');
         $parameters = [];
         $parameters['_route'] = $routeName;
         $parameters['_controller'] = $controller;
         $redirectRouteParameters = $slug->getRouteParameters();
         $parameters = array_merge($parameters, $redirectRouteParameters);
         $parameters['_route_params'] = $redirectRouteParameters;
         $request->attributes->add($parameters);
     }
 }
開發者ID:hafeez3000,項目名稱:orocommerce,代碼行數:31,代碼來源:ForwardListener.php

示例7: generateTabsView

 private function generateTabsView($fieldTranslations, $field, $isKeywords = false)
 {
     $template = '<ul id="tabs" class="nav nav-tabs" data-tabs="tabs">';
     $i = 0;
     foreach ($fieldTranslations as $langCode => $translationValue) {
         if ($i == 0) {
             $template .= '<li class="active"><a href="#' . $field . '-' . $langCode . '" data-toggle="tab">' . $langCode . '</a></li>';
         } else {
             $template .= '<li><a href="#' . $field . '-' . $langCode . '" data-toggle="tab">' . $langCode . '</a></li>';
         }
         $i++;
     }
     $template .= '</ul><div id="my-tab-content" class="tab-content">';
     $t = 0;
     foreach ($fieldTranslations as $langCode => $translationValue) {
         $activeString = $t == 0 ? 'active' : '';
         $template .= '<div class="tab-pane ' . $activeString . '" id="' . $field . '-' . $langCode . '">';
         if ($isKeywords) {
             $explodeValue = explode(',', $translationValue);
             $i = 0;
             foreach ($explodeValue as $explodeItem) {
                 $commaSign = $i != 0 ? ',' : '';
                 $template .= $commaSign . '<a href="' . $this->router->generate('ojs_search_index', ['q' => $explodeItem]) . '" target="_blank">' . $explodeItem . '</a>';
                 $i++;
             }
         } else {
             $template .= $translationValue;
         }
         $template .= '</div>';
         $t++;
     }
     $template .= '</div>';
     return $template;
 }
開發者ID:ojs,項目名稱:ojs,代碼行數:34,代碼來源:FieldDisplayExtension.php

示例8: onKernelResponse

 /**
  * add a rel=self Link header to the response
  *
  * @param FilterResponseEvent $event response listener event
  *
  * @return void
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         // don't do anything if it's not the master request
         return;
     }
     $response = $event->getResponse();
     $request = $event->getRequest();
     $linkHeader = LinkHeader::fromResponse($response);
     // extract various info from route
     $routeName = $request->get('_route');
     $routeParts = explode('.', $routeName);
     $routeType = end($routeParts);
     if ($routeType == 'post') {
         $routeName = substr($routeName, 0, -4) . 'get';
     }
     /** if the request failed in the RestController, $request will not have an record id in
         case of a POST and $router->generate() will fail. that's why we catch it and fail silently
         by not including our header in the response. i hope that's a good compromise. **/
     /** Nope, it's not a good compromise...catch and handle it where it happens.
      *  I will refactory this in another branch*/
     $addHeader = true;
     $url = '';
     try {
         $url = $this->router->generate($routeName, $this->generateParameters($routeType, $request), true);
     } catch (\Exception $e) {
         $addHeader = false;
     }
     if ($addHeader) {
         // append rel=self link to link headers
         $linkHeader->add(new LinkHeaderItem($url, array('rel' => 'self')));
         // overwrite link headers with new headers
         $response->headers->set('Link', (string) $linkHeader);
     }
 }
開發者ID:smoskalenko,項目名稱:graviton,代碼行數:42,代碼來源:SelfLinkResponseListener.php

示例9: onBagdeCreateValidationLink

 /**
  * @DI\Observe("badge-resource-icap_wiki-section_create-generate_validation_link")
  * @DI\Observe("badge-resource-icap_wiki-section_delete-generate_validation_link")
  * @DI\Observe("badge-resource-icap_wiki-section_move-generate_validation_link")
  * @DI\Observe("badge-resource-icap_wiki-section_remove-generate_validation_link")
  * @DI\Observe("badge-resource-icap_wiki-section_restore-generate_validation_link")
  * @DI\Observe("badge-resource-icap_wiki-section_update-generate_validation_link")
  * @DI\Observe("badge-resource-icap_wiki-contribution_create-generate_validation_link")
  */
 public function onBagdeCreateValidationLink($event)
 {
     $content = null;
     $log = $event->getLog();
     switch ($log->getAction()) {
         case LogSectionCreateEvent::ACTION:
         case LogSectionDeleteEvent::ACTION:
         case LogSectionMoveEvent::ACTION:
         case LogSectionRemoveEvent::ACTION:
         case LogSectionRestoreEvent::ACTION:
         case LogSectionUpdateEvent::ACTION:
             $logDetails = $event->getLog()->getDetails();
             $parameters = array('wikiId' => $logDetails['section']['wiki']);
             $sectionAnchor = sprintf('#section-%s', $logDetails['section']['id']);
             $url = $this->router->generate('icap_wiki_view', $parameters, UrlGeneratorInterface::ABSOLUTE_PATH);
             $title = $logDetails['section']['title'];
             $content = sprintf('<a href="%s%s" title="%s">%s</a>', $url, $sectionAnchor, $title, $title);
             break;
         case LogContributionCreateEvent::ACTION:
             $logDetails = $event->getLog()->getDetails();
             $parameters = array('wikiId' => $logDetails['contribution']['wiki']);
             $sectionAnchor = sprintf('#section-%s', $logDetails['contribution']['section']);
             $url = $this->router->generate('icap_wiki_view', $parameters, UrlGeneratorInterface::ABSOLUTE_PATH);
             $title = $logDetails['contribution']['title'];
             $content = sprintf('<a href="%s%s" title="%s">%s</a>', $url, $sectionAnchor, $title, $title);
             break;
     }
     $event->setContent($content);
     $event->stopPropagation();
 }
開發者ID:claroline,項目名稱:distribution,代碼行數:39,代碼來源:BadgeListener.php

示例10: testDeleteMultiple

 /**
  * @depends testPut
  */
 public function testDeleteMultiple()
 {
     $data = [2, 3];
     $uri = self::$router->generate('post_assets') . '.json';
     self::$client->request('DELETE', $uri, ['images' => json_encode($data)]);
     $this->assertTrue(self::$client->getResponse()->isRedirect());
 }
開發者ID:gorvelyfab,項目名稱:KoopaBaseAdminer,代碼行數:10,代碼來源:MediaControllerTest.php

示例11: generateLinkChangePassword

 /**
  * @return string
  */
 public function generateLinkChangePassword()
 {
     if (null === $this->webHomeAuthUrl) {
         return $this->router->generate('app_home_change_password');
     }
     return $this->webHomeAuthUrl . '/change-password';
 }
開發者ID:nicolasdewez,項目名稱:webhome-common,代碼行數:10,代碼來源:UserBar.php

示例12: onBagdeCreateValidationLink

 /**
  * @DI\Observe("badge-resource-icap_dropzone-correction_delete-generate_validation_link")
  * @DI\Observe("badge-resource-icap_dropzone-correction_end-generate_validation_link")
  * @DI\Observe("badge-resource-icap_dropzone-correction_start-generate_validation_link")
  * @DI\Observe("badge-resource-icap_dropzone-correction_update-generate_validation_link")
  * @DI\Observe("badge-resource-icap_dropzone-correction_validation_change-generate_validation_link")
  * @DI\Observe("badge-resource-icap_dropzone-criterion_create-generate_validation_link")
  * @DI\Observe("badge-resource-icap_dropzone-criterion_delete-generate_validation_link")
  * @DI\Observe("badge-resource-icap_dropzone-criterion_update-generate_validation_link")
  * @DI\Observe("badge-resource-icap_dropzone-document_create-generate_validation_link")
  * @DI\Observe("badge-resource-icap_dropzone-document_delete-generate_validation_link")
  * @DI\Observe("badge-resource-icap_dropzone-document_open-generate_validation_link")
  * @DI\Observe("badge-resource-icap_dropzone-drop_end-generate_validation_link")
  * @DI\Observe("badge-resource-icap_dropzone-drop_evaluate-generate_validation_link")
  * @DI\Observe("badge-resource-icap_dropzone-drop_start-generate_validation_link")
  * @DI\Observe("badge-resource-icap_dropzone-dropzone_configure-generate_validation_link")
  */
 public function onBagdeCreateValidationLink($event)
 {
     $content = null;
     $log = $event->getLog();
     switch ($log->getAction()) {
         case LogCorrectionDeleteEvent::ACTION:
         case LogCorrectionEndEvent::ACTION:
         case LogCorrectionStartEvent::ACTION:
         case LogCorrectionUpdateEvent::ACTION:
         case LogCorrectionValidationChangeEvent::ACTION:
         case LogCriterionCreateEvent::ACTION:
         case LogCriterionDeleteEvent::ACTION:
         case LogCriterionUpdateEvent::ACTION:
         case LogDocumentCreateEvent::ACTION:
         case LogDocumentDeleteEvent::ACTION:
         case LogDocumentOpenEvent::ACTION:
         case LogDropEndEvent::ACTION:
         case LogDropEvaluateEvent::ACTION:
         case LogDropStartEvent::ACTION:
         case LogDropzoneConfigureEvent::ACTION:
             $logDetails = $event->getLog()->getDetails();
             $parameters = array('resourceId' => $logDetails['dropzone']['id']);
             $url = $this->router->generate('icap_dropzone_open', $parameters, UrlGeneratorInterface::ABSOLUTE_PATH);
             /** @var Dropzone $dropzone */
             $dropzone = $this->entityManager->getRepository('IcapDropzoneBundle:Dropzone')->findOneById($logDetails['dropzone']['id']);
             $title = $dropzone->getResourceNode()->getName();
             $content = sprintf('<a href="%s" title="%s">%s</a>', $url, $title, $title);
             break;
     }
     $event->setContent($content);
     $event->stopPropagation();
 }
開發者ID:claroline,項目名稱:distribution,代碼行數:49,代碼來源:BadgeListener.php

示例13: create

 /**
  * @param array $material
  * @return UserMaterial[]
  */
 public function create(array $material)
 {
     if (array_key_exists('filename', $material) && !empty($material['filename'])) {
         $absoluteFileUri = $this->router->generate('ilios_core_downloadlearningmaterial', ['token' => $material['token']], UrlGenerator::ABSOLUTE_URL);
     }
     /* @var UserMaterial $obj */
     $obj = new $this->decoratorClassName();
     $obj->id = $material['id'];
     $obj->session = isset($material['sessionId']) ? $material['sessionId'] : null;
     $obj->course = isset($material['courseId']) ? $material['courseId'] : null;
     $obj->sessionTitle = isset($material['sessionTitle']) ? $material['sessionTitle'] : null;
     $obj->courseTitle = isset($material['courseTitle']) ? $material['courseTitle'] : null;
     $obj->firstOfferingDate = isset($material['firstOfferingDate']) ? $material['firstOfferingDate'] : null;
     if ($material['publicNotes']) {
         $obj->publicNotes = $material['notes'];
     }
     $obj->required = $material['required'];
     $obj->title = $material['title'];
     $obj->description = $material['description'];
     $obj->originalAuthor = $material['originalAuthor'];
     $obj->absoluteFileUri = isset($absoluteFileUri) ? $absoluteFileUri : null;
     $obj->citation = $material['citation'];
     $obj->link = $material['link'];
     $obj->filename = $material['filename'];
     $obj->mimetype = $material['mimetype'];
     return $obj;
 }
開發者ID:stopfstedt,項目名稱:ilios,代碼行數:31,代碼來源:UserMaterialFactory.php

示例14: onBagdeCreateValidationLink

 /**
  * @DI\Observe("badge-resource-icap_blog-post_create-generate_validation_link")
  * @DI\Observe("badge-resource-icap_blog-post_delete-generate_validation_link")
  * @DI\Observe("badge-resource-icap_blog-post_read-generate_validation_link")
  * @DI\Observe("badge-resource-icap_blog-post_update-generate_validation_link")
  * @DI\Observe("badge-resource-icap_blog-comment_create-generate_validation_link")
  * @DI\Observe("badge-resource-icap_blog-comment_delete-generate_validation_link")
  */
 public function onBagdeCreateValidationLink($event)
 {
     $content = null;
     $log = $event->getLog();
     switch ($log->getAction()) {
         case LogPostCreateEvent::ACTION:
         case LogPostDeleteEvent::ACTION:
         case LogPostReadEvent::ACTION:
         case LogPostUpdateEvent::ACTION:
             $logDetails = $event->getLog()->getDetails();
             $parameters = array('blogId' => $logDetails['post']['blog'], 'postSlug' => $logDetails['post']['slug']);
             $url = $this->router->generate('icap_blog_post_view', $parameters, UrlGeneratorInterface::ABSOLUTE_PATH);
             $title = $logDetails['post']['title'];
             $content = sprintf('<a href="%s" title="%s">%s</a>', $url, $title, $title);
             break;
         case LogCommentCreateEvent::ACTION:
         case LogCommentDeleteEvent::ACTION:
             $logDetails = $event->getLog()->getDetails();
             $parameters = array('blogId' => $logDetails['post']['blog'], 'postSlug' => $logDetails['post']['slug']);
             $url = $this->router->generate('icap_blog_post_view', $parameters, UrlGeneratorInterface::ABSOLUTE_PATH);
             $title = $logDetails['post']['title'];
             $anchor = isset($logDetails['comment']['id']) ? '#comment-' . $logDetails['comment']['id'] : '';
             $content = sprintf('<a href="%s%s" title="%s">%s</a>', $url, $anchor, $title, $title);
             break;
     }
     $event->setContent($content);
     $event->stopPropagation();
 }
開發者ID:rbs-aferreira,項目名稱:BlogBundle,代碼行數:36,代碼來源:BadgeListener.php

示例15: onUnlockBadge

 /**
  * @param BadgeUnlockEvent $event
  */
 public function onUnlockBadge(BadgeUnlockEvent $event)
 {
     $unlockedBadge = $event->getUnlockedBadge();
     $user = $unlockedBadge->getUser();
     $badge = $unlockedBadge->getBadge();
     $data = ['text' => sprintf('<%s|%s> just unlocked the badge <%s|%s>!', $this->router->generate('userprofile', ['username' => $user->getUsername()], UrlGeneratorInterface::ABSOLUTE_URL), $user->getUsername(), $this->router->generate('viewbadge', ['id' => $badge->getId()], UrlGeneratorInterface::ABSOLUTE_URL), $badge->getTitle()), 'attachments' => [['color' => 'good', 'title' => $badge->getTitle(), 'text' => $badge->getDescription(), 'thumb_url' => $this->router->generate('homepage', [], UrlGeneratorInterface::ABSOLUTE_URL) . $badge->getImageWebPath()]]];
     $this->notifier->notify($data);
 }
開發者ID:akeneo,項目名稱:badger,代碼行數:11,代碼來源:UnlockBadgeListener.php


注:本文中的Symfony\Bundle\FrameworkBundle\Routing\Router類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。