php Symfony-Component-Routing-Route类(方法)实例源码

下面列出了php Symfony-Component-Routing-Route 类(方法)源码代码实例,从而了解它的用法。

作者:brodaprojec    项目:brod   
protected function configureRoute(\Symfony\Component\Routing\Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot)
 {
     // defines the controller
     $route->setDefault('_controller', $class->getName() . '::' . $method->getName());
     // verify the other callbacks
     $options = $annot->getOptions();
     foreach ($options as $prop => &$values) {
         if (!in_array($prop, array('_after_middlewares', '_before_middlewares', '_converters'))) {
             continue;
         }
         if (empty($values)) {
             continue;
         }
         foreach ($values as &$value) {
             if (is_string($value) && $class->hasMethod($value)) {
                 // call static method from class
                 $value = array($class->getName(), $value);
             }
         }
         unset($value);
         // clear reference
     }
     unset($values);
     $route->setOptions($options);
 }

作者:Nikola-xii    项目:d8intrane   
/**
  * Checks translation access for the entity and operation on the given route.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The parametrized route.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  * @param string $source
  *   (optional) For a create operation, the language code of the source.
  * @param string $target
  *   (optional) For a create operation, the language code of the translation.
  * @param string $language
  *   (optional) For an update or delete operation, the language code of the
  *   translation being updated or deleted.
  * @param string $entity_type_id
  *   (optional) The entity type ID.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, $source = NULL, $target = NULL, $language = NULL, $entity_type_id = NULL)
 {
     /* @var \Drupal\Core\Entity\ContentEntityInterface $entity */
     if ($entity = $route_match->getParameter($entity_type_id)) {
         if ($account->hasPermission('translate any entity')) {
             return AccessResult::allowed()->cachePerRole();
         }
         $operation = $route->getRequirement('_access_content_translation_manage');
         /* @var \Drupal\content_translation\ContentTranslationHandlerInterface $handler */
         $handler = $this->entityManager->getHandler($entity->getEntityTypeId(), 'translation');
         // Load translation.
         $translations = $entity->getTranslationLanguages();
         $languages = $this->languageManager->getLanguages();
         switch ($operation) {
             case 'create':
                 $source_language = $this->languageManager->getLanguage($source) ?: $entity->language();
                 $target_language = $this->languageManager->getLanguage($target) ?: $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT);
                 $is_new_translation = $source_language->getId() != $target_language->getId() && isset($languages[$source_language->getId()]) && isset($languages[$target_language->getId()]) && !isset($translations[$target_language->getId()]);
                 return AccessResult::allowedIf($is_new_translation)->cachePerRole()->cacheUntilEntityChanges($entity)->andIf($handler->getTranslationAccess($entity, $operation));
             case 'update':
             case 'delete':
                 $language = $this->languageManager->getLanguage($language) ?: $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT);
                 $has_translation = isset($languages[$language->getId()]) && $language->getId() != $entity->getUntranslated()->language()->getId() && isset($translations[$language->getId()]);
                 return AccessResult::allowedIf($has_translation)->cachePerRole()->cacheUntilEntityChanges($entity)->andIf($handler->getTranslationAccess($entity, $operation));
         }
     }
     // No opinion.
     return AccessResult::neutral();
 }

作者:ddrozdi    项目:dmap   
/**
  * Checks access for the account and route using the custom access checker.
  *
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The route match object to be checked.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The account being checked.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account)
 {
     $callable = $this->controllerResolver->getControllerFromDefinition($route->getRequirement('_custom_access'));
     $arguments_resolver = $this->argumentsResolverFactory->getArgumentsResolver($route_match, $account);
     $arguments = $arguments_resolver->getArguments($callable);
     return call_user_func_array($callable, $arguments);
 }

作者:bankir    项目:rpc-server-bundl   
/**
  * @param Method $method
  * @param string $endpoint
  *
  * @return RpcApiDoc
  */
 protected function processMethod(Method $method, $endpoint)
 {
     /** @var string[] $views */
     $views = $method->getContext();
     if ($method->includeDefaultContext()) {
         $views[] = 'Default';
     }
     $views[] = 'default';
     $request = new Request($method, [], new ParameterBag(['_controller' => $method->getController()]));
     /** @var array $controller */
     $controller = $this->resolver->getController($request);
     $refl = new \ReflectionMethod($controller[0], $controller[1]);
     /** @var RpcApiDoc $methodDoc */
     $methodDoc = $this->reader->getMethodAnnotation($refl, RpcApiDoc::class);
     if (null === $methodDoc) {
         $methodDoc = new RpcApiDoc(['resource' => $endpoint]);
     }
     $methodDoc = clone $methodDoc;
     $methodDoc->setEndpoint($endpoint);
     $methodDoc->setRpcMethod($method);
     if (null === $methodDoc->getSection()) {
         $methodDoc->setSection($endpoint);
     }
     foreach ($views as $view) {
         $methodDoc->addView($view);
     }
     $route = new Route($endpoint);
     $route->setMethods([$endpoint]);
     $route->setDefault('_controller', get_class($controller[0]) . '::' . $controller[1]);
     $methodDoc->setRoute($route);
     return $methodDoc;
 }

作者:aWEBoLab    项目:tax   
/**
  * Checks access to create an entity of any bundle for the given route.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The parameterized route.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account)
 {
     $entity_type_id = $route->getRequirement($this->requirementsKey);
     $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
     $access_control_handler = $this->entityTypeManager->getAccessControlHandler($entity_type_id);
     // In case there is no "bundle" entity key, check create access with no
     // bundle specified.
     if (!$entity_type->hasKey('bundle')) {
         return $access_control_handler->createAccess(NULL, $account, [], TRUE);
     }
     $access = AccessResult::neutral();
     $bundles = array_keys($this->entityTypeBundleInfo->getBundleInfo($entity_type_id));
     // Include list cache tag as access might change if more bundles are added.
     if ($entity_type->getBundleEntityType()) {
         $access->addCacheTags($this->entityTypeManager->getDefinition($entity_type->getBundleEntityType())->getListCacheTags());
         // Check if the user is allowed to create new bundles. If so, allow
         // access, so the add page can show a link to create one.
         // @see \Drupal\Core\Entity\Controller\EntityController::addPage()
         $bundle_access_control_handler = $this->entityTypeManager->getAccessControlHandler($entity_type->getBundleEntityType());
         $access = $access->orIf($bundle_access_control_handler->createAccess(NULL, $account, [], TRUE));
         if ($access->isAllowed()) {
             return $access;
         }
     }
     // Check whether an entity of any bundle may be created.
     foreach ($bundles as $bundle) {
         $access = $access->orIf($access_control_handler->createAccess($bundle, $account, [], TRUE));
         // In case there is a least one bundle user can create entities for,
         // access is allowed.
         if ($access->isAllowed()) {
             break;
         }
     }
     return $access;
 }

作者:nishantkumar15    项目:drupal8.crackl   
/**
  * Constructs a Route object.
  */
 public function __construct($name, Route $route, RouteProviderInterface $route_provider)
 {
     $this->name = $name;
     $this->route = $route;
     $this->routeProvider = $route_provider ? $route_provider : \Drupal::service('router.route_provider');
     $this->path = new PathUtility($route->getPath());
 }

作者:ec-europ    项目:joinup-de   
/**
  * Build the route for the actual download path.
  */
 protected function getDownloadRoute(EntityTypeInterface $entity_type)
 {
     $entity_type_id = $entity_type->id();
     $route = new Route("/rdf-export/{$entity_type_id}/{{$entity_type_id}}/{export_format}");
     $route->addDefaults(['_controller' => '\\Drupal\\rdf_export\\Controller\\RdfExportController::download', '_title' => 'RDF Export'])->addRequirements(['_permission' => 'export rdf metadata'])->setOption('entity_type_id', $entity_type_id)->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]);
     return $route;
 }

作者:bigfishcm    项目:bigfishcm   
public function addCollection($path, array $data = array())
 {
     $route = new Route($path);
     //        $pageClass = ($entity->getResource()->getPageClass()) ? $entity->getResource()->getPageClass() : $entity->getResource()->getPageClass();
     $route->setDefaults($data);
     return $route;
 }

作者:darrylr    项目:protovbmwm   
/**
  * {@inheritdoc}
  */
 public function access(Route $route, AccountInterface $account, Request $request)
 {
     $_entity_revision = $request->attributes->get('_entity_revision');
     $operation = $route->getRequirement('_entity_access_revision');
     list(, $operation) = explode('.', $operation, 2);
     return AccessResult::allowedIf($_entity_revision && $this->checkAccess($_entity_revision, $account, $operation))->cachePerPermissions();
 }

作者:ddrozdi    项目:dmap   
/**
  * @covers ::applies
  */
 public function testAppliesWithFormat()
 {
     $route_filter = new RequestFormatRouteFilter();
     $route = new Route('/test');
     $route->setRequirement('_format', 'json');
     $this->assertTrue($route_filter->applies($route));
 }

作者:ehibe    项目:silexI18nRoutingServiceProvide   
public function shouldExcludeRoute($routeName, Route $route)
 {
     if ('_' === $routeName[0] || !$route->hasOption('i18n')) {
         return true;
     }
     return false;
 }

作者:neeravb    项目:unify-d   
/**
  * Checks if the user has access to underlying storage for a Panels display.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The parametrized route.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account)
 {
     $panels_storage_type = $route_match->getParameter('panels_storage_type');
     $panels_storage_id = $route_match->getParameter('panels_storage_id');
     $op = $route->getRequirement('_panels_storage_access');
     return $this->panelsStorage->access($panels_storage_type, $panels_storage_id, $op, $account);
 }

作者:BerlingskeMedi    项目:NelmioApiDocBundl   
public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method)
 {
     // description
     if (null === $annotation->getDescription()) {
         $comments = explode("\n", $annotation->getDocumentation());
         // just set the first line
         $comment = trim($comments[0]);
         $comment = preg_replace("#\n+#", ' ', $comment);
         $comment = preg_replace('#\\s+#', ' ', $comment);
         $comment = preg_replace('#[_`*]+#', '', $comment);
         if ('@' !== substr($comment, 0, 1)) {
             $annotation->setDescription($comment);
         }
     }
     // requirements
     $requirements = $annotation->getRequirements();
     foreach ($route->getRequirements() as $name => $value) {
         if (!isset($requirements[$name]) && '_method' !== $name && '_scheme' !== $name) {
             $requirements[$name] = array('requirement' => $value, 'dataType' => '', 'description' => '');
         }
         if ('_scheme' === $name) {
             $https = 'https' == $value;
             $annotation->setHttps($https);
         }
     }
     if (method_exists($route, 'getSchemes')) {
         $annotation->setHttps(in_array('https', $route->getSchemes()));
     }
     $paramDocs = array();
     foreach (explode("\n", $this->commentExtractor->getDocComment($method)) as $line) {
         if (preg_match('{^@param (.+)}', trim($line), $matches)) {
             $paramDocs[] = $matches[1];
         }
         if (preg_match('{^@deprecated\\b(.*)}', trim($line), $matches)) {
             $annotation->setDeprecated(true);
         }
         if (preg_match('{^@link\\b(.*)}', trim($line), $matches)) {
             $annotation->setLink($matches[1]);
         }
     }
     $regexp = '{(\\w*) *\\$%s\\b *(.*)}i';
     foreach ($route->compile()->getVariables() as $var) {
         $found = false;
         foreach ($paramDocs as $paramDoc) {
             if (preg_match(sprintf($regexp, preg_quote($var)), $paramDoc, $matches)) {
                 $requirements[$var]['dataType'] = isset($matches[1]) ? $matches[1] : '';
                 $requirements[$var]['description'] = $matches[2];
                 if (!isset($requirements[$var]['requirement'])) {
                     $requirements[$var]['requirement'] = '';
                 }
                 $found = true;
                 break;
             }
         }
         if (!isset($requirements[$var]) && false === $found) {
             $requirements[$var] = array('requirement' => '', 'dataType' => '', 'description' => '');
         }
     }
     $annotation->setRequirements($requirements);
 }

作者:Gregwa    项目:symfon   
/**
     * {@inheritdoc}
     */
    protected function describeRoute(Route $route, array $options = array())
    {
        $requirements = $route->getRequirements();
        unset($requirements['_scheme'], $requirements['_method']);

        // fixme: values were originally written as raw
        $description = array(
            '<comment>Path</comment>         '.$route->getPath(),
            '<comment>Host</comment>         '.('' !== $route->getHost() ? $route->getHost() : 'ANY'),
            '<comment>Scheme</comment>       '.($route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY'),
            '<comment>Method</comment>       '.($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY'),
            '<comment>Class</comment>        '.get_class($route),
            '<comment>Defaults</comment>     '.$this->formatRouterConfig($route->getDefaults()),
            '<comment>Requirements</comment> '.$this->formatRouterConfig($requirements) ?: 'NO CUSTOM',
            '<comment>Options</comment>      '.$this->formatRouterConfig($route->getOptions()),
            '<comment>Path-Regex</comment>   '.$route->compile()->getRegex(),
        );

        if (isset($options['name'])) {
            array_unshift($description, '<comment>Name</comment>         '.$options['name']);
            array_unshift($description, $this->formatSection('router', sprintf('Route "%s"', $options['name'])));
        }

        if (null !== $route->compile()->getHostRegex()) {
            $description[] = '<comment>Host-Regex</comment>   '.$route->compile()->getHostRegex();
        }

        $this->writeText(implode("\n", $description)."\n", $options);
    }

作者:zenmagic    项目:zenmagic   
public function load($resource, $type = null)
 {
     if (true === $this->loaded) {
         throw new \RuntimeException('Do not add this loader twice');
     }
     $routes = new RouteCollection();
     $contextConfigLoader = $this->contextConfigLoader;
     foreach ($contextConfigLoader->getRouting() as $routing) {
         foreach ($routing as $id => $info) {
             if (array_key_exists('pattern', $info)) {
                 $route = new Route($info['pattern']);
                 // merge options and defaults
                 if (array_key_exists('defaults', $info)) {
                     $route->addDefaults($info['defaults']);
                 }
                 if (array_key_exists('options', $info)) {
                     $route->addOptions($info['options']);
                 }
                 if (array_key_exists('requirements', $info)) {
                     $route->addRequirements($info['requirements']);
                 }
             }
             $routes->add($id, $route);
         }
     }
     return $routes;
 }

作者:xGoule    项目:PSPublicWriterBundl   
public function publicToPrivateWriterForward(Route $currentRoute, array $attributes, Request $currentRequest)
 {
     $attributes['_controller'] = $this->router->getRouteCollection()->get($currentRoute->getOption('forward_http_route'))->getDefault('_controller');
     $subRequest = $currentRequest->duplicate(null, null, $attributes);
     $response = $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
     return $response;
 }

作者:ec-europ    项目:joinup-de   
/**
  * {@inheritdoc}
  */
 public function access(Route $route, AccountInterface $account, RdfInterface $rdf_entity, $operation = 'view')
 {
     $graph = $route->getOption('graph_name');
     $entity_type_id = $route->getOption('entity_type_id');
     $storage = $this->entityManager->getStorage($entity_type_id);
     if (!$storage instanceof RdfEntitySparqlStorage) {
         throw new \Exception('Storage not supported.');
     }
     // The active graph is the published graph. It is handled by the default
     // operation handler.
     // @todo: getActiveGraph is not the default. We should load from settings.
     $default_graph = $storage->getBundleGraphUri($rdf_entity->bundle(), 'default');
     $requested_graph = $storage->getBundleGraphUri($rdf_entity->bundle(), $graph);
     if ($requested_graph == $default_graph) {
         return AccessResult::neutral();
     }
     $active_graph_type = $storage->getRequestGraphs($rdf_entity->id());
     // Check if there is an entity saved in the passed graph.
     $storage->setRequestGraphs($rdf_entity->id(), [$graph]);
     $entity = $storage->load($rdf_entity->id());
     // Restore active graph.
     $storage->setRequestGraphs($rdf_entity->id(), $active_graph_type);
     // @todo: When the requested graph is the only one and it is not the
     // default, it is loaded in the default view, so maybe there is no need
     // to also show a separate tab.
     return AccessResult::allowedIf($entity && $this->checkAccess($rdf_entity, $route, $account, $operation, $graph))->cachePerPermissions()->addCacheableDependency($rdf_entity);
 }

作者:kleijnwe    项目:swagger-bundl   
/**
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  *
  * @param mixed $resource
  * @param null  $type
  *
  * @return RouteCollection
  */
 public function load($resource, $type = null) : RouteCollection
 {
     $resource = (string) $resource;
     if (in_array($resource, $this->descriptions)) {
         throw new \RuntimeException("Resource '{$resource}' was already loaded");
     }
     $description = $this->repository->get($resource);
     $routes = new RouteCollection();
     $router = $description->getExtension('router') ?: 'swagger.controller';
     $routerController = $description->getExtension('router-controller');
     foreach ($description->getPaths() as $pathItem) {
         $relativePath = ltrim($pathItem->getPath(), '/');
         $resourceName = strpos($relativePath, '/') ? substr($relativePath, 0, strpos($relativePath, '/')) : $relativePath;
         $routerController = $pathItem->getExtension('router-controller') ?: $routerController;
         foreach ($pathItem->getOperations() as $operation) {
             $controllerKey = $this->resolveControllerKey($operation, $resourceName, $router, $routerController);
             $defaults = ['_controller' => $controllerKey, RequestMeta::ATTRIBUTE_URI => $resource, RequestMeta::ATTRIBUTE_PATH => $pathItem->getPath()];
             $route = new Route($pathItem->getPath(), $defaults, $this->resolveRequirements($operation));
             $route->setMethods($operation->getMethod());
             $routes->add($this->createRouteId($resource, $pathItem->getPath(), $controllerKey), $route);
         }
     }
     $this->descriptions[] = $resource;
     return $routes;
 }

作者:ddrozdi    项目:dmap   
/**
  * {@inheritdoc}
  */
 public function getTitle(Request $request, Route $route)
 {
     $route_title = NULL;
     // A dynamic title takes priority. Route::getDefault() returns NULL if the
     // named default is not set.  By testing the value directly, we also avoid
     // trying to use empty values.
     if ($callback = $route->getDefault('_title_callback')) {
         $callable = $this->controllerResolver->getControllerFromDefinition($callback);
         $arguments = $this->controllerResolver->getArguments($request, $callable);
         $route_title = call_user_func_array($callable, $arguments);
     } elseif ($title = $route->getDefault('_title')) {
         $options = array();
         if ($context = $route->getDefault('_title_context')) {
             $options['context'] = $context;
         }
         $args = array();
         if ($raw_parameters = $request->attributes->get('_raw_variables')) {
             foreach ($raw_parameters->all() as $key => $value) {
                 $args['@' . $key] = $value;
                 $args['%' . $key] = $value;
             }
         }
         if ($title_arguments = $route->getDefault('_title_arguments')) {
             $args = array_merge($args, (array) $title_arguments);
         }
         // Fall back to a static string from the route.
         $route_title = $this->t($title, $args, $options);
     }
     return $route_title;
 }

作者:robertfoleyj    项目:robertfoleyjr-d   
/**
  * {@inheritdoc}
  */
 protected function processRoute(Route $route)
 {
     // Add entity upcasting information.
     $parameters = $route->getOption('parameters') ?: array();
     $parameters += array('menu_link_plugin' => array('type' => 'menu_link_plugin'));
     $route->setOption('parameters', $parameters);
 }


问题


面经


文章

微信
公众号

扫码关注公众号