Files
DesignPatternsPHP/Structural/Proxy/RecordProxy.php
Dominik Liebler 95ad95c33e On to PHP7^!
2016-09-21 17:23:20 +02:00

55 lines
1.1 KiB
PHP

<?php
namespace DesignPatterns\Structural\Proxy;
class RecordProxy extends Record
{
/**
* @var bool
*/
private $isDirty = false;
/**
* @var bool
*/
private $isInitialized = false;
/**
* @param array $data
*/
public function __construct(array $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 (count($data) > 0) {
$this->isInitialized = true;
$this->isDirty = true;
}
}
/**
* magic setter
*
* @param string $name
* @param string $value
*/
public function __set(string $name, string $value)
{
$this->isDirty = true;
parent::__set($name, $value);
}
/**
* @return bool
*/
public function isDirty(): bool
{
return $this->isDirty;
}
}