mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-25 09:11:17 +02:00
55 lines
1.1 KiB
PHP
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;
|
|
}
|
|
}
|