本文整理汇总了PHP中HTTPRequest::match方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTPRequest::match方法的具体用法?PHP HTTPRequest::match怎么用?PHP HTTPRequest::match使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPRequest
的用法示例。
在下文中一共展示了HTTPRequest::match方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMatch
function testMatch()
{
$request = new HTTPRequest("GET", "admin/crm/add");
/* When a rule matches, but has no variables, array("_matched" => true) is returned. */
$this->assertEquals(array("_matched" => true), $request->match('admin/crm', true));
/* Becasue we shifted admin/crm off the stack, just "add" should be remaining */
$this->assertEquals("add", $request->remaining());
$this->assertEquals(array("_matched" => true), $request->match('add', true));
}
示例2: handleRequest
public function handleRequest($request) {
self::$is_at_root = true;
$this->pushCurrent();
$this->init();
$controller = new ModelAsController();
$request = new HTTPRequest("GET", self::get_homepage_urlsegment().'/', $request->getVars(), $request->postVars());
$request->match('$URLSegment//$Action', true);
$result = $controller->handleRequest($request);
$this->popCurrent();
return $result;
}
示例3: testFindOldPage
public function testFindOldPage()
{
$page = new Page();
$page->Title = 'Test Page';
$page->URLSegment = 'test-page';
$page->write();
$page->publish('Stage', 'Live');
$page->URLSegment = 'test';
$page->write();
$page->publish('Stage', 'Live');
$router = new ModelAsController();
$request = new HTTPRequest('GET', 'test-page/action/id/otherid');
$request->match('$URLSegment/$Action/$ID/$OtherID');
$response = $router->handleRequest($request);
$this->assertEquals($response->getHeader('Location'), Controller::join_links(Director::baseURL() . 'test/action/id/otherid'));
}
示例4: handleRequest
public function handleRequest($request)
{
self::$is_at_root = true;
$this->pushCurrent();
$this->init();
// If the basic database hasn't been created, then build it.
if (!DB::isActive() || !ClassInfo::hasTable('SiteTree')) {
$this->response = new HTTPResponse();
$this->redirect("dev/build?returnURL=");
return $this->response;
}
$controller = new ModelAsController();
$request = new HTTPRequest("GET", self::get_homepage_urlsegment() . '/', $request->getVars(), $request->postVars());
$request->match('$URLSegment//$Action', true);
$result = $controller->handleRequest($request);
$this->popCurrent();
return $result;
}
示例5: handleRequest
/**
* Handle an HTTP request, defined with a HTTPRequest object.
*
* @return HTTPResponse|string
*/
protected static function handleRequest(HTTPRequest $request, Session $session)
{
krsort(Director::$rules);
if (isset($_REQUEST['debug'])) {
Debug::show(Director::$rules);
}
foreach (Director::$rules as $priority => $rules) {
foreach ($rules as $pattern => $controllerOptions) {
if (is_string($controllerOptions)) {
if (substr($controllerOptions, 0, 2) == '->') {
$controllerOptions = array('Redirect' => substr($controllerOptions, 2));
} else {
$controllerOptions = array('Controller' => $controllerOptions);
}
}
if (($arguments = $request->match($pattern, true)) !== false) {
// controllerOptions provide some default arguments
$arguments = array_merge($controllerOptions, $arguments);
// Find the controller name
if (isset($arguments['Controller'])) {
$controller = $arguments['Controller'];
}
// Pop additional tokens from the tokeniser if necessary
if (isset($controllerOptions['_PopTokeniser'])) {
$request->shift($controllerOptions['_PopTokeniser']);
}
// Handle redirections
if (isset($arguments['Redirect'])) {
return "redirect:" . Director::absoluteURL($arguments['Redirect'], true);
} else {
/*
if(isset($arguments['Action'])) {
$arguments['Action'] = str_replace('-','',$arguments['Action']);
}
if(isset($arguments['Action']) && ClassInfo::exists($controller.'_'.$arguments['Action']))
$controller = $controller.'_'.$arguments['Action'];
*/
if (isset($arguments['URLSegment'])) {
self::$urlSegment = $arguments['URLSegment'] . "/";
}
Director::$urlParams = $arguments;
$controllerObj = new $controller();
$controllerObj->setSession($session);
return $controllerObj->handleRequest($request);
}
}
}
}
}