当前位置: 首页>>代码示例>>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;未经允许,请勿转载。