/** * {@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); }
/** * {@inheritDoc} */ public function generateI18nPatterns($routeName, Route $route) { $patterns = array(); foreach ($route->getOption('i18n_locales') ?: $this->locales as $locale) { // Check if translation exists in the translation catalogue to avoid errors being logged by // the new LoggingTranslator of Symfony 2.6. However, the LoggingTranslator did not implement // the interface until Symfony 2.6.5, so an extra check is needed. if ($this->translator instanceof TranslatorBagInterface || $this->translator instanceof LoggingTranslator) { // Check if route is translated. if (!$this->translator->getCatalogue($locale)->has($routeName, $this->translationDomain)) { // No translation found. $i18nPattern = $route->getPattern(); } else { // Get translation. $i18nPattern = $this->translator->trans($routeName, array(), $this->translationDomain, $locale); } } else { // if no translation exists, we use the current pattern if ($routeName === ($i18nPattern = $this->translator->trans($routeName, array(), $this->translationDomain, $locale))) { $i18nPattern = $route->getPattern(); } } // prefix with locale if requested if (self::STRATEGY_PREFIX === $this->strategy || self::STRATEGY_PREFIX_EXCEPT_DEFAULT === $this->strategy && $this->defaultLocale !== $locale) { $i18nPattern = '/' . $locale . $i18nPattern; if (null !== $route->getOption('i18n_prefix')) { $i18nPattern = $route->getOption('i18n_prefix') . $i18nPattern; } } $patterns[$i18nPattern][] = $locale; } return $patterns; }
/** * {@inheritdoc} */ public function shouldExcludeRoute($routeName, Route $route) { if ('_' === $routeName[0]) { return true; } if (false === $route->getOption('i18n') || 'false' === $route->getOption('i18n')) { return true; } return false; }
/** * {@inheritDoc} */ public function generateI18nPatterns($routeName, Route $route) { $patterns = array(); foreach ($route->getOption('i18n_locales') ?: $this->locales as $locale) { // Check if translation exists in the translation catalogue to avoid errors being logged by // the new LoggingTranslator of Symfony 2.6. However, the LoggingTranslator did not implement // the interface until Symfony 2.6.5, so an extra check is needed. if ($this->translator instanceof TranslatorBagInterface || $this->translator instanceof LoggingTranslator) { // Check if route is translated. if (!$this->translator->getCatalogue($locale)->has($routeName, $this->translationDomain)) { // No translation found. $i18nPattern = $route->getPath(); } else { // Get translation. $i18nPattern = $this->translator->trans($routeName, array(), $this->translationDomain, $locale); } } else { // if no translation exists, we use the current pattern if ($routeName === ($i18nPattern = $this->translator->trans($routeName, array(), $this->translationDomain, $locale))) { $i18nPattern = $route->getPath(); } } /////////////////////////////////////// // Begin customizations // prefix with zikula module url if requested if ($route->hasDefault('_zkModule')) { $module = $route->getDefault('_zkModule'); $zkNoBundlePrefix = $route->getOption('zkNoBundlePrefix'); if (!isset($zkNoBundlePrefix) || !$zkNoBundlePrefix) { $untranslatedPrefix = $this->getModUrlString($module); if ($this->translator->getCatalogue($locale)->has($untranslatedPrefix, strtolower($module))) { $prefix = $this->translator->trans($untranslatedPrefix, [], strtolower($module), $locale); } else { $prefix = $untranslatedPrefix; } $i18nPattern = "/" . $prefix . $i18nPattern; } } // End customizations /////////////////////////////////////// // prefix with locale if requested if (self::STRATEGY_PREFIX === $this->strategy || self::STRATEGY_PREFIX_EXCEPT_DEFAULT === $this->strategy && $this->defaultLocale !== $locale) { $i18nPattern = '/' . $locale . $i18nPattern; if (null !== $route->getOption('i18n_prefix')) { $i18nPattern = $route->getOption('i18n_prefix') . $i18nPattern; } } $patterns[$i18nPattern][] = $locale; } return $patterns; }
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; }
/** * {@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); }
/** * {@inheritdoc} */ public function resolve(Route $route, RouteCollectionAccessor $routes) { if ($route->getOption('group') !== self::ROUTE_GROUP) { return; } if ($this->hasAttribute($route, self::ACTIVITY_PLACEHOLDER)) { $activities = array_map(function (ConfigInterface $config) { // convert to entity alias return $this->entityAliasResolver->getPluralAlias($config->getId()->getClassName()); }, $this->groupingConfigProvider->filter(function (ConfigInterface $config) { // filter activity entities $groups = $config->get('groups'); return !empty($groups) && in_array(ActivityScope::GROUP_ACTIVITY, $groups, true); })); if (!empty($activities)) { $activities = $this->adjustRoutes($route, $routes, $activities); if (!empty($activities)) { $route->setRequirement(self::ACTIVITY_ATTRIBUTE, implode('|', $activities)); } } $this->completeRouteRequirements($route); } elseif ($this->hasAttribute($route, self::ENTITY_PLACEHOLDER)) { $this->completeRouteRequirements($route); } }
/** * {@inheritdoc} */ public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method) { if ($route->getOption('group') !== RestRouteOptionsResolver::ROUTE_GROUP) { return; } $action = $route->getDefault('_action'); if (empty($action)) { return; } $entityClass = $this->getEntityClass($route); if ($entityClass) { $config = $this->getConfig($action, $entityClass); $this->setDescription($annotation, $action, (array) $config->getConfig(), $entityClass); if ($this->hasAttribute($route, RestRouteOptionsResolver::ID_PLACEHOLDER)) { $this->addIdRequirement($annotation, $entityClass, $route->getRequirement(RestRouteOptionsResolver::ID_ATTRIBUTE)); } if ($config->hasConfigExtra(FiltersConfigExtra::NAME) && method_exists($config, 'getFilters')) { $this->addFilters($annotation, $config->getFilters()); } } $formatRequirement = $route->getRequirement(RestRouteOptionsResolver::FORMAT_ATTRIBUTE); if ($formatRequirement) { $this->addFormatRequirement($annotation, $formatRequirement); } }
public function testConstructor() { $route = new Route('/{foo}', array('foo' => 'bar'), array('foo' => '\\d+'), array('foo' => 'bar')); $this->assertEquals('/{foo}', $route->getPattern(), '__construct() takes a pattern as its first argument'); $this->assertEquals(array('foo' => 'bar'), $route->getDefaults(), '__construct() takes defaults as its second argument'); $this->assertEquals(array('foo' => '\\d+'), $route->getRequirements(), '__construct() takes requirements as its third argument'); $this->assertEquals('bar', $route->getOption('foo'), '__construct() takes options as its fourth argument'); }
/** * {@inheritdoc} */ public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method) { if (!$route->getOption('old_options')) { return; } $annotation->setDeprecated(true); $annotation->setDocumentation($annotation->getDocumentation() . "\n\nDeprecated since v1.8. Will be removed in v2.0"); }
/** * Returns the default revision of the entity this route is for. * * @param \Symfony\Component\Routing\Route $route * The route to check against. * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The parametrized route. * * @return \Drupal\Core\Entity\ContentEntityInterface * returns the Entity in question. * * @throws \Exception * A generic exception is thrown if the entity couldn't be loaded. This * almost always implies a developer error, so it should get turned into * an HTTP 500. */ protected function loadEntity(Route $route, RouteMatchInterface $route_match) { $entity_type = $route->getOption('_content_moderation_entity_type'); if ($entity = $route_match->getParameter($entity_type)) { if ($entity instanceof EntityInterface) { return $entity; } } throw new \Exception(sprintf('%s is not a valid entity route. The LatestRevisionCheck access checker may only be used with a route that has a single entity parameter.', $route_match->getRouteName())); }
/** * {@inheritDoc} */ public function generateI18nPatterns($routeName, Route $route) { $patterns = array(); foreach ($route->getOption('i18n_locales') ?: $this->locales as $locale) { // if no translation exists, we use the current pattern if ($routeName === ($i18nPattern = $this->translator->trans($routeName, array(), $this->translationDomain, $locale))) { $i18nPattern = $route->getPattern(); } // prefix with locale if requested if (self::STRATEGY_PREFIX === $this->strategy || self::STRATEGY_PREFIX_EXCEPT_DEFAULT === $this->strategy && $this->defaultLocale !== $locale) { $i18nPattern = '/' . $locale . $i18nPattern; if (null !== $route->getOption('i18n_prefix')) { $i18nPattern = $route->getOption('i18n_prefix') . $i18nPattern; } } $patterns[$i18nPattern][] = $locale; } return $patterns; }
/** * {@inheritdoc} */ public function applies(Route $route) { // Check whether there is any entity revision parameter. $parameters = $route->getOption('parameters') ?: []; foreach ($parameters as $info) { if (isset($info['type']) && strpos($info['type'], 'entity_revision:') === 0) { return TRUE; } } return FALSE; }
public function generateI18nPatterns($routeName, Route $route) { $patterns = array(); $config = $route->getOption('i18n'); foreach ($this->locales as $locale) { // if no translation exists, we use the current pattern $i18nPattern = array_key_exists($locale, $config) ? $config[$locale] : $route->getPath(); $i18nPattern = '/' . $locale . $i18nPattern; $patterns[$i18nPattern][] = $locale; } return $patterns; }
/** * {@inheritdoc} */ public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL) { if ($route->hasOption('parameters')) { foreach ($route->getOption('parameters') as $type => $parameter) { // If the rdf_entity converter exists in the parameter, // then the parameter is of type rdf_entity and needs to be normalized. if (isset($parameter['converter']) && $parameter['converter'] == 'paramconverter.rdf_entity') { $parameters[$type] = str_replace('/', '\\', $parameters[$type]); } } } }
public function generateI18nPatterns($routeName, Route $route) { $patterns = []; /** @var FrozenParameterBag $parameterBag */ $parameterBag = $this->container->getParameterBag(); if (empty($this->offices)) { $this->offices = $this->container->get('doctrine')->getRepository('OctavaMuiBundle:Office')->getRoutingOffices(); } $translation = null; if ($structureId = $route->getDefault(Structure::ROUTING_ID_NAME)) { $structureRepository = $this->container->get('doctrine.orm.entity_manager')->getRepository('OctavaStructureBundle:Structure'); $translation = $structureRepository->getTranslations($structureRepository->getById($structureId)); } foreach (array_keys($this->offices) as $locale) { if ($translation !== null && empty($translation[$locale]['state'])) { // отключенная страница continue; } $office = $this->offices[$locale]; $i18nPattern = $route->getPath(); $paths = $route->getOption('translatable_path'); if (!empty($paths[$locale])) { $i18nPattern = $paths[$locale]; } if ($office->getIncludeLangInUrl()) { $i18nPattern = '/{_locale}' . $i18nPattern; } if (null !== ($prefix = $route->getOption('i18n_prefix'))) { $prefix = $parameterBag->resolveValue($prefix); $i18nPattern = $prefix . $i18nPattern; } $host = $office->getHost(); if (empty($patterns[$i18nPattern][$host])) { $patterns[$i18nPattern][$host] = []; } $patterns[$i18nPattern][$host][] = $locale; } return $patterns; }
public function generateI18nPatterns($routeName, Route $route) { $patterns = []; /** @var \Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag $parameterBag */ $parameterBag = $this->container->getParameterBag(); $locales = $route->getOption('i18n_locales') ?: $this->locales; $locales = $parameterBag->resolveValue($locales); foreach ($locales as $locale) { $i18nPattern = $route->getPath(); // prefix with locale if requested if (DefaultPatternGenerationStrategy::STRATEGY_PREFIX === $this->strategy || DefaultPatternGenerationStrategy::STRATEGY_PREFIX === $route->getOption('i18n_strategy') || DefaultPatternGenerationStrategy::STRATEGY_PREFIX_EXCEPT_DEFAULT === $this->strategy && $this->defaultLocale !== $locale) { $i18nPattern = '/{_locale}' . $i18nPattern; if (null !== $route->getOption('i18n_prefix')) { $prefix = $route->getOption('i18n_prefix'); $prefix = $parameterBag->resolveValue($prefix); $i18nPattern = $prefix . $i18nPattern; } } $patterns[$i18nPattern][] = $locale; } return $patterns; }
/** * {@inheritdoc} */ public function resolve(Route $route, RouteCollectionAccessor $routes) { if ($route->getOption('group') !== self::ROUTE_GROUP) { return; } if ($this->hasAttribute($route, self::ENTITY_PLACEHOLDER)) { $this->setFormatAttribute($route); $entities = $this->getSupportedEntityClasses(); if (!empty($entities)) { $this->adjustRoutes($route, $routes, $entities); } } }
/** * Builds an array of breadcrumbs for the given route recursively * * @param Route $route * @param string $routeKey * @param RouteCollection $routeCollection * * @return array */ private function getBreadcrumbs(Route $route, $routeKey, RouteCollection $routeCollection) { $breadcrumbOptions = $route->getOption('breadcrumb'); $rawBreadcrumbsCollection = array(); if (isset($breadcrumbOptions['parent_route'])) { $rawBreadcrumbsCollection = $this->getBreadcrumbs($routeCollection->get($breadcrumbOptions['parent_route']), $breadcrumbOptions['parent_route'], $routeCollection); } if (false === isset($breadcrumbOptions['label'])) { throw new \InvalidArgumentException(sprintf('Label for breadcrumb on route "%s" must be configured', $routeKey)); } $rawBreadcrumbsCollection[] = array('route' => $routeKey, 'label' => $breadcrumbOptions['label']); return $rawBreadcrumbsCollection; }
/** * {@inheritDoc} */ public function generateI18nPatterns($routeName, Route $route) { $locales = $route->getOption('i18n_locales') ?: $this->locales; $patterns = array(); // "routes" option which store all translations for a given route (TODO: required after refacto) if (null !== ($routes = $route->getOption('routes')) && !isset($routes[$this->defaultLocale])) { throw new \InvalidArgumentException(sprintf('The "path" option for the route "%s" must have at least the %s translation.', $routeName, $this->defaultLocale)); } foreach ($locales as $locale) { // if no translation exists, we use the current pattern $i18nPattern = $this->translator->trans($routeName, array(), $this->translationDomain, $locale); // overload the routes' translations from translations' files by the routes' translations from route' files if (null !== $routes) { $i18nPattern = isset($routes[$locale]) ? $routes[$locale] : $routes[$this->defaultLocale]; } if ($routeName === $i18nPattern) { $i18nPattern = $route->getPath(); } $patterns[$i18nPattern][] = $locale; } return $patterns; }
/** * {@inheritdoc} */ public function resolve(Route $route, RouteCollectionAccessor $routes) { if ($route->getOption('group') !== self::ROUTE_GROUP) { return; } if ($this->hasAttribute($route, self::ENTITY_PLACEHOLDER)) { $entities = $this->getSupportedEntities(); if (!empty($entities)) { $this->adjustRoutes($route, $routes, $entities); } $route->setRequirement(self::ENTITY_ATTRIBUTE, '\\w+'); $route->setOption('hidden', true); } }
public function generateI18nPatterns($routeName, Route $route) { $patterns = []; foreach ($route->getOption('i18n_locales') ?: $this->locales as $locale) { // if no translation exists, we use the current pattern if ($routeName === ($i18nPattern = $this->translator->trans($routeName, [], $this->translationDomain, $locale))) { $i18nPattern = $route->getPath(); } // prefix with locale if requested if (self::STRATEGY_PREFIX === $this->strategy || self::STRATEGY_PREFIX === $route->getOption('i18n_strategy') || self::STRATEGY_PREFIX_EXCEPT_DEFAULT === $this->strategy && $this->defaultLocale !== $locale) { $i18nPattern = '/' . $locale . $i18nPattern; if (null !== $route->getOption('i18n_prefix')) { $prefix = $route->getOption('i18n_prefix'); /** @var FrozenParameterBag $parameterBag */ $parameterBag = $this->container->getParameterBag(); $prefix = $parameterBag->resolveValue($prefix); $i18nPattern = $prefix . $i18nPattern; } } $patterns[$i18nPattern][] = $locale; } return $patterns; }
/** * @param Route $route * @return CsrfToken|null */ public function getTokenFromRoute(Route $route) { // Check if route has the option if (!$route->hasOption(self::OPTION_NAME)) { return null; } // Get option $option = $route->getOption(self::OPTION_NAME); if (!$option) { return null; } // Get token return $this->getTokenFromOption($option); }
public function testConstructor() { $route = new Route('/{foo}', array('foo' => 'bar'), array('foo' => '\\d+'), array('foo' => 'bar'), '{locale}.example.com'); $this->assertEquals('/{foo}', $route->getPath(), '__construct() takes a path as its first argument'); $this->assertEquals(array('foo' => 'bar'), $route->getDefaults(), '__construct() takes defaults as its second argument'); $this->assertEquals(array('foo' => '\\d+'), $route->getRequirements(), '__construct() takes requirements as its third argument'); $this->assertEquals('bar', $route->getOption('foo'), '__construct() takes options as its fourth argument'); $this->assertEquals('{locale}.example.com', $route->getHost(), '__construct() takes a host pattern as its fifth argument'); $route = new Route('/', array(), array(), array(), '', array('Https'), array('POST', 'put')); $this->assertEquals(array('https'), $route->getSchemes(), '__construct() takes schemes as its sixth argument and lowercases it'); $this->assertEquals(array('POST', 'PUT'), $route->getMethods(), '__construct() takes methods as its seventh argument and uppercases it'); $route = new Route('/', array(), array(), array(), '', 'Https', 'Post'); $this->assertEquals(array('https'), $route->getSchemes(), '__construct() takes a single scheme as its sixth argument'); $this->assertEquals(array('POST'), $route->getMethods(), '__construct() takes a single method as its seventh argument'); }
/** * {@inheritdoc} */ public function resolve(Route $route, RouteCollectionAccessor $routes) { if ($route->getOption('group') !== self::ROUTE_GROUP) { return; } if ($this->hasAttribute($route, self::ENTITY_PLACEHOLDER)) { $entities = $this->dictionaryProvider->getSupportedEntityClasses(); if (!empty($entities)) { $entities = $this->adjustRoutes($route, $routes, $entities); if (!empty($entities)) { $route->setRequirement(self::ENTITY_ATTRIBUTE, implode('|', $entities)); } } } }
/** * {@inheritdoc} */ public function access(Route $route, AccountInterface $account, Request $request = NULL) { if (empty($request)) { $request = $this->requestStack->getCurrentRequest(); } $operation = $route->getRequirement('_entity_access_revision'); list(, $operation) = explode('.', $operation, 2); if ($operation === 'list') { $_entity = $request->attributes->get('_entity', $request->attributes->get($route->getOption('entity_type_id'))); return AccessResult::allowedIf($this->checkAccess($_entity, $account, $operation))->cachePerPermissions(); } else { $_entity_revision = $request->attributes->get('_entity_revision'); return AccessResult::allowedIf($_entity_revision && $this->checkAccess($_entity_revision, $account, $operation))->cachePerPermissions(); } }
/** * {@inheritdoc} */ public function processRequest(Request $request, Route $route) { if (!$this->enabled || !$route->hasOption('cache') || !$request->isMethod('GET')) { return null; } $cacheKey = $this->generateCacheKey($request); $ttl = $route->getOption('cache'); $cache = $this->getCache(); if ($cache->hasItem($cacheKey)) { return $this->handleCached($cache, $cacheKey, $ttl); } // enable cache for current request. Store response later in given key $request->attributes->set('_cacheKey', $cacheKey); $request->attributes->set('_cacheTTL', $ttl); return null; }
/** * {@inheritdoc} */ public function resolve(Route $route, RouteCollectionAccessor $routes) { if ($route->getOption('group') !== self::ROUTE_GROUP) { return; } if ($this->hasAttribute($route, self::ACTIVITY_PLACEHOLDER)) { $activities = $this->getSupportedActivities(); if (!empty($activities)) { $this->adjustRoutes($route, $routes, $activities); } $this->completeRouteRequirements($route); $route->setOption('hidden', true); } elseif ($this->hasAttribute($route, self::ENTITY_PLACEHOLDER)) { $this->completeRouteRequirements($route); } }
/** * Checks access based on a CSRF token for the request. * * @param \Symfony\Component\Routing\Route $route * The route to check against. * @param \Symfony\Component\HttpFoundation\Request $request * The request object. * * @return string * A \Drupal\Core\Access\AccessInterface constant value. */ public function access(Route $route, Request $request) { // If this is the controller request, check CSRF access as normal. if ($request->attributes->get('_controller_request')) { // @todo Remove dependency on the internal _system_path attribute: // https://www.drupal.org/node/2293501. return $this->csrfToken->validate($request->query->get('token'), $request->attributes->get('_system_path')) ? static::ALLOW : static::KILL; } // Otherwise, this could be another requested access check that we don't // want to check CSRF tokens on. $conjunction = $route->getOption('_access_mode') ?: 'ANY'; // Return ALLOW if all access checks are needed. if ($conjunction == 'ALL') { return static::ALLOW; } else { return static::DENY; } }
/** * {@inheritdoc} */ public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method) { if ($route->getOption('group') !== DictionaryEntityRouteOptionsResolver::ROUTE_GROUP) { return; } $pluralAlias = $route->getDefault(DictionaryEntityRouteOptionsResolver::ENTITY_ATTRIBUTE); if (!$pluralAlias) { return; } $className = $this->entityAliasResolver->getClassByPluralAlias($pluralAlias); $pluralName = $this->entityClassNameProvider->getEntityClassPluralName($className); if ($pluralName) { $annotation->setDescription(strtr(static::DESCRIPTION_TEMPLATE, ['{plural_name}' => $pluralName])); $annotation->setDocumentation(strtr(static::DOCUMENTATION_TEMPLATE, ['{plural_name}' => $pluralName])); } else { $annotation->setDescription(strtr(static::FALLBACK_DESCRIPTION_TEMPLATE, ['{class}' => $className])); $annotation->setDocumentation(strtr(static::FALLBACK_DOCUMENTATION_TEMPLATE, ['{class}' => $className])); } }