本文整理汇总了PHP中Symfony\Component\Routing\Route::hasDefault方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::hasDefault方法的具体用法?PHP Route::hasDefault怎么用?PHP Route::hasDefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\Route
的用法示例。
在下文中一共展示了Route::hasDefault方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkForRole
/**
* @param Route $route
* @param UserVO $user
* @throws MethodNotAllowedException
*/
protected function checkForRole(Route $route, UserVO $user)
{
if ($route->hasDefault('_role')) {
$role = $route->getDefault('_role');
if (!in_array($role, $user->roles)) {
throw new MethodNotAllowedException([], sprintf('Need role %s', $role));
}
}
}
示例2: convertController
private function convertController(Route $route)
{
$nameParser = $this->getContainer()->get('controller_name_converter');
if ($route->hasDefault('_controller')) {
try {
$route->setDefault('_controller', $nameParser->build($route->getDefault('_controller')));
} catch (\InvalidArgumentException $e) {
}
}
}
示例3: generateI18nPatterns
/**
* {@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;
}
示例4: processRequest
/**
* {@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);
}
示例5: compile
/**
* Compiles the current route instance.
*
* @param Route $route A Route instance
*
* @return CompiledRoute A CompiledRoute instance
*/
public function compile(Route $route)
{
$pattern = $route->getPattern();
$len = strlen($pattern);
$tokens = array();
$variables = array();
$pos = 0;
preg_match_all('#.\{([\w\d_]+)\}#', $pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
foreach ($matches as $match) {
if ($text = substr($pattern, $pos, $match[0][1] - $pos)) {
$tokens[] = array('text', $text);
}
$seps = array($pattern[$pos]);
$pos = $match[0][1] + strlen($match[0][0]);
$var = $match[1][0];
if ($req = $route->getRequirement($var)) {
$regexp = $req;
} else {
if ($pos !== $len) {
$seps[] = $pattern[$pos];
}
$regexp = sprintf('[^%s]+?', preg_quote(implode('', array_unique($seps)), '#'));
}
$tokens[] = array('variable', $match[0][0][0], $regexp, $var);
$variables[] = $var;
}
if ($pos < $len) {
$tokens[] = array('text', substr($pattern, $pos));
}
// find the first optional token
$firstOptional = INF;
for ($i = count($tokens) - 1; $i >= 0; $i--) {
if ('variable' === $tokens[$i][0] && $route->hasDefault($tokens[$i][3])) {
$firstOptional = $i;
} else {
break;
}
}
// compute the matching regexp
$regex = '';
$indent = 1;
if (1 === count($tokens) && 0 === $firstOptional) {
$token = $tokens[0];
++$indent;
$regex .= str_repeat(' ', $indent * 4).sprintf("%s(?:\n", preg_quote($token[1], '#'));
$regex .= str_repeat(' ', $indent * 4).sprintf("(?P<%s>%s)\n", $token[3], $token[2]);
} else {
foreach ($tokens as $i => $token) {
if ('text' === $token[0]) {
$regex .= str_repeat(' ', $indent * 4).preg_quote($token[1], '#')."\n";
} else {
if ($i >= $firstOptional) {
$regex .= str_repeat(' ', $indent * 4)."(?:\n";
++$indent;
}
$regex .= str_repeat(' ', $indent * 4).sprintf("%s(?P<%s>%s)\n", preg_quote($token[1], '#'), $token[3], $token[2]);
}
}
}
while (--$indent) {
$regex .= str_repeat(' ', $indent * 4).")?\n";
}
return new CompiledRoute(
'text' === $tokens[0][0] ? $tokens[0][1] : '',
sprintf("#^\n%s#x", $regex),
array_reverse($tokens),
$variables
);
}
示例6: applies
/**
* {@inheritdoc}
*/
public function applies(Route $route)
{
return !$route->hasDefault('_controller') && ($route->hasDefault('_entity_form') || $route->hasDefault('_entity_list') || $route->hasDefault('_entity_view'));
}
示例7: applies
/**
* {@inheritdoc}
*/
public function applies(Route $route)
{
return $route->hasDefault('_form') && !$route->hasDefault('_controller');
}
示例8: applies
/**
* {@inheritdoc}
*/
public function applies(Route $route)
{
return $route->hasDefault('view_id');
}
示例9: applies
/**
* {@inheritdoc}
*/
public function applies(Route $route)
{
return !$route->hasDefault('_controller') && ($route->hasDefault('_wizard') || $route->hasDefault('_entity_wizard'));
}
示例10: applies
/**
* {@inheritdoc}
*/
public function applies(Route $route)
{
return $route->hasDefault('_entity_wizard') && strpos($route->getDefault('_entity_wizard'), 'entity_browser.') === 0;
}
示例11: convertController
/**
* Returns a more readable controller/action description for a Route.
*
* @param Route $route The selected Route
*
* @return string The couple Controller::Action if available
*/
private function convertController(Route $route)
{
if ($route->hasDefault('_controller') && $route->hasDefault('_action')) {
return $route->getDefault('_controller') . '::' . $route->getDefault('_action');
}
throw new \InvalidArgumentException(sprintf('The route with path "%s" does not have defaults _controller or _action.', $route->getPath()));
}
示例12: applies
/**
* {@inheritdoc}
*/
public function applies($definition, $name, Route $route)
{
if (!empty($definition['type']) && ($definition['type'] == 'tempstore' || strpos($definition['type'], 'tempstore:') === 0)) {
if (!empty($definition['tempstore_id']) || $route->hasDefault('tempstore_id')) {
return TRUE;
}
}
return FALSE;
}