Dominik Liebler 644d9cbd49 cs
2013-09-13 12:00:39 +02:00

60 lines
1.1 KiB
PHP

<?php
namespace DesignPatterns\Proxy;
/**
* Proxy pattern
*
* Purpose:
* to interface to anything that is expensive or impossible to duplicate
*
* Examples:
* - Doctrine2 uses proxies to implement framework magic (e.g. lazy initialization) in them, while the user still works
* with his own entity classes and will never use nor touch the proxies
*
*/
class Record
{
/**
* @var array|null
*/
protected $data;
/**
* @param null $data
*/
public function __construct($data = null)
{
$this->data = (array) $data;
}
/**
* magic setter
*
* @param string $name
* @param mixed $value
*
* @return void
*/
public function __set($name, $value)
{
$this->data[(string) $name] = $value;
}
/**
* magic getter
*
* @param string $name
*
* @return mixed|null
*/
public function __get($name)
{
if (array_key_exists($name, $this->data)) {
return $this->data[(string) $name];
} else {
return null;
}
}
}