mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-25 17:21:19 +02:00
PHP7 Proxy
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
namespace DesignPatterns\Structural\Proxy;
|
namespace DesignPatterns\Structural\Proxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class Record.
|
* @property string username
|
||||||
*/
|
*/
|
||||||
class Record
|
class Record
|
||||||
{
|
{
|
||||||
@@ -21,31 +21,20 @@ class Record
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* magic setter
|
|
||||||
*
|
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param string $value
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function __set(string $name, string $value)
|
public function __set(string $name, string $value)
|
||||||
{
|
{
|
||||||
$this->data[$name] = $value;
|
$this->data[$name] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* magic getter
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
*
|
|
||||||
* @return string|null
|
|
||||||
*/
|
|
||||||
public function __get(string $name): string
|
public function __get(string $name): string
|
||||||
{
|
{
|
||||||
if (isset($this->data[$name])) {
|
if (!isset($this->data[$name])) {
|
||||||
return $this->data[$name];
|
throw new \OutOfRangeException('Invalid name given');
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->data[$name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,8 +32,6 @@ class RecordProxy extends Record
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* magic setter
|
|
||||||
*
|
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $value
|
* @param string $value
|
||||||
*/
|
*/
|
||||||
@@ -44,9 +42,6 @@ class RecordProxy extends Record
|
|||||||
parent::__set($name, $value);
|
parent::__set($name, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isDirty(): bool
|
public function isDirty(): bool
|
||||||
{
|
{
|
||||||
return $this->isDirty;
|
return $this->isDirty;
|
||||||
|
@@ -10,7 +10,7 @@ class ProxyTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testWillSetDirtyFlagInProxy()
|
public function testWillSetDirtyFlagInProxy()
|
||||||
{
|
{
|
||||||
$recordProxy = new RecordProxy([]);
|
$recordProxy = new RecordProxy([]);
|
||||||
$recordProxy->foobar = 'baz';
|
$recordProxy->username = 'baz';
|
||||||
|
|
||||||
$this->assertTrue($recordProxy->isDirty());
|
$this->assertTrue($recordProxy->isDirty());
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ class ProxyTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testProxyIsInstanceOfRecord()
|
public function testProxyIsInstanceOfRecord()
|
||||||
{
|
{
|
||||||
$recordProxy = new RecordProxy([]);
|
$recordProxy = new RecordProxy([]);
|
||||||
$recordProxy->foobar = 'baz';
|
$recordProxy->username = 'baz';
|
||||||
|
|
||||||
$this->assertInstanceOf('DesignPatterns\Structural\Proxy\Record', $recordProxy);
|
$this->assertInstanceOf('DesignPatterns\Structural\Proxy\Record', $recordProxy);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user