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


PHP Route::compile方法代码示例

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


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

示例1: describeRoute

 /**
  * {@inheritdoc}
  */
 protected function describeRoute(Route $route, array $options = array())
 {
     $tableHeaders = array('Property', 'Value');
     $tableRows = array(array('Route Name', $options['name']), array('Path', $route->getPath()), array('Path Regex', $route->compile()->getRegex()), array('Host', '' !== $route->getHost() ? $route->getHost() : 'ANY'), array('Host Regex', '' !== $route->getHost() ? $route->compile()->getHostRegex() : ''), array('Scheme', $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY'), array('Method', $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY'), array('Requirements', $route->getRequirements() ? $this->formatRouterConfig($route->getRequirements()) : 'NO CUSTOM'), array('Class', get_class($route)), array('Defaults', $this->formatRouterConfig($route->getDefaults())), array('Options', $this->formatRouterConfig($route->getOptions())));
     $table = new Table($this->getOutput());
     $table->setHeaders($tableHeaders)->setRows($tableRows);
     $table->render();
 }
开发者ID:romankd,项目名称:symfony,代码行数:11,代码来源:TextDescriptor.php

示例2: describeRoute

 /**
  * {@inheritdoc}
  */
 protected function describeRoute(Route $route, array $options = array())
 {
     $requirements = $route->getRequirements();
     unset($requirements['_scheme'], $requirements['_method']);
     $output = '- Path: ' . $route->getPath() . "\n" . '- Path Regex: ' . $route->compile()->getRegex() . "\n" . '- Host: ' . ('' !== $route->getHost() ? $route->getHost() : 'ANY') . "\n" . '- Host Regex: ' . ('' !== $route->getHost() ? $route->compile()->getHostRegex() : '') . "\n" . '- Scheme: ' . ($route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY') . "\n" . '- Method: ' . ($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY') . "\n" . '- Class: ' . get_class($route) . "\n" . '- Defaults: ' . $this->formatRouterConfig($route->getDefaults()) . "\n" . '- Requirements: ' . ($requirements ? $this->formatRouterConfig($requirements) : 'NO CUSTOM') . "\n" . '- Options: ' . $this->formatRouterConfig($route->getOptions());
     $this->write(isset($options['name']) ? $options['name'] . "\n" . str_repeat('-', strlen($options['name'])) . "\n\n" . $output : $output);
     $this->write("\n");
 }
开发者ID:source-foundry,项目名称:code-corpora,代码行数:11,代码来源:MarkdownDescriptor.php

示例3: describeRoute

 /**
  * {@inheritdoc}
  */
 protected function describeRoute(Route $route, array $options = array())
 {
     // fixme: values were originally written as raw
     $description = array('<comment>Path</comment>         ' . $route->getPath(), '<comment>Path Regex</comment>   ' . $route->compile()->getRegex(), '<comment>Host</comment>         ' . ('' !== $route->getHost() ? $route->getHost() : 'ANY'), '<comment>Host Regex</comment>   ' . ('' !== $route->getHost() ? $route->compile()->getHostRegex() : ''), '<comment>Scheme</comment>       ' . ($route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY'), '<comment>Method</comment>       ' . ($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY'), '<comment>Class</comment>        ' . get_class($route), '<comment>Defaults</comment>     ' . $this->formatRouterConfig($route->getDefaults()), '<comment>Requirements</comment> ' . ($route->getRequirements() ? $this->formatRouterConfig($route->getRequirements()) : 'NO CUSTOM'), '<comment>Options</comment>      ' . $this->formatRouterConfig($route->getOptions()));
     if (isset($options['name'])) {
         array_unshift($description, '<comment>Name</comment>         ' . $options['name']);
         array_unshift($description, $this->formatSection('router', sprintf('Route "%s"', $options['name'])));
     }
     $this->writeText(implode("\n", $description) . "\n", $options);
 }
开发者ID:ninvfeng,项目名称:symfony,代码行数:13,代码来源:TextDescriptor.php

示例4: createFromRoute

 public function createFromRoute(Route $route)
 {
     $compiledRoute = $route->compile();
     $defaults = array_intersect_key($route->getDefaults(), array_fill_keys($compiledRoute->getVariables(), null));
     $tokens = $compiledRoute->getTokens();
     return new ExtractedRoute($tokens, $defaults);
 }
开发者ID:funddy,项目名称:jsrouting-bundle,代码行数:7,代码来源:ExtractedRouteFactory.php

示例5: matchCollection

    protected function matchCollection($pathinfo, RouteCollection $routes)
    {
        foreach ($routes as $name => $route) {
            $compiledRoute = $route->compile();

            if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
                // does it match without any requirements?
                $r = new Route($route->getPath(), $route->getDefaults(), array(), $route->getOptions());
                $cr = $r->compile();
                if (!preg_match($cr->getRegex(), $pathinfo)) {
                    $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);

                    continue;
                }

                foreach ($route->getRequirements() as $n => $regex) {
                    $r = new Route($route->getPath(), $route->getDefaults(), array($n => $regex), $route->getOptions());
                    $cr = $r->compile();

                    if (in_array($n, $cr->getVariables()) && !preg_match($cr->getRegex(), $pathinfo)) {
                        $this->addTrace(sprintf('Requirement for "%s" does not match (%s)', $n, $regex), self::ROUTE_ALMOST_MATCHES, $name, $route);

                        continue 2;
                    }
                }

                continue;
            }

            // check HTTP method requirement
            if ($req = $route->getRequirement('_method')) {
                // HEAD and GET are equivalent as per RFC
                if ('HEAD' === $method = $this->context->getMethod()) {
                    $method = 'GET';
                }

                if (!in_array($method, $req = explode('|', strtoupper($req)))) {
                    $this->allow = array_merge($this->allow, $req);

                    $this->addTrace(sprintf('Method "%s" does not match the requirement ("%s")', $this->context->getMethod(), implode(', ', $req)), self::ROUTE_ALMOST_MATCHES, $name, $route);

                    continue;
                }
            }

            // check HTTP scheme requirement
            if ($scheme = $route->getRequirement('_scheme')) {
                if ($this->context->getScheme() !== $scheme) {
                    $this->addTrace(sprintf('Scheme "%s" does not match the requirement ("%s"); the user will be redirected', $this->context->getScheme(), $scheme), self::ROUTE_ALMOST_MATCHES, $name, $route);

                    return true;
                }
            }

            $this->addTrace('Route matches!', self::ROUTE_MATCHES, $name, $route);

            return true;
        }
    }
开发者ID:nysander,项目名称:symfony,代码行数:59,代码来源:TraceableUrlMatcher.php

示例6: matchCollection

 protected function matchCollection($pathinfo, RouteCollection $routes)
 {
     foreach ($routes as $name => $route) {
         $compiledRoute = $route->compile();
         if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
             // does it match without any requirements?
             $r = new Route($route->getPath(), $route->getDefaults(), array(), $route->getOptions());
             $cr = $r->compile();
             if (!preg_match($cr->getRegex(), $pathinfo)) {
                 $this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
                 continue;
             }
             foreach ($route->getRequirements() as $n => $regex) {
                 $r = new Route($route->getPath(), $route->getDefaults(), array($n => $regex), $route->getOptions());
                 $cr = $r->compile();
                 if (in_array($n, $cr->getVariables()) && !preg_match($cr->getRegex(), $pathinfo)) {
                     $this->addTrace(sprintf('Requirement for "%s" does not match (%s)', $n, $regex), self::ROUTE_ALMOST_MATCHES, $name, $route);
                     continue 2;
                 }
             }
             continue;
         }
         // check host requirement
         $hostMatches = array();
         if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
             $this->addTrace(sprintf('Host "%s" does not match the requirement ("%s")', $this->context->getHost(), $route->getHost()), self::ROUTE_ALMOST_MATCHES, $name, $route);
             continue;
         }
         // check HTTP method requirement
         if ($req = $route->getRequirement('_method')) {
             // HEAD and GET are equivalent as per RFC
             if ('HEAD' === ($method = $this->context->getMethod())) {
                 $method = 'GET';
             }
             if (!in_array($method, $req = explode('|', strtoupper($req)))) {
                 $this->allow = array_merge($this->allow, $req);
                 $this->addTrace(sprintf('Method "%s" does not match the requirement ("%s")', $this->context->getMethod(), implode(', ', $req)), self::ROUTE_ALMOST_MATCHES, $name, $route);
                 continue;
             }
         }
         // check condition
         if ($condition = $route->getCondition()) {
             if (!$this->getExpressionLanguage()->evaluate($condition, array('context' => $this->context, 'request' => $this->request))) {
                 $this->addTrace(sprintf('Condition "%s" does not evaluate to "true"', $condition), self::ROUTE_ALMOST_MATCHES, $name, $route);
                 continue;
             }
         }
         // check HTTP scheme requirement
         if ($requiredSchemes = $route->getSchemes()) {
             $scheme = $this->context->getScheme();
             if (!$route->hasScheme($scheme)) {
                 $this->addTrace(sprintf('Scheme "%s" does not match any of the required schemes ("%s"); the user will be redirected to first required scheme', $scheme, implode(', ', $requiredSchemes)), self::ROUTE_ALMOST_MATCHES, $name, $route);
                 return true;
             }
         }
         $this->addTrace('Route matches!', self::ROUTE_MATCHES, $name, $route);
         return true;
     }
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:59,代码来源:TraceableUrlMatcher.php

示例7: getParameters

 /**
  * @param Route $route
  * @return Generator
  */
 private function getParameters(Route $route) : Generator
 {
     /** @var CompiledRoute $compiled */
     $compiled = $route->compile();
     foreach ($compiled->getVariables() as $name) {
         (yield ['name' => $name, 'type' => 'string', 'required' => true, 'in' => 'path']);
     }
 }
开发者ID:brainexe,项目名称:core,代码行数:12,代码来源:SwaggerDumpCommand.php

示例8: handle

 public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method)
 {
     // description
     if (null === $annotation->getDescription()) {
         $comments = explode("\n", $annotation->getDocumentation());
         // just set the first line
         $comment = trim($comments[0]);
         $comment = preg_replace("#\n+#", ' ', $comment);
         $comment = preg_replace('#\\s+#', ' ', $comment);
         $comment = preg_replace('#[_`*]+#', '', $comment);
         if ('@' !== substr($comment, 0, 1)) {
             $annotation->setDescription($comment);
         }
     }
     // requirements
     $requirements = $annotation->getRequirements();
     foreach ($route->getRequirements() as $name => $value) {
         if (!isset($requirements[$name]) && '_method' !== $name) {
             $requirements[$name] = array('requirement' => $value, 'dataType' => '', 'description' => '');
         }
         if ('_scheme' == $name) {
             $https = 'https' == $value;
             $annotation->setHttps($https);
         }
     }
     $paramDocs = array();
     foreach (explode("\n", $this->commentExtractor->getDocComment($method)) as $line) {
         if (preg_match('{^@param (.+)}', trim($line), $matches)) {
             $paramDocs[] = $matches[1];
         }
         if (preg_match('{^@deprecated\\b(.*)}', trim($line), $matches)) {
             $annotation->setDeprecated(true);
         }
         if (preg_match('{^@link\\b(.*)}', trim($line), $matches)) {
             $annotation->setLink($matches[1]);
         }
     }
     $regexp = '{(\\w*) *\\$%s\\b *(.*)}i';
     foreach ($route->compile()->getVariables() as $var) {
         $found = false;
         foreach ($paramDocs as $paramDoc) {
             if (preg_match(sprintf($regexp, preg_quote($var)), $paramDoc, $matches)) {
                 $requirements[$var]['dataType'] = isset($matches[1]) ? $matches[1] : '';
                 $requirements[$var]['description'] = $matches[2];
                 if (!isset($requirements[$var]['requirement'])) {
                     $requirements[$var]['requirement'] = '';
                 }
                 $found = true;
                 break;
             }
         }
         if (!isset($requirements[$var]) && false === $found) {
             $requirements[$var] = array('requirement' => '', 'dataType' => '', 'description' => '');
         }
     }
     $annotation->setRequirements($requirements);
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:57,代码来源:PhpDocHandler.php

示例9: testCompilationDefaultValue

 /**
  * Confirms that a compiled route with default values has the correct outline.
  */
 public function testCompilationDefaultValue()
 {
     // Because "here" has a default value, it should not factor into the outline
     // or the fitness.
     $route = new Route('/test/{something}/more/{here}', array('here' => 'there'));
     $route->setOption('compiler_class', 'Drupal\\Core\\Routing\\RouteCompiler');
     $compiled = $route->compile();
     $this->assertEquals($compiled->getFit(), 5, 'The fit was not correct.');
     $this->assertEquals($compiled->getPatternOutline(), '/test/%/more', 'The pattern outline was not correct.');
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:13,代码来源:RouteCompilerTest.php

示例10: applies

 /**
  * {@inheritdoc}
  */
 public function applies($definition, $name, Route $route)
 {
     if (!empty($definition['type']) && strpos($definition['type'], 'entity_revision:') === 0) {
         $entity_type_id = substr($definition['type'], strlen('entity:'));
         if (strpos($definition['type'], '{') !== FALSE) {
             $entity_type_slug = substr($entity_type_id, 1, -1);
             return $name != $entity_type_slug && in_array($entity_type_slug, $route->compile()->getVariables(), TRUE);
         }
         return $this->entityManager->hasDefinition($entity_type_id);
     }
     return FALSE;
 }
开发者ID:sedurzu,项目名称:ildeposito8,代码行数:15,代码来源:EntityRevisionConverter.php

示例11: compile

 public function compile()
 {
     $defaults = $this->getDefaults();
     if (array_key_exists('_formats', $defaults)) {
         $path = $this->getPath();
         // add format to the path
         $this->setPath($path . ".{_format}");
         // add a requirement
         $this->addRequirements(['_format' => implode('|', $defaults['_formats'])]);
     }
     return parent::compile();
 }
开发者ID:boltphp,项目名称:core,代码行数:12,代码来源:route.php

示例12: getDataFromRoute

 /**
  * get collection and id from route
  *
  * @param Route  $route route to look at
  * @param string $value value of reference as URI
  *
  * @return array
  */
 private function getDataFromRoute(Route $route, $value)
 {
     if ($route->getRequirement('id') !== null && $route->getMethods() === ['GET'] && preg_match($route->compile()->getRegex(), $value, $matches)) {
         $id = $matches['id'];
         list($routeService) = explode(':', $route->getDefault('_controller'));
         list($core, $bundle, , $name) = explode('.', $routeService);
         $serviceName = implode('.', [$core, $bundle, 'rest', $name]);
         $collection = array_search($serviceName, $this->mapping);
         return [$collection, $id];
     }
     return [null, null];
 }
开发者ID:alebon,项目名称:graviton,代码行数:20,代码来源:ExtReferenceConverter.php

示例13: applies

 /**
  * {@inheritdoc}
  */
 public function applies($definition, $name, Route $route)
 {
     if (!empty($definition['type']) && strpos($definition['type'], 'entity:') === 0) {
         $entity_type_id = substr($definition['type'], strlen('entity:'));
         if (strpos($definition['type'], '{') !== FALSE) {
             $entity_type_slug = substr($entity_type_id, 1, -1);
             return $name != $entity_type_slug && in_array($entity_type_slug, $route->compile()->getVariables(), TRUE);
         }
         // This converter only applies rdf entities.
         $entity_storage = $this->entityManager->getStorage($entity_type_id);
         if ($entity_storage instanceof RdfEntitySparqlStorage) {
             return $this->entityManager->hasDefinition($entity_type_id);
         }
     }
     return FALSE;
 }
开发者ID:ec-europa,项目名称:joinup-dev,代码行数:19,代码来源:RdfEntityConverter.php

示例14: extractRawAttributes

 /**
  * Extracts all of the raw attributes from a path for a given route.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route object.
  * @param string $name
  *   The route name.
  * @param string $path
  *   A path.
  *
  * @return array
  *   An array of raw attributes for this path and route.
  */
 public static function extractRawAttributes(Route $route, $name, $path)
 {
     // See \Symfony\Component\Routing\Matcher\UrlMatcher::matchCollection().
     preg_match($route->compile()->getRegex(), $path, $matches);
     // See \Symfony\Component\Routing\Matcher\UrlMatcher::mergeDefaults().
     $attributes = $route->getDefaults();
     foreach ($matches as $key => $value) {
         if (!is_int($key)) {
             $attributes[$key] = $value;
         }
     }
     // See \Symfony\Cmf\Component\Routing\NestedMatcher\UrlMatcher::getAttributes().
     $attributes[RouteObjectInterface::ROUTE_OBJECT] = $route;
     $attributes[RouteObjectInterface::ROUTE_NAME] = $name;
     return $attributes;
 }
开发者ID:neeravbm,项目名称:unify-d8,代码行数:29,代码来源:RouteAttributes.php

示例15: matchRoute

 /**
  * Tries to match a URL with an individual route.
  *
  * @param $pathinfo
  * @param $name
  * @param BaseRoute $route
  * @return array|null
  */
 protected function matchRoute($pathinfo, $name, BaseRoute $route)
 {
     $compiledRoute = $route->compile();
     // check the static prefix of the URL first. Only use the more expensive preg_match when it matches
     if ('' !== $compiledRoute->getStaticPrefix() && 0 !== strpos($pathinfo, $compiledRoute->getStaticPrefix())) {
         return null;
     }
     if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
         return null;
     }
     $hostMatches = array();
     if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
         return null;
     }
     // check HTTP method requirement
     if ($req = $route->getRequirement('_method')) {
         // HEAD and GET are equivalent as per RFC
         if ('HEAD' === ($method = $this->context->getMethod())) {
             $method = 'GET';
         }
         if (!in_array($method, $req = explode('|', strtoupper($req)))) {
             $this->allow = array_merge($this->allow, $req);
             return null;
         }
     }
     $status = $this->handleRouteRequirements($pathinfo, $name, $route);
     if (self::ROUTE_MATCH === $status[0]) {
         return $status[1];
     }
     if (self::REQUIREMENT_MISMATCH === $status[0]) {
         return null;
     }
     $attrs = $this->getAttributes($route, $name, array_replace($matches, $hostMatches));
     if ($route instanceof Route) {
         foreach ($route->getMatchCallbacks() as $callback) {
             $ret = call_user_func($callback, $attrs);
             if ($ret === false) {
                 return null;
             }
             if (is_array($ret)) {
                 $attrs = $ret;
             }
         }
     }
     return $attrs;
 }
开发者ID:mikegibson,项目名称:sentient,代码行数:54,代码来源:UrlMatcher.php


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