2008-08-09 05:19:54 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class is the base class of any Sapphire object that can be used to handle HTTP requests.
|
|
|
|
*
|
2008-10-30 23:03:21 +01:00
|
|
|
* Any RequestHandler object can be made responsible for handling its own segment of the URL namespace.
|
2008-08-09 05:19:54 +02:00
|
|
|
* The {@link Director} begins the URL parsing process; it will parse the beginning of the URL to identify which
|
2008-10-06 00:16:07 +02:00
|
|
|
* controller is being used. It will then call {@link handleRequest()} on that Controller, passing it the parameters that it
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
* parsed from the URL, and the {@link SS_HTTPRequest} that contains the remainder of the URL to be parsed.
|
2008-10-06 00:16:07 +02:00
|
|
|
*
|
|
|
|
* You can use ?debug_request=1 to view information about the different components and rule matches for a specific URL.
|
2008-08-09 05:19:54 +02:00
|
|
|
*
|
|
|
|
* In Sapphire, URL parsing is distributed throughout the object graph. For example, suppose that we have a search form
|
2008-10-06 00:16:07 +02:00
|
|
|
* that contains a {@link TreeMultiSelectField} named "Groups". We want to use ajax to load segments of this tree as they are needed
|
2008-08-09 05:19:54 +02:00
|
|
|
* rather than downloading the tree right at the beginning. We could use this URL to get the tree segment that appears underneath
|
2008-10-06 00:16:07 +02:00
|
|
|
* Group #36: "admin/crm/SearchForm/field/Groups/treesegment/36"
|
2008-08-09 05:19:54 +02:00
|
|
|
* - Director will determine that admin/crm is controlled by a new ModelAdmin object, and pass control to that.
|
2008-10-06 00:16:07 +02:00
|
|
|
* Matching Director Rule: "admin/crm" => "ModelAdmin" (defined in mysite/_config.php)
|
2008-08-09 05:19:54 +02:00
|
|
|
* - ModelAdmin will determine that SearchForm is controlled by a Form object returned by $this->SearchForm(), and pass control to that.
|
2008-10-30 23:03:21 +01:00
|
|
|
* Matching $url_handlers: "$Action" => "$Action" (defined in RequestHandler class)
|
2008-10-06 00:16:07 +02:00
|
|
|
* - Form will determine that field/Groups is controlled by the Groups field, a TreeMultiselectField, and pass control to that.
|
|
|
|
* Matching $url_handlers: 'field/$FieldName!' => 'handleField' (defined in Form class)
|
2008-08-09 05:19:54 +02:00
|
|
|
* - TreeMultiselectField will determine that treesegment/36 is handled by its treesegment() method. This method will return an HTML fragment that is output to the screen.
|
2008-10-06 00:16:07 +02:00
|
|
|
* Matching $url_handlers: "$Action/$ID" => "handleItem" (defined in TreeMultiSelectField class)
|
2008-08-09 05:19:54 +02:00
|
|
|
*
|
2008-10-30 23:03:21 +01:00
|
|
|
* {@link RequestHandler::handleRequest()} is where this behaviour is implemented.
|
2009-03-22 23:59:14 +01:00
|
|
|
*
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage control
|
2008-08-09 05:19:54 +02:00
|
|
|
*/
|
2008-10-30 23:03:21 +01:00
|
|
|
class RequestHandler extends ViewableData {
|
2008-08-09 05:54:55 +02:00
|
|
|
protected $request = null;
|
|
|
|
|
2009-04-29 09:28:53 +02:00
|
|
|
/**
|
|
|
|
* This variable records whether RequestHandler::__construct()
|
|
|
|
* was called or not. Useful for checking if subclasses have
|
|
|
|
* called parent::__construct()
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
protected $brokenOnConstruct = true;
|
|
|
|
|
2008-08-09 05:19:54 +02:00
|
|
|
/**
|
|
|
|
* The default URL handling rules. This specifies that the next component of the URL corresponds to a method to
|
|
|
|
* be called on this RequestHandlingData object.
|
|
|
|
*
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
* The keys of this array are parse rules. See {@link SS_HTTPRequest::match()} for a description of the rules available.
|
2008-08-09 05:19:54 +02:00
|
|
|
*
|
|
|
|
* The values of the array are the method to be called if the rule matches. If this value starts with a '$', then the
|
|
|
|
* named parameter of the parsed URL wil be used to determine the method name.
|
|
|
|
*/
|
|
|
|
static $url_handlers = array(
|
|
|
|
'$Action' => '$Action',
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Define a list of action handling methods that are allowed to be called directly by URLs.
|
|
|
|
* The variable should be an array of action names. This sample shows the different values that it can contain:
|
|
|
|
*
|
|
|
|
* <code>
|
|
|
|
* array(
|
|
|
|
* 'someaction', // someaction can be accessed by anyone, any time
|
|
|
|
* 'otheraction' => true, // So can otheraction
|
|
|
|
* 'restrictedaction' => 'ADMIN', // restrictedaction can only be people with ADMIN privilege
|
|
|
|
* 'complexaction' '->canComplexAction' // complexaction can only be accessed if $this->canComplexAction() returns true
|
|
|
|
* );
|
|
|
|
* </code>
|
|
|
|
*/
|
|
|
|
static $allowed_actions = null;
|
2009-04-29 09:28:53 +02:00
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$this->brokenOnConstruct = false;
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
2008-08-09 05:19:54 +02:00
|
|
|
/**
|
|
|
|
* Handles URL requests.
|
|
|
|
*
|
|
|
|
* - ViewableData::handleRequest() iterates through each rule in {@link self::$url_handlers}.
|
|
|
|
* - If the rule matches, the named method will be called.
|
2009-09-07 02:14:11 +02:00
|
|
|
* - If there is still more URL to be processed, then handleRequest()
|
|
|
|
* is called on the object that that method returns.
|
2008-08-09 05:19:54 +02:00
|
|
|
*
|
2009-09-07 02:14:11 +02:00
|
|
|
* Once all of the URL has been processed, the final result is returned.
|
|
|
|
* However, if the final result is an array, this
|
|
|
|
* array is interpreted as being additional template data to customise the
|
|
|
|
* 2nd to last result with, rather than an object
|
|
|
|
* in its own right. This is most frequently used when a Controller's
|
|
|
|
* action will return an array of data with which to
|
2008-08-09 05:19:54 +02:00
|
|
|
* customise the controller.
|
|
|
|
*
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
* @param $request The {@link SS_HTTPRequest} object that is reponsible for distributing URL parsing
|
|
|
|
* @uses SS_HTTPRequest
|
|
|
|
* @uses SS_HTTPRequest->match()
|
|
|
|
* @return SS_HTTPResponse|RequestHandler|string|array
|
2008-08-09 05:19:54 +02:00
|
|
|
*/
|
2010-10-04 06:20:49 +02:00
|
|
|
function handleRequest(SS_HTTPRequest $request) {
|
2008-10-30 23:28:01 +01:00
|
|
|
// $handlerClass is used to step up the class hierarchy to implement url_handlers inheritance
|
2008-11-05 02:59:27 +01:00
|
|
|
$handlerClass = ($this->class) ? $this->class : get_class($this);
|
2009-04-29 09:28:53 +02:00
|
|
|
|
|
|
|
if($this->brokenOnConstruct) {
|
|
|
|
user_error("parent::__construct() needs to be called on {$handlerClass}::__construct()", E_USER_WARNING);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->request = $request;
|
|
|
|
|
2008-10-30 23:28:01 +01:00
|
|
|
// We stop after RequestHandler; in other words, at ViewableData
|
2008-11-05 02:59:27 +01:00
|
|
|
while($handlerClass && $handlerClass != 'ViewableData') {
|
2009-03-21 06:10:05 +01:00
|
|
|
$urlHandlers = Object::get_static($handlerClass, 'url_handlers');
|
2008-10-30 23:28:01 +01:00
|
|
|
|
|
|
|
if($urlHandlers) foreach($urlHandlers as $rule => $action) {
|
|
|
|
if(isset($_REQUEST['debug_request'])) Debug::message("Testing '$rule' with '" . $request->remaining() . "' on $this->class");
|
|
|
|
if($params = $request->match($rule, true)) {
|
2010-10-15 04:53:11 +02:00
|
|
|
// Backwards compatible setting of url parameters, please use SS_HTTPRequest->latestParam() instead
|
2010-10-15 04:53:31 +02:00
|
|
|
//Director::setUrlParams($request->latestParams());
|
2008-08-15 00:20:32 +02:00
|
|
|
|
2008-10-30 23:28:01 +01:00
|
|
|
if(isset($_REQUEST['debug_request'])) {
|
|
|
|
Debug::message("Rule '$rule' matched to action '$action' on $this->class. Latest request params: " . var_export($request->latestParams(), true));
|
|
|
|
}
|
2008-08-09 05:19:54 +02:00
|
|
|
|
2008-10-30 23:28:01 +01:00
|
|
|
// Actions can reference URL parameters, eg, '$Action/$ID/$OtherID' => '$Action',
|
|
|
|
if($action[0] == '$') $action = $params[substr($action,1)];
|
2008-08-09 05:19:54 +02:00
|
|
|
|
2008-10-30 23:28:01 +01:00
|
|
|
if($this->checkAccessAction($action)) {
|
|
|
|
if(!$action) {
|
|
|
|
if(isset($_REQUEST['debug_request'])) Debug::message("Action not set; using default action method name 'index'");
|
|
|
|
$action = "index";
|
|
|
|
} else if(!is_string($action)) {
|
|
|
|
user_error("Non-string method name: " . var_export($action, true), E_USER_ERROR);
|
2009-06-27 10:48:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$result = $this->$action($request);
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
} catch(SS_HTTPResponse_Exception $responseException) {
|
2009-06-27 10:48:44 +02:00
|
|
|
$result = $responseException->getResponse();
|
|
|
|
}
|
2008-10-30 23:28:01 +01:00
|
|
|
} else {
|
|
|
|
return $this->httpError(403, "Action '$action' isn't allowed on class $this->class");
|
|
|
|
}
|
2008-08-09 05:19:54 +02:00
|
|
|
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
if($result instanceof SS_HTTPResponse && $result->isError()) {
|
2008-10-30 23:28:01 +01:00
|
|
|
if(isset($_REQUEST['debug_request'])) Debug::message("Rule resulted in HTTP error; breaking");
|
|
|
|
return $result;
|
|
|
|
}
|
2008-08-11 02:03:57 +02:00
|
|
|
|
2008-10-30 23:28:01 +01:00
|
|
|
// If we return a RequestHandler, call handleRequest() on that, even if there is no more URL to parse.
|
2010-10-13 03:24:53 +02:00
|
|
|
// It might have its own handler. However, we only do this if we haven't just parsed an empty rule ourselves,
|
|
|
|
// to prevent infinite loops. Also prevent further handling of controller actions which return themselves
|
|
|
|
// to avoid infinite loops.
|
|
|
|
if($this !== $result && !$request->isEmptyPattern($rule) && is_object($result) && $result instanceof RequestHandler) {
|
2008-10-30 23:28:01 +01:00
|
|
|
$returnValue = $result->handleRequest($request);
|
2008-08-09 05:19:54 +02:00
|
|
|
|
2008-10-30 23:28:01 +01:00
|
|
|
// Array results can be used to handle
|
|
|
|
if(is_array($returnValue)) $returnValue = $this->customise($returnValue);
|
2008-08-09 05:19:54 +02:00
|
|
|
|
2008-10-30 23:28:01 +01:00
|
|
|
return $returnValue;
|
2008-08-09 05:19:54 +02:00
|
|
|
|
2008-10-30 23:28:01 +01:00
|
|
|
// If we return some other data, and all the URL is parsed, then return that
|
|
|
|
} else if($request->allParsed()) {
|
|
|
|
return $result;
|
2008-08-09 05:19:54 +02:00
|
|
|
|
2008-10-30 23:28:01 +01:00
|
|
|
// But if we have more content on the URL and we don't know what to do with it, return an error.
|
|
|
|
} else {
|
2009-04-29 03:20:24 +02:00
|
|
|
return $this->httpError(404, "I can't handle sub-URLs of a $this->class object.");
|
2008-10-30 23:28:01 +01:00
|
|
|
}
|
2008-08-09 05:19:54 +02:00
|
|
|
|
2008-10-30 23:28:01 +01:00
|
|
|
return $this;
|
|
|
|
}
|
2008-08-09 05:19:54 +02:00
|
|
|
}
|
2008-10-30 23:28:01 +01:00
|
|
|
|
|
|
|
$handlerClass = get_parent_class($handlerClass);
|
2008-08-09 05:19:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// If nothing matches, return this object
|
|
|
|
return $this;
|
|
|
|
}
|
2009-03-21 06:10:05 +01:00
|
|
|
|
2009-10-11 02:07:26 +02:00
|
|
|
/**
|
|
|
|
* Get a unified array of allowed actions on this controller (if such data is available) from both the controller
|
|
|
|
* ancestry and any extensions.
|
|
|
|
*
|
|
|
|
* @return array|null
|
|
|
|
*/
|
|
|
|
public function allowedActions() {
|
|
|
|
$actions = Object::combined_static(get_class($this), 'allowed_actions', 'RequestHandler');
|
|
|
|
|
|
|
|
foreach($this->extension_instances as $extension) {
|
|
|
|
if($extensionActions = Object::get_static(get_class($extension), 'allowed_actions')) {
|
|
|
|
$actions = array_merge($actions, $extensionActions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($actions) {
|
2009-10-15 23:50:02 +02:00
|
|
|
// convert all keys and values to lowercase to
|
|
|
|
// allow for easier comparison, unless it is a permission code
|
|
|
|
$actions = array_change_key_case($actions, CASE_LOWER);
|
2009-10-11 02:07:26 +02:00
|
|
|
|
|
|
|
foreach($actions as $key => $value) {
|
|
|
|
if(is_numeric($key)) $actions[$key] = strtolower($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $actions;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-11 02:07:23 +02:00
|
|
|
/**
|
|
|
|
* Checks if this request handler has a specific action (even if the current user cannot access it).
|
|
|
|
*
|
|
|
|
* @param string $action
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasAction($action) {
|
|
|
|
if($action == 'index') return true;
|
|
|
|
|
|
|
|
$action = strtolower($action);
|
2009-10-11 02:07:26 +02:00
|
|
|
$actions = $this->allowedActions();
|
2009-10-11 02:07:23 +02:00
|
|
|
|
2010-10-13 05:30:54 +02:00
|
|
|
// Check if the action is defined in the allowed actions as either a
|
|
|
|
// key or value. Note that if the action is numeric, then keys are not
|
|
|
|
// searched for actions to prevent actual array keys being recognised
|
|
|
|
// as actions.
|
2009-10-11 02:07:23 +02:00
|
|
|
if(is_array($actions)) {
|
2010-10-13 05:30:54 +02:00
|
|
|
$isKey = !is_numeric($action) && array_key_exists($action, $actions);
|
|
|
|
$isValue = in_array($action, $actions);
|
|
|
|
|
|
|
|
if($isKey || $isValue) return true;
|
2009-10-11 02:07:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!is_array($actions) || !$this->uninherited('allowed_actions')) {
|
|
|
|
if($action != 'init' && $action != 'run' && method_exists($this, $action)) return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-08-09 05:19:54 +02:00
|
|
|
/**
|
|
|
|
* Check that the given action is allowed to be called from a URL.
|
|
|
|
* It will interrogate {@link self::$allowed_actions} to determine this.
|
|
|
|
*/
|
|
|
|
function checkAccessAction($action) {
|
2010-10-13 03:24:15 +02:00
|
|
|
$actionOrigCasing = $action;
|
2009-03-21 06:10:05 +01:00
|
|
|
$action = strtolower($action);
|
2009-10-11 02:07:26 +02:00
|
|
|
$allowedActions = $this->allowedActions();
|
2009-10-11 07:16:18 +02:00
|
|
|
|
2009-03-21 06:10:05 +01:00
|
|
|
if($allowedActions) {
|
2009-04-02 18:34:27 +02:00
|
|
|
// check for specific action rules first, and fall back to global rules defined by asterisk
|
|
|
|
foreach(array($action,'*') as $actionOrAll) {
|
|
|
|
// check if specific action is set
|
|
|
|
if(isset($allowedActions[$actionOrAll])) {
|
|
|
|
$test = $allowedActions[$actionOrAll];
|
2009-07-16 05:44:15 +02:00
|
|
|
if($test === true || $test === 1 || $test === '1') {
|
2009-04-02 18:34:27 +02:00
|
|
|
// Case 1: TRUE should always allow access
|
|
|
|
return true;
|
|
|
|
} elseif(substr($test, 0, 2) == '->') {
|
|
|
|
// Case 2: Determined by custom method with "->" prefix
|
|
|
|
return $this->{substr($test, 2)}();
|
2009-10-11 11:15:51 +02:00
|
|
|
} else {
|
2009-04-02 18:34:27 +02:00
|
|
|
// Case 3: Value is a permission code to check the current member against
|
2009-10-11 11:15:51 +02:00
|
|
|
return Permission::check($test);
|
2009-04-02 18:34:27 +02:00
|
|
|
}
|
2009-10-11 11:15:51 +02:00
|
|
|
|
2009-04-02 18:34:27 +02:00
|
|
|
} elseif((($key = array_search($actionOrAll, $allowedActions)) !== false) && is_numeric($key)) {
|
|
|
|
// Case 4: Allow numeric array notation (search for array value as action instead of key)
|
2009-03-21 06:10:05 +01:00
|
|
|
return true;
|
2008-10-31 03:16:25 +01:00
|
|
|
}
|
2008-08-09 05:19:54 +02:00
|
|
|
}
|
|
|
|
}
|
2009-03-21 06:10:05 +01:00
|
|
|
|
2009-10-11 11:15:51 +02:00
|
|
|
// If we get here an the action is 'index', then it hasn't been specified, which means that
|
|
|
|
// it should be allowed.
|
2010-10-13 03:24:15 +02:00
|
|
|
if($action == 'index' || empty($action)) return true;
|
2009-10-11 11:15:51 +02:00
|
|
|
|
2009-03-21 06:10:05 +01:00
|
|
|
if($allowedActions === null || !$this->uninherited('allowed_actions')) {
|
2008-10-31 03:16:25 +01:00
|
|
|
// If no allowed_actions are provided, then we should only let through actions that aren't handled by magic methods
|
2010-10-13 03:24:15 +02:00
|
|
|
// we test this by calling the unmagic method_exists.
|
|
|
|
if(method_exists($this, $action)) {
|
|
|
|
// Disallow any methods which aren't defined on RequestHandler or subclasses
|
|
|
|
// (e.g. ViewableData->getSecurityID())
|
|
|
|
$r = new ReflectionClass(get_class($this));
|
|
|
|
if($r->hasMethod($actionOrigCasing)) {
|
|
|
|
$m = $r->getMethod($actionOrigCasing);
|
2010-10-13 03:46:02 +02:00
|
|
|
return ($m && is_subclass_of($m->getDeclaringClass()->getName(), 'RequestHandler'));
|
2010-10-13 03:24:15 +02:00
|
|
|
} else {
|
|
|
|
throw new Exception("method_exists() true but ReflectionClass can't find method - PHP is b0kred");
|
|
|
|
}
|
2010-10-13 03:26:16 +02:00
|
|
|
} else if(!$this->hasMethod($action)){
|
2010-10-13 03:24:15 +02:00
|
|
|
// Return true so that a template can handle this action
|
|
|
|
return true;
|
|
|
|
}
|
2008-10-31 03:16:25 +01:00
|
|
|
}
|
2009-03-21 06:10:05 +01:00
|
|
|
|
2008-08-09 05:19:54 +02:00
|
|
|
return false;
|
|
|
|
}
|
2009-03-21 06:10:05 +01:00
|
|
|
|
2008-08-09 05:19:54 +02:00
|
|
|
/**
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
* Throws a HTTP error response encased in a {@link SS_HTTPResponse_Exception}, which is later caught in
|
2009-06-27 10:48:44 +02:00
|
|
|
* {@link RequestHandler::handleAction()} and returned to the user.
|
|
|
|
*
|
|
|
|
* @param int $errorCode
|
2010-12-02 09:03:17 +01:00
|
|
|
* @param string $errorMessage Plaintext error message
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
* @uses SS_HTTPResponse_Exception
|
2008-08-09 05:19:54 +02:00
|
|
|
*/
|
2009-06-27 10:48:44 +02:00
|
|
|
public function httpError($errorCode, $errorMessage = null) {
|
2010-12-02 09:03:17 +01:00
|
|
|
$e = new SS_HTTPResponse_Exception($errorMessage, $errorCode);
|
|
|
|
|
|
|
|
// Error responses should always be considered plaintext, for security reasons
|
|
|
|
$e->getResponse()->addHeader('Content-Type', 'text/plain');
|
|
|
|
|
|
|
|
throw $e;
|
2008-08-09 05:19:54 +02:00
|
|
|
}
|
2008-08-11 02:14:48 +02:00
|
|
|
|
|
|
|
/**
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
* Returns the SS_HTTPRequest object that this controller is using.
|
2008-08-11 02:14:48 +02:00
|
|
|
*
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
* @return SS_HTTPRequest
|
2008-08-11 02:14:48 +02:00
|
|
|
*/
|
|
|
|
function getRequest() {
|
|
|
|
return $this->request;
|
|
|
|
}
|
2009-06-27 10:48:44 +02:00
|
|
|
}
|