Skip to content

Commit

Permalink
MINOR Check that parent::__construct() is called on RequestHandler su…
Browse files Browse the repository at this point in the history
…bclasses, throw a warning if not

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@75657 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
Sean Harvey authored and Sam Minnee committed Feb 2, 2011
1 parent bc7c833 commit fe87ef7
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions core/control/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
class RequestHandler extends ViewableData {
protected $request = null;

/**
* This variable records whether RequestHandler::__construct()
* was called or not. Useful for checking if subclasses have
* called parent::__construct()
*
* @var boolean
*/
protected $brokenOnConstruct = true;

/**
* 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.
Expand Down Expand Up @@ -59,6 +68,12 @@ class RequestHandler extends ViewableData {
* </code>
*/
static $allowed_actions = null;

public function __construct() {
$this->brokenOnConstruct = false;
parent::__construct();
}

/**
* Handles URL requests.
*
Expand All @@ -78,10 +93,15 @@ class RequestHandler extends ViewableData {
* @return HTTPResponse|RequestHandler|string|array
*/
function handleRequest($request) {
$this->request = $request;

// $handlerClass is used to step up the class hierarchy to implement url_handlers inheritance
$handlerClass = ($this->class) ? $this->class : get_class($this);

if($this->brokenOnConstruct) {
user_error("parent::__construct() needs to be called on {$handlerClass}::__construct()", E_USER_WARNING);
}

$this->request = $request;

// We stop after RequestHandler; in other words, at ViewableData
while($handlerClass && $handlerClass != 'ViewableData') {
$urlHandlers = Object::get_static($handlerClass, 'url_handlers');
Expand Down

0 comments on commit fe87ef7

Please sign in to comment.