mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API: Replace Director::direct() with Director::handleRequest().
There was no longer any code in direct() and so I opted to expose the handleRequest() method instead.
This commit is contained in:
parent
72a7655e95
commit
10866c0809
@ -16,13 +16,13 @@ use SilverStripe\View\TemplateGlobalProvider;
|
||||
/**
|
||||
* Director is responsible for processing URLs, and providing environment information.
|
||||
*
|
||||
* The most important part of director is {@link Director::direct()}, which is passed a URL and will
|
||||
* The most important part of director is {@link Director::handleRequest()}, which is passed an HTTPRequest and will
|
||||
* execute the appropriate controller.
|
||||
*
|
||||
* Director also has a number of static methods that provide information about the environment, such as
|
||||
* {@link Director::$environment_type}.
|
||||
*
|
||||
* @see Director::direct()
|
||||
* @see Director::handleRequest()
|
||||
* @see Director::$rules
|
||||
* @see Director::$environment_type
|
||||
*/
|
||||
@ -100,40 +100,10 @@ class Director implements TemplateGlobalProvider
|
||||
protected static $environment_type;
|
||||
|
||||
/**
|
||||
* Process the given URL, creating the appropriate controller and executing it.
|
||||
*
|
||||
* Request processing is handled as follows:
|
||||
* - Director::direct() creates a new HTTPResponse object and passes this to
|
||||
* Director::handleRequest().
|
||||
* - Director::handleRequest($request) checks each of the Director rules and identifies a controller
|
||||
* to handle this request.
|
||||
* - Controller::handleRequest($request) is then called. This will find a rule to handle the URL,
|
||||
* and call the rule handling method.
|
||||
* - RequestHandler::handleRequest($request) is recursively called whenever a rule handling method
|
||||
* returns a RequestHandler object.
|
||||
*
|
||||
* In addition to request processing, Director will manage the session, and perform the output of
|
||||
* the actual response to the browser.
|
||||
*
|
||||
* @uses handleRequest() rule-lookup logic is handled by this.
|
||||
* @uses TestController::handleRequest() This handles the page logic for a Director::direct() call.
|
||||
* @param HTTPRequest $request
|
||||
* @return HTTPResponse
|
||||
* @throws HTTPResponse_Exception
|
||||
*/
|
||||
public static function direct(HTTPRequest $request)
|
||||
{
|
||||
// Generate output
|
||||
return static::handleRequest($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a URL request, returning a response object. This method is the counterpart of
|
||||
* Director::direct() that is used in functional testing. It will execute the URL given, and
|
||||
* Test a URL request, returning a response object. This method is a wrapper around
|
||||
* Director::handleRequest() to assist with functional testing. It will execute the URL given, and
|
||||
* return the result as an HTTPResponse object.
|
||||
*
|
||||
* @uses TestController::handleRequest() Handles the page logic for a Director::direct() call.
|
||||
*
|
||||
* @param string $url The URL to visit.
|
||||
* @param array $postVars The $_POST & $_FILES variables.
|
||||
* @param array|Session $session The {@link Session} object representing the current session.
|
||||
@ -162,7 +132,7 @@ class Director implements TemplateGlobalProvider
|
||||
) {
|
||||
return static::mockRequest(
|
||||
function (HTTPRequest $request) {
|
||||
return static::direct($request);
|
||||
return static::handleRequest($request);
|
||||
},
|
||||
$url,
|
||||
$postVars,
|
||||
@ -315,13 +285,24 @@ class Director implements TemplateGlobalProvider
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an HTTP request, defined with a HTTPRequest object.
|
||||
* Process the given URL, creating the appropriate controller and executing it.
|
||||
*
|
||||
* Request processing is handled as follows:
|
||||
* - Director::handleRequest($request) checks each of the Director rules and identifies a controller
|
||||
* to handle this request.
|
||||
* - Controller::handleRequest($request) is then called. This will find a rule to handle the URL,
|
||||
* and call the rule handling method.
|
||||
* - RequestHandler::handleRequest($request) is recursively called whenever a rule handling method
|
||||
* returns a RequestHandler object.
|
||||
*
|
||||
* In addition to request processing, Director will manage the session, and perform the output of
|
||||
* the actual response to the browser.
|
||||
*
|
||||
* @skipUpgrade
|
||||
* @param HTTPRequest $request
|
||||
* @return HTTPResponse
|
||||
* @throws HTTPResponse_Exception
|
||||
*/
|
||||
protected static function handleRequest(HTTPRequest $request)
|
||||
public static function handleRequest(HTTPRequest $request)
|
||||
{
|
||||
$rules = Director::config()->uninherited('rules');
|
||||
|
||||
|
@ -96,7 +96,7 @@ class HTTPApplication implements Application
|
||||
|
||||
// Ensure boot is invoked
|
||||
return $this->execute($request, function (HTTPRequest $request) {
|
||||
return Director::direct($request);
|
||||
return Director::handleRequest($request);
|
||||
}, $flush);
|
||||
}
|
||||
|
||||
|
@ -846,7 +846,7 @@ class HTTPRequest implements ArrayAccess
|
||||
* Using GET for the "_method" override is not supported,
|
||||
* as GET should never carry out state changes.
|
||||
* Alternatively you can use a custom HTTP header 'X-HTTP-Method-Override'
|
||||
* to override the original method in {@link Director::direct()}.
|
||||
* to override the original method.
|
||||
* The '_method' POST parameter overrules the custom HTTP header.
|
||||
*
|
||||
* @param string $origMethod Original HTTP method from the browser request
|
||||
@ -857,7 +857,7 @@ class HTTPRequest implements ArrayAccess
|
||||
{
|
||||
if (isset($postVars['_method'])) {
|
||||
if (!in_array(strtoupper($postVars['_method']), array('GET','POST','PUT','DELETE','HEAD'))) {
|
||||
user_error('Director::direct(): Invalid "_method" parameter', E_USER_ERROR);
|
||||
user_error('HTTPRequest::detect_method(): Invalid "_method" parameter', E_USER_ERROR);
|
||||
}
|
||||
return strtoupper($postVars['_method']);
|
||||
} else {
|
||||
|
@ -1032,7 +1032,7 @@ class Form extends ViewableData implements HasRequestHandler
|
||||
* As most browsers only support GET and POST in
|
||||
* form submissions, all other HTTP methods are
|
||||
* added as a hidden field "_method" that
|
||||
* gets evaluated in {@link Director::direct()}.
|
||||
* gets evaluated in {@link HTTPRequest::detect_method()}.
|
||||
* See {@link FormMethod()} to get a HTTP method
|
||||
* for safe insertion into a <form> tag.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user