2013-09-11 16:50:01 +02:00
|
|
|
<?php
|
|
|
|
|
2014-04-15 23:14:39 -03:00
|
|
|
namespace DesignPatterns\Structural\Proxy;
|
2013-09-11 16:50:01 +02:00
|
|
|
|
|
|
|
/**
|
2015-12-21 07:28:20 -05:00
|
|
|
* Class RecordProxy.
|
2013-09-11 16:50:01 +02:00
|
|
|
*/
|
|
|
|
class RecordProxy extends Record
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $isDirty = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $isInitialized = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*/
|
|
|
|
public function __construct($data)
|
|
|
|
{
|
|
|
|
parent::__construct($data);
|
|
|
|
|
|
|
|
// when the record has data, mark it as initialized
|
|
|
|
// since Record will hold our business logic, we don't want to
|
|
|
|
// implement this behaviour there, but instead in a new proxy class
|
|
|
|
// that extends the Record class
|
|
|
|
if (null !== $data) {
|
|
|
|
$this->isInitialized = true;
|
|
|
|
$this->isDirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-21 07:28:20 -05:00
|
|
|
* magic setter.
|
2013-09-11 16:50:01 +02:00
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param mixed $value
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __set($name, $value)
|
|
|
|
{
|
|
|
|
$this->isDirty = true;
|
|
|
|
parent::__set($name, $value);
|
|
|
|
}
|
2013-09-13 12:00:39 +02:00
|
|
|
}
|