public function shouldExcludeRoute($routeName, Route $route) { if ('_' === $routeName[0] || !$route->hasOption('i18n')) { return true; } return false; }
public function testOption() { $route = new Route('/{foo}'); $this->assertFalse($route->hasOption('foo'), '->hasOption() return false if option is not set'); $this->assertEquals($route, $route->setOption('foo', 'bar'), '->setOption() implements a fluent interface'); $this->assertEquals('bar', $route->getOption('foo'), '->setOption() sets the option'); $this->assertTrue($route->hasOption('foo'), '->hasOption() return true if option is set'); }
/** * {@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]); } } } }
/** * @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); }
/** * {@inheritdoc} */ public function processRequest(Request $request, Route $route) { $givenToken = $request->headers->get(self::HEADER); $session = $request->getSession(); $expectedToken = $session->get(self::CSRF); if ($request->isMethod('GET') && !$route->hasOption(self::CSRF) || $route->hasDefault('_guest')) { if (empty($expectedToken)) { $this->renewCsrfToken(); } return; } if (empty($givenToken) || $givenToken !== $expectedToken) { throw new MethodNotAllowedException(['POST'], 'invalid CSRF token'); } $this->generateNewTokenWhenNeeded($session); }
/** * {@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 applies(Route $route) { return ($route->hasOption('_scheduled_updates')); }
/** * @param Route $route * @return array */ private function convertRouteToConfig(Route $route) { $className = $route->getOption(self::RESOURCE_ENTITY_CLASS_OPTION); $converter = $this->defaultConverter; if ($route->hasOption(self::RESOURCE_CONVERTER_OPTION)) { $converter = $route->getOption(self::RESOURCE_CONVERTER_OPTION); } if ($route->hasOption(self::RESOURCE_SINGULAR_NAME)) { $singular = $route->getOption(self::RESOURCE_SINGULAR_NAME); } else { $classNameParts = explode('\\', $className); end($classNameParts); $singular = strtolower(current($classNameParts)); } if ($route->hasOption(self::RESOURCE_PLURAL_NAME)) { $plural = $route->getOption(self::RESOURCE_PLURAL_NAME); } else { $plural = $this->inflector->pluralize($singular); } return ['route' => $route->getDefault('_route'), 'class' => $className, 'converter' => $converter, 'singular_name' => $singular, 'plural_name' => $plural]; }
/** * {@inheritdoc} */ public function applies(Route $route) { return $route->hasOption('_field_ui'); }
/** * {@inheritdoc} */ public function applies(Route $route) { return $route->hasOption('auto_label'); }
/** * @param Route $route * @return bool */ protected function isRouteFrontend(Route $route) { return $route->hasOption(self::FRONTEND_OPTION) && true === $route->getOption(self::FRONTEND_OPTION); }
/** * {@inheritdoc} */ public function applies(Route $route) { return $route->hasOption('_entity_layout'); }