cakephp/cakephp — pull request #2650 by mouyang (2014-01-14 08:32:07+00:00)
Title: allow additional status codes through constructor

It is currently possible to possible to trigger a CakeException by passing in an unsupported status code into the constructor. This allows for additional status codes to be set (through $options['codes']). While this is largely syntactic sugar, it can potentially prevent an exception.

Assuming we are inside of a class declaration, $object is an class instance, and $extraCodes is an object attribute,

public function __construct($object) {
$this->httpCodes($this->extraCodes);
parent::__construct(
'status' => $object->getStatusCode(),
// etc ...
);
}

would turn into ...

public function __construct($object) {
parent::__construct(
'status' => $object->getStatusCode(),
'codes' => $this->extraCodes,
// etc ...
);
}

My current usage is that I am trying to build a CakeResponse from a different object (Adapter pattern) that can have a status code not in CakeResponse::$_statusCodes. It's not ground-breaking and I could totally do without it. But I think the second form follows a more functional style and thus is a little more concise than the first.