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


PHP Route::getPath方法代码示例

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


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

示例1: assignRoute

 /**
  * @param Route $route
  * @return $this
  */
 public function assignRoute(Route $route)
 {
     if (isset($this->_routes[$route->getRouteType()])) {
         if (isset($this->_routes[$route->getRouteType()][$route->getPath()])) {
             throw new \Exception("assigned route path was assigned before");
         }
     }
     // $this->_concatPath($this->_path, $route->getPath()) . PHP_EOL;
     $this->_routes[$route->getRouteType()][$route->getPath()] = $route;
     return $this;
 }
开发者ID:stevleibelt,项目名称:PicoRest,代码行数:15,代码来源:Endpoint.php

示例2: compileRoute

 /**
  * {@inheritDoc}
  *
  * @throws RuntimeException
  */
 protected function compileRoute(Route $route)
 {
     $parameters = $this->processPathParameters($route->getPath());
     $regexp = $route->getPath();
     foreach ($parameters as $parameter) {
         if (substr_count($route->getPath(), '{' . $parameter . '}') > 1) {
             throw new \RuntimeException(sprintf('Route name "%s" cannot reference variable "%s" more than once.', $route->getName(), $parameter));
         }
         $regexp = str_replace('{' . $parameter . '}', '(?<' . $parameter . '>[A-z0-9_-]+)', $regexp);
     }
     $regexp = "#^{$regexp}\$#";
     return ['parameters' => $parameters, 'regexp' => $regexp];
 }
开发者ID:strident,项目名称:router,代码行数:18,代码来源:RouteMatcher.php

示例3: testGetRoutPath

 public function testGetRoutPath()
 {
     $route = new Route();
     $test_path = '/a/path';
     $route->setPath($test_path);
     $this->assertSame($test_path, $route->getPath(), 'Path not set correctly');
 }
开发者ID:neurobashing,项目名称:php-router,代码行数:7,代码来源:RouteTest.php

示例4: getRoutePath

 /**
  * Returns the route path containing the aliases definitions if any given.
  * @param \Brickoo\Component\Routing\Route\Route $route
  * @return string the modified route path containing the aliases
  */
 private function getRoutePath(Route $route)
 {
     $routePath = $route->getPath();
     foreach ($this->aliases as $routeKey => $routeAlias) {
         if (strpos($routePath, $routeKey) !== false) {
             $replacement = sprintf("(%s|%s)", $routeKey, preg_quote($routeAlias, "~"));
             $routePath = str_replace($routeKey, $replacement, $routePath);
             break;
         }
     }
     return $routePath;
 }
开发者ID:brickoo,项目名称:components,代码行数:17,代码来源:RoutePathRegexGenerator.php

示例5: makeRegExp

 /**
  * @param Route $route
  * @return string
  */
 public function makeRegExp(Route $route)
 {
     $regexp = $route->getPath();
     $restrictions = $route->getRestrictions();
     if (preg_match_all('~{(.*)}~Uu', $regexp, $placeholders)) {
         foreach ($placeholders[0] as $index => $match) {
             $name = $placeholders[1][$index];
             $replace = array_key_exists($name, $restrictions) ? $restrictions[$name] : '.*';
             $replace = '(?<' . $name . '>' . $replace . ')';
             $regexp = str_replace($match, $replace, $regexp);
         }
     }
     return $regexp;
 }
开发者ID:alexpts,项目名称:php-routing,代码行数:18,代码来源:RouteService.php

示例6: fetchPlaceholder

 public static function fetchPlaceholder(Route $route, $path)
 {
     $origin = $route->getOrigin();
     $params = self::extractPlaceholder($origin);
     $segments = explode('/', $path);
     $numeric = $params ? array_slice($segments, (int) min($params)) : [];
     foreach ($params as $name => $index) {
         if (isset($segments[$index])) {
             $params[$name] = $segments[$index];
         } else {
             $params[$name] = null;
         }
     }
     $wildcard = $route->getWildcard();
     if (null !== $wildcard) {
         $slice = substr($path, strlen($route->getPath()));
         $slice = array_values(array_filter(explode('/', $slice)));
         $params[$wildcard] = $slice;
     }
     $route->setParams($params + $numeric);
 }
开发者ID:undercloud,项目名称:beacon,代码行数:21,代码来源:Helper.php

示例7: map

 /**
  * Maps the route into routing table
  *
  * @param    Route   $route  A route instance
  * @return   Router  Returns current route instance
  */
 public function map(Route $route)
 {
     list($path, $groupMiddleware) = $this->processed;
     if ($path != '') {
         $route->setPath($path . $route->getPath());
     }
     if (!empty($groupMiddleware)) {
         $route->addMiddleware($groupMiddleware);
     }
     //Appends route to routing table.
     //We are using Trie search data structure.
     $this->routingTable->appendRoute($route);
     if ($route->getName() !== null) {
         //This is the named route
         if (isset($this->namedRoutes[$route->getName()])) {
             throw new \RuntimeException(sprintf("The Route with the name '%s' alredy exists", $route->getName()));
         } else {
             $this->namedRoutes[$route->getName()] = $route;
         }
     }
     return $this;
 }
开发者ID:mheydt,项目名称:scalr,代码行数:28,代码来源:Router.php

示例8: load

 static function load($app_name)
 {
     $apps = self::getAppList();
     if (!isset($apps[$app_name])) {
         return;
     }
     $app_dir = $apps[$app_name];
     self::$activeAppName = strtolower($app_name);
     self::$activeAppDir = $app_dir;
     $route_file_name = String::glue($app_dir, DS, APP_CONFIG_DIR, DS, 'route.php');
     if (php_sapi_name() != 'cli') {
         try {
             Route::setActive(Route::getPath(), file_exists($route_file_name) ? include $route_file_name : array(), true);
         } catch (Exception $e) {
             self::parseError($e, $app_name);
         }
     }
     self::setDefaultParams();
     // Abort this code, but later
     if (!Auth::loged() && Core::isSecure(Request::get('module')) && Request::get('module') != 'login' && false) {
         if (php_sapi_name() == 'cli') {
             echo 'Auth Error';
             exit;
         }
         Request::redirect('/login/' . (Request::get(Route::$path) ? '&return=' . Request::get(Route::$path) : ''));
     }
     //
     Settings::load('core', CORE_CONFIG_DIR . DS);
     self::loadDependences($app_dir);
     Settings::load($app_name);
     App::startApp($app_name);
     try {
         Load::Action($app_dir . DS, Request::get('action'));
     } catch (Exception $e) {
         self::parseError($e, $app_name);
     }
     App::endApp($app_name);
     Language::translate(Language::getActiveLanguageISO());
 }
开发者ID:Yogurt933,项目名称:Made-Easy,代码行数:39,代码来源:App.class.php

示例9: route

 /**
  * Evaluates all routes from the controller. The first found
  * route is executed. If this route does *not* return false,
  * the script is exited.
  * @return void
  */
 public function route()
 {
     foreach ($this->routes as $preg => $method) {
         $matches = null;
         if (preg_match($preg, Route::getPath(), $matches)) {
             $result = null;
             if (is_array($method)) {
                 $requestType = strtolower($_SERVER['REQUEST_METHOD']);
                 if (array_key_exists($requestType, $method)) {
                     $func = $method[$requestType];
                     if (is_callable($func)) {
                         $result = $func($matches);
                     } else {
                         $result = $this->{$func}($matches);
                     }
                 }
             } elseif (is_callable($method)) {
                 $result = $method($matches);
             } else {
                 $result = $this->{$method}($matches);
             }
             if ($result !== false) {
                 exit;
             }
         }
     }
 }
开发者ID:michielvaneerd,项目名称:phpmicrolib,代码行数:33,代码来源:router.inc.php

示例10: addStaticRoute

 /**
  *
  */
 private function addStaticRoute($routeData, Route $route)
 {
     $handler = $route->getHandler();
     $routeStr = $routeData[0];
     foreach ($route->getMethod() as $method) {
         if (isset($this->staticRoutes[$method][$routeStr])) {
             throw new Exception("Cannot register two routes matching \"{$routeStr}\" for method \"{$method}\"");
         }
         if (isset($this->dynamicRoutes[$method])) {
             foreach ($this->dynamicRoutes[$method] as $route) {
                 if ($route->matches($routeStr)) {
                     throw new Exception("Static route \"{$routeStr}\" is shadowed by previously defined variable route \"{$route->getPath()}\" for method \"{$method}\"");
                 }
             }
         }
         $this->staticRoutes[$method][$routeStr] = $handler;
     }
 }
开发者ID:wispira,项目名称:framework,代码行数:21,代码来源:Router.php

示例11: testGetPath

 public function testGetPath()
 {
     $this->assertSame('/foo', $this->route->getPath());
 }
开发者ID:tonis-io,项目名称:tonis,代码行数:4,代码来源:RouteTest.php

示例12: pullVariables

 /**
  * Pull the variables out of a path given the actual path and the
  * path that is is representing.
  * @param string $pathToMatch The path that is being matched.
  * @param Route $route The route to use.
  * @return array
  */
 private static function pullVariables($pathToMatch, Route $route)
 {
     $rtn = array();
     $pathToMatch = self::fixPath($pathToMatch);
     $nameMatches = array();
     $valueMatches = array();
     preg_match_all(self::IDENT_PREG, $route->getPath(), $nameMatches, PREG_PATTERN_ORDER);
     preg_match_all($route->getRegexPath(), $pathToMatch, $valueMatches, PREG_PATTERN_ORDER);
     for ($i = 0; $i < count($nameMatches[1]); $i++) {
         $value = $valueMatches[$i + 1][0];
         $rtn = array_merge($rtn, array($nameMatches[1][$i] => $value));
     }
     return $rtn;
 }
开发者ID:brandonfrancis,项目名称:scsapi,代码行数:21,代码来源:routing.php

示例13: setGetData

 /**
  * @param Route $route Route object matching rules
  */
 protected function setGetData($route)
 {
     $routePath = str_replace(array('(', ')'), array('', ''), $route->getPath());
     $trim = explode('<', $routePath);
     $parsed_url = str_replace(array($this->basePath), array(''), $this->url);
     $parsed_url = preg_replace("#{$trim['0']}#", '', $parsed_url, 1);
     // sets the parameters passed in the URL
     foreach ($route->getParams() as $key => $param) {
         preg_match("#{$param}#", $parsed_url, $results);
         if (isset($results[0])) {
             $_GET[$key] = $results[0];
             $parsed_url = str_replace($results[0], '', $parsed_url);
         }
     }
     // if no parameter in the URL, it sets the default values from the table
     foreach ($route->getDefaults() as $key => $default) {
         if (!isset($_GET[$key])) {
             $_GET[$key] = $default;
         }
     }
 }
开发者ID:pawelbienko,项目名称:rest-without-framework,代码行数:24,代码来源:Router.php

示例14: appendRoute

 /**
  * Appends route to routing table
  *
  * @param    Route   $route     The route object
  * @param    array   $parts     optional The list of the parts in the route path
  * @return   Item    Returns the terminal item which contains the route
  */
 public function appendRoute(Route $route, array &$parts = null)
 {
     if ($parts === null) {
         $parts = explode('/', trim($route->getPath(), '/'));
     }
     $part = array_shift($parts);
     $pathPart = new PathPart($part);
     if (strpos($part, ':') !== false) {
         //This is regexp part
         $pathPart->type = PathPart::TYPE_REGEXP;
         $pathPart->value = '~^' . preg_replace_callback('~:([\\w]+)\\+?~', function ($m) use($route, $pathPart) {
             $requirements = $route->getRequirements();
             if (isset($requirements[$m[1]])) {
                 return '(?<' . $m[1] . '>' . $requirements[$m[1]] . ')';
             }
             if (substr($m[0], -1) === '+') {
                 $pathPart->type = PathPart::TYPE_REGEXP_PATH;
                 return '(?<' . $m[1] . '>.+)';
             }
             return '(?<' . $m[1] . '>[^/]+)';
         }, str_replace(')', ')?', $part)) . '$~';
     }
     if (!$this->offsetExists($pathPart->value)) {
         /* @var $item Item */
         $item = new Item($pathPart);
         $this[$pathPart->value] = $item;
     } else {
         $item = $this[$pathPart->value];
     }
     if (empty($parts)) {
         //This is the terminal item
         if (!in_array($route, $item->routes)) {
             $item->routes[] = $route;
         }
         return $item;
     }
     return $item->getTable()->appendRoute($route, $parts);
 }
开发者ID:mheydt,项目名称:scalr,代码行数:45,代码来源:Table.php

示例15: testSetPath

 public function testSetPath()
 {
     $route = new Route("/");
     $route->setPath("/home");
     $this->assertEquals("/home", $route->getPath());
 }
开发者ID:sugiphp,项目名称:routing,代码行数:6,代码来源:RouteTest.php


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