All pastes #226308 Raw Edit

Untitled

public text v1 · immutable
#226308 ·published 2006-10-28 12:18 UTC
rendered paste body
class DataObjectDescriptor extends Object
{
    private $args;

    function __construct(array $args)
    {
        $this->args = $args;
    }

    function refresh(Object $object)
    {
        $publicproperties = $this->getPublicProperties($object);
        foreach ($this->args as $key => $value) if (isset($publicproperties[$key])) $object->$key = $value;
    }

    private function getPublicProperties(Object $object)
    {
        $objectname = get_class($object);
        $class = new ReflectionClass($objectname);
        $properties = array();
        foreach($class->getProperties() as $p) {
            $prop = new ReflectionProperty($objectname,$p->name);
            if ($prop->isPublic()) $properties[$p->name] = $p->name;
        }
        return $properties;
    }
}

class DataObjectMaster extends Object
{
    private $descriptor;

    public $objectid    = null;         // system id of the object in this installation
....

    function __construct(DataObjectDescriptor $descriptor)
    {
        $this->descriptor = $descriptor;
        $this->load();
        ....
    }
    
    public function load()
    {
        $this->descriptor->refresh($this);
    }