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


PHP Helper::segmentizeUrl方法代码示例

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


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

示例1: run

 /**
  * Finds and serves the requested backend controller.
  * If the controller cannot be found, returns the Cms page with the URL /404.
  * If the /404 page doesn't exist, returns the system 404 page.
  * @param string $url Specifies the requested page URL.
  * If the parameter is omitted, the current URL used.
  * @return string Returns the processed page content.
  */
 public function run($url = null)
 {
     $params = RouterHelper::segmentizeUrl($url);
     /*
      * Look for a Module controller
      */
     $module = isset($params[0]) ? $params[0] : 'backend';
     $controller = isset($params[1]) ? $params[1] : 'index';
     self::$action = $action = isset($params[2]) ? $this->parseAction($params[2]) : 'index';
     self::$params = $controllerParams = array_slice($params, 3);
     $controllerClass = '\\' . $module . '\\Controllers\\' . $controller;
     if ($controllerObj = $this->findController($controllerClass, $action, base_path() . '/modules')) {
         return $controllerObj->run($action, $controllerParams);
     }
     /*
      * Look for a Plugin controller
      */
     if (count($params) >= 2) {
         list($author, $plugin) = $params;
         $controller = isset($params[2]) ? $params[2] : 'index';
         self::$action = $action = isset($params[3]) ? $this->parseAction($params[3]) : 'index';
         self::$params = $controllerParams = array_slice($params, 4);
         $controllerClass = '\\' . $author . '\\' . $plugin . '\\Controllers\\' . $controller;
         if ($controllerObj = $this->findController($controllerClass, $action, plugins_path())) {
             return $controllerObj->run($action, $controllerParams);
         }
     }
     /*
      * Fall back on Cms controller
      */
     return App::make('Cms\\Classes\\Controller')->run($url);
 }
开发者ID:janusnic,项目名称:23copperleaf,代码行数:40,代码来源:BackendController.php

示例2: resolveUrl

 /**
  * Checks whether a given URL matches a given pattern.
  * @param string $url The URL to check.
  * @param array $parameters A reference to a PHP array variable to return the parameter list fetched from URL.
  * @return boolean Returns true if the URL matches the pattern. Otherwise returns false.
  */
 public function resolveUrl($url, &$parameters)
 {
     $parameters = [];
     $patternSegments = $this->segments;
     $patternSegmentNum = count($patternSegments);
     $urlSegments = Helper::segmentizeUrl($url);
     /*
      * Only one wildcard can be used, if found, pull out the excess segments
      */
     if ($this->wildSegmentCount === 1) {
         $wildSegments = $this->captureWildcardSegments($urlSegments);
     }
     /*
      * If the number of URL segments is more than the number of pattern segments - return false
      */
     if (count($urlSegments) > count($patternSegments)) {
         return false;
     }
     /*
      * Compare pattern and URL segments
      */
     foreach ($patternSegments as $index => $patternSegment) {
         $patternSegmentLower = mb_strtolower($patternSegment);
         if (strpos($patternSegment, ':') !== 0) {
             /*
              * Static segment
              */
             if (!array_key_exists($index, $urlSegments) || $patternSegmentLower != mb_strtolower($urlSegments[$index])) {
                 return false;
             }
         } else {
             /*
              * Dynamic segment. Initialize the parameter
              */
             $paramName = Helper::getParameterName($patternSegment);
             $parameters[$paramName] = false;
             /*
              * Determine whether it is optional
              */
             $optional = Helper::segmentIsOptional($patternSegment);
             /*
              * Check if the optional segment has no required segments following it
              */
             if ($optional && $index < $patternSegmentNum - 1) {
                 for ($i = $index + 1; $i < $patternSegmentNum; $i++) {
                     if (!Helper::segmentIsOptional($patternSegments[$i])) {
                         $optional = false;
                         break;
                     }
                 }
             }
             /*
              * If the segment is optional and there is no corresponding value in the URL, assign the default value (if provided)
              * and skip to the next segment.
              */
             $urlSegmentExists = array_key_exists($index, $urlSegments);
             if ($optional && !$urlSegmentExists) {
                 $parameters[$paramName] = Helper::getSegmentDefaultValue($patternSegment);
                 continue;
             }
             /*
              * If the segment is not optional and there is no corresponding value in the URL, return false
              */
             if (!$optional && !$urlSegmentExists) {
                 return false;
             }
             /*
              * Validate the value with the regular expression
              */
             $regexp = Helper::getSegmentRegExp($patternSegment);
             if ($regexp) {
                 try {
                     if (!preg_match($regexp, $urlSegments[$index])) {
                         return false;
                     }
                 } catch (\Exception $ex) {
                 }
             }
             /*
              * Set the parameter value
              */
             $parameters[$paramName] = $urlSegments[$index];
             /*
              * Determine if wildcard and add stored paramters as a suffix
              */
             if (Helper::segmentIsWildcard($patternSegment) && count($wildSegments)) {
                 $parameters[$paramName] .= Helper::rebuildUrl($wildSegments);
             }
         }
     }
     return true;
 }
开发者ID:betes-curieuses-design,项目名称:ElieJosiePhotographie,代码行数:98,代码来源:Rule.php


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