Skip to content

Commit

Permalink
Consolidate the emulated property definitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Sep 1, 2016
1 parent 4dfd141 commit 4beec44
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Network/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ class Request implements ArrayAccess
*/
protected $attributes = [];

/**
* A list of propertes that emulated by the PSR7 attribute methods.
*
* @var array
*/
protected $emulatedAttributes = ['webroot', 'base', 'params'];

/**
* Wrapper method to create a new request from PHP superglobals.
*
Expand Down Expand Up @@ -1438,8 +1445,7 @@ public function withParam($name, $value)
public function withAttribute($name, $value)
{
$new = clone $this;
$emulated = ['webroot', 'base', 'params'];
if (in_array($name, $emulated, true)) {
if (in_array($name, $this->emulatedAttributes, true)) {
$new->{$name} = $value;
} else {
$new->attributes[$name] = $value;
Expand All @@ -1458,8 +1464,7 @@ public function withAttribute($name, $value)
public function withoutAttribute($name)
{
$new = clone $this;
$emulated = ['webroot', 'base', 'params'];
if (in_array($name, $emulated, true)) {
if (in_array($name, $this->emulatedAttributes, true)) {
throw new InvalidArgumentException(
"You cannot unset '$name'. It is a required CakePHP attribute."
);
Expand All @@ -1478,8 +1483,7 @@ public function withoutAttribute($name)
*/
public function getAttribute($name, $default = null)
{
$emulated = ['webroot', 'base', 'params'];
if (in_array($name, $emulated, true)) {
if (in_array($name, $this->emulatedAttributes, true)) {
return $this->{$name};
}
if (array_key_exists($name, $this->attributes)) {
Expand Down

0 comments on commit 4beec44

Please sign in to comment.