Skip to content
Permalink
Browse files

Consolidate the emulated property definitions.

  • Loading branch information...
markstory committed Sep 1, 2016
1 parent 4dfd141 commit 4beec44a8dd9b5adff7d8a6144b89d6a5ec21407
Showing with 10 additions and 6 deletions.
  1. +10 −6 src/Network/Request.php
@@ -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.
*
@@ -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;
@@ -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."
);
@@ -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)) {

0 comments on commit 4beec44

Please sign in to comment.
You can’t perform that action at this time.