本文整理匯總了PHP中Symfony\Component\Routing\RouteCollection::get方法的典型用法代碼示例。如果您正苦於以下問題:PHP RouteCollection::get方法的具體用法?PHP RouteCollection::get怎麽用?PHP RouteCollection::get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Routing\RouteCollection
的用法示例。
在下文中一共展示了RouteCollection::get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onKernelView
/**
* @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $e
*/
public function onKernelView(GetResponseForControllerResultEvent $e)
{
$queryset = $e->getControllerResult();
$routeName = $e->getRequest()->attributes->get('_route');
$route = $this->routes->get($routeName);
if (!$route) {
return;
}
$interface = 'SDispatcher\\Common\\PaginatorInterface';
$paginatorClass = $route->getOption(RouteOptions::PAGINATOR_CLASS);
if (!$paginatorClass || !is_subclass_of($paginatorClass, $interface)) {
return;
}
try {
/* @var \SDispatcher\Common\PaginatorInterface $paginator */
$paginator = new $paginatorClass();
if (!$paginator->supports($queryset)) {
return;
}
list($headers, $data) = $paginator->paginate($e->getRequest(), $queryset, 0, $route->getOption(RouteOptions::PAGE_LIMIT), $route->getOption(RouteOptions::PAGINATED_META_CONTAINER_NAME), $route->getOption(RouteOptions::PAGINATED_DATA_CONTAINER_NAME));
} catch (\Exception $ex) {
list($headers, $data) = array(array(), array());
}
$response = new DataResponse($data);
$response->headers->add($headers);
$e->setResponse($response);
}
示例2: alterRoutes
/**
* New and improved hook_menu_alter().
*/
public function alterRoutes(RouteCollection $collection) {
// admin/structure/taxonomy
if ($route = $collection->get('entity.taxonomy_vocabulary.collection')) {
$route->setRequirements(array(
'_custom_access' => '\taxonomy_access_fix_route_access',
));
$route->setOption('op', 'index');
}
// admin/structure/taxonomy/%vocabulary
if ($route = $collection->get('entity.taxonomy_vocabulary.overview_form')) {
$route->setRequirements(array(
'_custom_access' => '\taxonomy_access_fix_route_access',
));
$route->setOption('op', 'list terms');
}
// admin/structure/taxonomy/%vocabulary/add
if ($route = $collection->get('entity.taxonomy_term.add_form')) {
$route->setRequirements(array(
'_custom_access' => '\taxonomy_access_fix_route_access',
));
$route->setOption('op', 'add terms');
}
}
示例3: alterRoutes
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection)
{
foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
// Try to get the route from the current collection.
$link_template = $entity_type->getLinkTemplate('canonical');
if (strpos($link_template, '/') !== FALSE) {
$base_path = '/' . $link_template;
} else {
if (!($entity_route = $collection->get("entity.{$entity_type_id}.canonical"))) {
continue;
}
$base_path = $entity_route->getPath();
}
// Inherit admin route status from edit route, if exists.
$is_admin = FALSE;
$route_name = "entity.{$entity_type_id}.edit_form";
if ($edit_route = $collection->get($route_name)) {
$is_admin = (bool) $edit_route->getOption('_admin_route');
}
$path = $base_path . '/translations';
$route = new Route($path, array('_controller' => '\\Drupal\\content_translation\\Controller\\ContentTranslationController::overview', 'entity_type_id' => $entity_type_id), array('_entity_access' => $entity_type_id . '.view', '_access_content_translation_overview' => $entity_type_id), array('parameters' => array($entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
$route_name = "entity.{$entity_type_id}.content_translation_overview";
$collection->add($route_name, $route);
$route = new Route($path . '/add/{source}/{target}', array('_controller' => '\\Drupal\\content_translation\\Controller\\ContentTranslationController::add', 'source' => NULL, 'target' => NULL, '_title' => 'Add', 'entity_type_id' => $entity_type_id), array('_entity_access' => $entity_type_id . '.view', '_access_content_translation_manage' => 'create'), array('parameters' => array('source' => array('type' => 'language'), 'target' => array('type' => 'language'), $entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
$collection->add("entity.{$entity_type_id}.content_translation_add", $route);
$route = new Route($path . '/edit/{language}', array('_controller' => '\\Drupal\\content_translation\\Controller\\ContentTranslationController::edit', 'language' => NULL, '_title' => 'Edit', 'entity_type_id' => $entity_type_id), array('_access_content_translation_manage' => 'update'), array('parameters' => array('language' => array('type' => 'language'), $entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
$collection->add("entity.{$entity_type_id}.content_translation_edit", $route);
$route = new Route($path . '/delete/{language}', array('_entity_form' => $entity_type_id . '.content_translation_deletion', 'language' => NULL, '_title' => 'Delete', 'entity_type_id' => $entity_type_id), array('_access_content_translation_manage' => 'delete'), array('parameters' => array('language' => array('type' => 'language'), $entity_type_id => array('type' => 'entity:' . $entity_type_id)), '_admin_route' => $is_admin));
$collection->add("entity.{$entity_type_id}.content_translation_delete", $route);
}
}
示例4: getRouteByName
/**
* @inheritdoc
*/
public function getRouteByName($name, $params = [])
{
if ($route = $this->routes->get($name)) {
return $route;
}
return null;
}
示例5: getIndexControllerWithSets
private function getIndexControllerWithSets($cachePath = null)
{
$extractor = $this->getExtractor(null, '', $cachePath);
$extractor->expects($this->any())->method('getRoutes')->will($this->returnCallback(function (array $sets = array()) {
$routes = new RouteCollection();
$routesDefinition = array('no_set' => array(), 'set1' => array('set1'), 'set1set2' => array('set1', 'set2'), 'set3' => array('set3'));
foreach ($routesDefinition as $name => $routeSets) {
$routes->add($name, new Route('/' . $name, array(), array(), array('expose_sets' => $routeSets)));
}
$routesSet1 = new RouteCollection();
$routesSet1->add('set1', $routes->get('set1'));
$routesSet1->add('set1set2', $routes->get('set1set2'));
$routesSet2Set3 = new RouteCollection();
$routesSet2Set3->add('set1set2', $routes->get('set1set2'));
$routesSet2Set3->add('set3', $routes->get('set3'));
if ($sets == array('set1')) {
return $routesSet1;
} elseif ($sets == array('set2', 'set3')) {
return $routesSet2Set3;
}
throw new \InvalidArgumentException(sprintf('Theses sets are not configured : %s', join(', ', $sets)));
}));
$controller = new Controller($this->getSerializer(), $extractor);
return $controller;
}
示例6: doKernelResponse
protected function doKernelResponse(Request $request, Response $response)
{
if (!$response instanceof DataResponse) {
return;
}
$routeName = $request->attributes->get('_route');
$route = $this->routes->get($routeName);
if (!$route) {
return;
}
$acceptedFormat = $route->getOption(RouteOptions::ACCEPTED_FORMAT);
if (!$acceptedFormat) {
$response->setContent('');
$response->setStatusCode(406);
}
if ($this->encoder->supportsEncoding($acceptedFormat) && $acceptedFormat === 'json') {
$contentType = $request->getMimeType($acceptedFormat);
$jsonResponse = new JsonResponse($response->getContent());
$response->setContent($jsonResponse->getContent());
$response->headers->set('Content-Type', $contentType);
} elseif ($this->encoder->supportsEncoding($acceptedFormat)) {
$contentType = $request->getMimeType($acceptedFormat);
$content = $this->encoder->encode($response->getContent(), $acceptedFormat);
$response->setContent($content);
$response->headers->set('Content-Type', $contentType);
}
}
示例7: onKernelController
/**
* Handler Kernel Controller events
*
* @param FilterControllerEvent $event
*/
public function onKernelController(FilterControllerEvent $event)
{
$request = $event->getRequest();
$route = $this->routes->get($request->attributes->get('_route'));
if ($route && $route->hasContent()) {
$this->populateContent($route, $request);
}
}
示例8: alterRoutes
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
if ($route = $collection->get('node.revision_revert_confirm')) {
$route->setDefault('_form', '\Drupal\revision_ui\Form\NodeRevisionRevertForm');
}
if ($route = $collection->get('node.revision_revert_translation_confirm')) {
$route->setDefault('_form', '\Drupal\revision_ui\Form\NodeRevisionRevertTranslationForm');
}
}
示例9: getRoutesByNames
/**
* Implements \Symfony\Cmf\Component\Routing\RouteProviderInterface::getRoutesByName().
*/
public function getRoutesByNames($names)
{
$routes = array();
foreach ($names as $name) {
$routes[] = $this->routes->get($name);
}
return $routes;
}
示例10: testAddPrefix
public function testAddPrefix()
{
$collection = new RouteCollection();
$collection->add('foo', $foo = new Route('/foo'));
$collection->add('bar', $bar = new Route('/bar'));
$collection->addPrefix('/admin');
$this->assertEquals('/admin/foo', $collection->get('foo')->getPattern(), '->addPrefix() adds a prefix to all routes');
$this->assertEquals('/admin/bar', $collection->get('bar')->getPattern(), '->addPrefix() adds a prefix to all routes');
}
示例11: onKernelReponse
/**
* Handler Kernel Response events
*
* @param FilterResponseEvent $event
*/
public function onKernelReponse(FilterResponseEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
$route = $this->routes->get($request->attributes->get('_route'));
if ($route && $route->hasContent() && !$response->headers->has('Last-Modified')) {
$this->setLastModifiedHeader($route, $request, $response);
}
}
示例12: onKernelReponse
/**
* Handler Kernel Response events
*
* @param FilterResponseEvent $event
*/
public function onKernelReponse(FilterResponseEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
$route = $this->routes->get($request->attributes->get('_route'));
if ($route && $route->isMapped()) {
$url = $request->attributes->get('_canonical');
$lastModified = new DateTime($response->headers->get('Last-Modified'));
$this->sitemap->add($url, $lastModified);
}
}
示例13: alterRoutes
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection)
{
if ($collection->get('tmgmt.admin_tmgmt')) {
$route = $collection->get('tmgmt.admin_tmgmt');
$route->addRequirements(['_permission' => $collection->get('tmgmt.admin_tmgmt')->getRequirement('_permission') . '+administer translation tasks+provide translation services']);
}
foreach ($collection->all() as $route) {
if (strpos($route->getPath(), '/translate') === 0 && $this->configFactory->get('tmgmt_local.settings')->get('use_admin_theme') || strpos($route->getPath(), '/manage-translate') === 0) {
$route->setOption('_admin_route', TRUE);
}
}
}
示例14: alterRoutes
/**
* {@inheritdoc}
*/
public function alterRoutes(RouteCollection $collection)
{
// Change path '/user/login' to '/login'.
if ($route = $collection->get('user.login')) {
$route->setPath('/login');
}
// Always deny access to '/user/logout'.
// Note that the second parameter of setRequirement() is a string.
if ($route = $collection->get('user.logout')) {
$route->setRequirement('_access', 'FALSE');
}
}
示例15: alterRoutes
/**
* {@inheritdoc}
*/
public function alterRoutes(RouteCollection $collection)
{
// Change path '/user/login' to '/login'.
if ($route = $collection->get('sociallogin.settings_form')) {
$route->setPath('admin/config/people/userregistration');
$defaults = $route->getDefaults();
$defaults['_title'] = "User Registration settings";
$route->setDefaults($defaults);
}
if ($route = $collection->get('advanced.settings_form')) {
$route->setPath('admin/config/people/userregistration/advanced');
}
}