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


PHP Route::getCondition方法代码示例

本文整理汇总了PHP中Symfony\Component\Routing\Route::getCondition方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::getCondition方法的具体用法?PHP Route::getCondition怎么用?PHP Route::getCondition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Routing\Route的用法示例。


在下文中一共展示了Route::getCondition方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handleRouteRequirements

 /**
  * {@inheritdoc}
  */
 protected function handleRouteRequirements($pathinfo, $name, Route $route)
 {
     // expression condition
     if ($route->getCondition() && !$this->getExpressionLanguage()->evaluate($route->getCondition(), array('context' => $this->context, 'request' => $this->request))) {
         return array(self::REQUIREMENT_MISMATCH, null);
     }
     // check HTTP scheme requirement
     $scheme = $route->getRequirement('_scheme');
     if ($scheme && $this->context->getScheme() !== $scheme) {
         return array(self::ROUTE_MATCH, $this->redirect($pathinfo, $name, $scheme));
     }
     return array(self::REQUIREMENT_MATCH, null);
 }
开发者ID:flelievre,项目名称:EasyVisit,代码行数:16,代码来源:RedirectableUrlMatcher.php

示例2: handleRouteRequirements

 protected function handleRouteRequirements($pathinfo, $name, Route $route)
 {
     if ($route->getCondition() && !$this->getExpressionLanguage()->evaluate($route->getCondition(), array('context' => $this->context, 'request' => $this->request))) {
         return array(self::REQUIREMENT_MISMATCH, null);
     }
     $scheme = $this->context->getScheme();
     $schemes = $route->getSchemes();
     if ($schemes && !$route->hasScheme($scheme)) {
         return array(self::ROUTE_MATCH, $this->redirect($pathinfo, $name, current($schemes)));
     }
     return array(self::REQUIREMENT_MATCH, null);
 }
开发者ID:Cronverk,项目名称:lr_application,代码行数:12,代码来源:classes.php

示例3: testCondition

 public function testCondition()
 {
     $route = new Route('/');
     $this->assertEquals(null, $route->getCondition());
     $route->setCondition('context.getMethod() == "GET"');
     $this->assertEquals('context.getMethod() == "GET"', $route->getCondition());
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:7,代码来源:RouteTest.php

示例4: handleRouteRequirements

 /**
  * Handles specific route requirements.
  *
  * @param string $pathinfo The path
  * @param string $name     The route name
  * @param Route  $route    The route
  *
  * @return array The first element represents the status, the second contains additional information
  */
 protected function handleRouteRequirements($pathinfo, $name, Route $route)
 {
     // expression condition
     if ($route->getCondition() && !$this->getExpressionLanguage()->evaluate($route->getCondition(), array('context' => $this->context, 'request' => $this->request))) {
         return array(self::REQUIREMENT_MISMATCH, null);
     }
     // check HTTP scheme requirement
     $scheme = $this->context->getScheme();
     $status = $route->getSchemes() && !$route->hasScheme($scheme) ? self::REQUIREMENT_MISMATCH : self::REQUIREMENT_MATCH;
     return array($status, null);
 }
开发者ID:GeorgeBroadley,项目名称:caffeine-vendor,代码行数:20,代码来源:UrlMatcher.php

示例5: compileRoute

    /**
     * Compiles a single Route to PHP code used to match it against the path info.
     *
     * @param Route       $route                A Route instance
     * @param string      $name                 The name of the Route
     * @param bool        $supportsRedirections Whether redirections are supported by the base class
     * @param string|null $parentPrefix         The prefix of the parent collection used to optimize the code
     *
     * @return string PHP code
     *
     * @throws \LogicException
     */
    private function compileRoute(Route $route, $name, $supportsRedirections, $parentPrefix = null)
    {
        $code = '';
        $compiledRoute = $route->compile();
        $conditions = array();
        $hasTrailingSlash = false;
        $matches = false;
        $hostMatches = false;
        $methods = $route->getMethods();
        // GET and HEAD are equivalent
        if (in_array('GET', $methods) && !in_array('HEAD', $methods)) {
            $methods[] = 'HEAD';
        }
        $supportsTrailingSlash = $supportsRedirections && (!$methods || in_array('HEAD', $methods));
        if (!count($compiledRoute->getPathVariables()) && false !== preg_match('#^(.)\\^(?P<url>.*?)\\$\\1#', $compiledRoute->getRegex(), $m)) {
            if ($supportsTrailingSlash && substr($m['url'], -1) === '/') {
                $conditions[] = sprintf("rtrim(\$pathinfo, '/') === %s", var_export(rtrim(str_replace('\\', '', $m['url']), '/'), true));
                $hasTrailingSlash = true;
            } else {
                $conditions[] = sprintf("\$pathinfo === %s", var_export(str_replace('\\', '', $m['url']), true));
            }
        } else {
            if ($compiledRoute->getStaticPrefix() && $compiledRoute->getStaticPrefix() !== $parentPrefix) {
                $conditions[] = sprintf("0 === strpos(\$pathinfo, %s)", var_export($compiledRoute->getStaticPrefix(), true));
            }
            $regex = $compiledRoute->getRegex();
            if ($supportsTrailingSlash && ($pos = strpos($regex, '/$'))) {
                $regex = substr($regex, 0, $pos) . '/?$' . substr($regex, $pos + 2);
                $hasTrailingSlash = true;
            }
            $conditions[] = sprintf("preg_match(%s, \$pathinfo, \$matches)", var_export($regex, true));
            $matches = true;
        }
        if ($compiledRoute->getHostVariables()) {
            $hostMatches = true;
        }
        if ($route->getCondition()) {
            $conditions[] = $this->getExpressionLanguage()->compile($route->getCondition(), array('context', 'request'));
        }
        $conditions = implode(' && ', $conditions);
        $code .= <<<EOF
        // {$name}
        if ({$conditions}) {

EOF;
        $gotoname = 'not_' . preg_replace('/[^A-Za-z0-9_]/', '', $name);
        if ($methods) {
            if (1 === count($methods)) {
                $code .= <<<EOF
            if (\$this->context->getMethod() != '{$methods['0']}') {
                \$allow[] = '{$methods['0']}';
                goto {$gotoname};
            }


EOF;
            } else {
                $methods = implode("', '", $methods);
                $code .= <<<EOF
            if (!in_array(\$this->context->getMethod(), array('{$methods}'))) {
                \$allow = array_merge(\$allow, array('{$methods}'));
                goto {$gotoname};
            }


EOF;
            }
        }
        if ($hasTrailingSlash) {
            $code .= <<<EOF
            if (substr(\$pathinfo, -1) !== '/') {
                return \$this->redirect(\$pathinfo.'/', '{$name}');
            }


EOF;
        }
        if ($schemes = $route->getSchemes()) {
            if (!$supportsRedirections) {
                throw new \LogicException('The "schemes" requirement is only supported for URL matchers that implement RedirectableUrlMatcherInterface.');
            }
            $schemes = str_replace("\n", '', var_export(array_flip($schemes), true));
            $code .= <<<EOF
            \$requiredSchemes = {$schemes};
            if (!isset(\$requiredSchemes[\$this->context->getScheme()])) {
                return \$this->redirect(\$pathinfo, '{$name}', key(\$requiredSchemes));
            }

//.........这里部分代码省略.........
开发者ID:jacobDaeHyung,项目名称:laravel_bus_reservation,代码行数:101,代码来源:PhpMatcherDumper.php


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