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


PHP Router::parse方法代码示例

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


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

示例1: match

 /**
  * Compare $url with $mask. Returns true if there is a match !
  *
  * @param  mixed $url   String, array or Request : url to test
  * @param  array  $mask Mask, in a Request::$params form
  * @return bool         Yep/nope ?
  */
 public static function match($url, array $mask)
 {
     // Multiple $url types
     if ($url instanceof Request) {
         $test = Router::parse($url);
     } elseif (is_string($url)) {
         $request = new Request();
         $request->url = $url;
         $test = Router::parse($request);
     } else {
         $test = $url;
     }
     foreach ($mask as $key => $value) {
         if (!isset($test[$key])) {
             return false;
         }
         if (is_array($value) && !static::match($mask[$key], $test[$key])) {
             return false;
         }
         if (is_string($value) && strtolower($value) !== strtolower($test[$key])) {
             return false;
         }
     }
     return true;
 }
开发者ID:scharrier,项目名称:li3_menu,代码行数:32,代码来源:Url.php

示例2: testRouteContinuations

 /**
  * Tests that continuation routes properly fall through and aggregate multiple route parameters.
  */
 public function testRouteContinuations()
 {
     Router::connect('/{:locale:en|de|it|jp}/{:args}', array(), array('continue' => true));
     Router::connect('/{:controller}/{:action}/{:id:[0-9]+}');
     $request = new Request(array('url' => '/en/posts/view/1138'));
     $result = Router::process($request)->params;
     $expected = array('controller' => 'posts', 'action' => 'view', 'id' => '1138', 'locale' => 'en');
     $this->assertEqual($expected, $result);
     $request = new Request(array('url' => '/en/foo/bar/baz'));
     $this->assertNull(Router::parse($request));
     Router::reset();
     Router::connect('/{:args}/{:locale:en|de|it|jp}', array(), array('continue' => true));
     Router::connect('/{:controller}/{:action}/{:id:[0-9]+}');
     $request = new Request(array('url' => '/posts/view/1138/en'));
     $result = Router::process($request)->params;
     $this->assertEqual($expected, $result);
     Router::reset();
     Router::connect('/{:locale:en|de|it|jp}/{:args}', array(), array('continue' => true));
     Router::connect('/', 'Pages::view');
     $request = new Request(array('url' => '/en'));
     $result = Router::process($request)->params;
     $expected = array('locale' => 'en', 'controller' => 'Pages', 'action' => 'view');
     $this->assertEqual($expected, $result);
 }
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:27,代码来源:RouterTest.php

示例3: testResettingRoutes

 /**
  * Tests that routing is fully reset when calling `Router::reset()`.
  *
  * @return void
  */
 public function testResettingRoutes()
 {
     Router::connect('/{:controller}', array('controller' => 'posts'));
     $this->request->url = '/hello';
     $expected = array('controller' => 'hello', 'action' => 'index');
     $result = Router::parse($this->request);
     $this->assertEqual($expected, $result->params);
     Router::reset();
     $this->assertNull(Router::parse($this->request));
 }
开发者ID:WarToaster,项目名称:HangOn,代码行数:15,代码来源:RouterTest.php

示例4: _prepare

 /**
  * Prepare data to display and calculate the current node.
  * @param  array  $menu    The menu description.
  * @param  array  $options Options.
  * @return array           Calulated menu.
  */
 protected function _prepare(array $menu, array $options = array())
 {
     $return = array();
     $active = false;
     $current = array_filter($this->request->params);
     foreach ($menu as $label => $mask) {
         $link = array('url' => null, 'label' => is_string($label) ? $label : null, 'class' => null, 'active' => null, 'mask' => null);
         if (is_string($mask)) {
             $link['url'] = $mask;
         } elseif (array_intersect_key($mask, array('class' => true))) {
             $link = $mask + $link;
         } else {
             $link['url'] = $mask;
         }
         if (!is_string($link['url'])) {
             $link['url'] = Router::match($link['url']);
         }
         if (!$active) {
             if ($link['active']) {
                 // Force the value
                 $link['active'] = 'active';
             } else {
                 if ($link['mask']) {
                     // We have a mask. Easy.
                     $compare = array_filter($link['mask']);
                 } else {
                     // Only do this if we haven't found any active link yet and we haven't any mask to compare !
                     $request = new Request();
                     $request->url = $link['url'];
                     $compare = array_filter(Router::parse($request)->params);
                 }
                 $link['active'] = Url::match($current, $compare) ? 'active' : '';
             }
             $active = !empty($link['active']);
         }
         $return[] = $link;
     }
     return $return;
 }
开发者ID:scharrier,项目名称:li3_menu,代码行数:45,代码来源:Menu.php

示例5: function

<?php

use app\services\OauthWeixinUserService;
use app\extensions\util\HttpUserAgentUtil;
use lithium\action\Response;
use app\services\UserService;
use lithium\net\http\Router;
use lithium\action\Dispatcher;
/**
 * 拦截登录过滤器, 检测页面访问权限.
 */
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
    $router = Router::parse($params['request']);
    if (empty($router->params)) {
        return $chain->next($self, $params, $chain);
    } else {
        $router = $router->params;
    }
    if (UserService::check_auth($router)) {
        // 如果是微信里的页面, 则需要注入当前的微信用户信息
        if (HttpUserAgentUtil::is_weixin()) {
            OauthWeixinUserService::set_current_oauth_user();
        }
        return $chain->next($self, $params, $chain);
    } else {
        $login_url = SYS_PATH . '/user/login?ref_url=' . urldecode(current_url());
        return new Response(array('location' => $login_url));
    }
});
开发者ID:qujian,项目名称:rwe,代码行数:29,代码来源:auth.php


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