当前位置: 首页>>代码示例>>PHP>>正文


PHP Route::hasDefault方法代码示例

本文整理汇总了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));
         }
     }
 }
开发者ID:brainexe,项目名称:core,代码行数:14,代码来源:Authentication.php

示例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) {
         }
     }
 }
开发者ID:rodrigojcmello,项目名称:scalable.design,代码行数:10,代码来源:RouterDebugCommand.php

示例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;
 }
开发者ID:Silwereth,项目名称:core,代码行数:54,代码来源:ZikulaPatternGenerationStrategy.php

示例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);
 }
开发者ID:brainexe,项目名称:core,代码行数:19,代码来源:Csrf.php

示例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
        );
    }
开发者ID:ninethousand,项目名称:NineThousandCompreduxBundle,代码行数:82,代码来源:CompreduxRouteCompiler.php

示例6: applies

 /**
  * {@inheritdoc}
  */
 public function applies(Route $route)
 {
     return !$route->hasDefault('_controller') && ($route->hasDefault('_entity_form') || $route->hasDefault('_entity_list') || $route->hasDefault('_entity_view'));
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:7,代码来源:EntityRouteEnhancer.php

示例7: applies

 /**
  * {@inheritdoc}
  */
 public function applies(Route $route)
 {
     return $route->hasDefault('_form') && !$route->hasDefault('_controller');
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:7,代码来源:FormRouteEnhancer.php

示例8: applies

 /**
  * {@inheritdoc}
  */
 public function applies(Route $route)
 {
     return $route->hasDefault('view_id');
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:7,代码来源:ViewsAccessCheck.php

示例9: applies

 /**
  * {@inheritdoc}
  */
 public function applies(Route $route)
 {
     return !$route->hasDefault('_controller') && ($route->hasDefault('_wizard') || $route->hasDefault('_entity_wizard'));
 }
开发者ID:eric-shell,项目名称:eric-shell-d8,代码行数:7,代码来源:WizardEnhancer.php

示例10: applies

 /**
  * {@inheritdoc}
  */
 public function applies(Route $route)
 {
     return $route->hasDefault('_entity_wizard') && strpos($route->getDefault('_entity_wizard'), 'entity_browser.') === 0;
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:7,代码来源:CtoolsFallbackRouteEnhancer.php

示例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()));
 }
开发者ID:backbee,项目名称:debug-bundle,代码行数:14,代码来源:DebugRoutingCommand.php

示例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;
 }
开发者ID:Wylbur,项目名称:gj,代码行数:12,代码来源:TempstoreConverter.php


注:本文中的Symfony\Component\Routing\Route::hasDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。