<?php

namespace Heanup\Frame;

/**
 * 数据结构父类
 */
class Object
{

    private $_data = array ();

    public function __construct(Array $data = array ())
    {
        foreach ($data as $name => $value) {
            $this->_data[$name] = $value;
        }
    }

    public function __isset($name)
    {
        return isset($this->_data[$name]);
    }

    public function __set($name, $value)
    {
        if (isset($this->_data[$name])) {
            $this->_data[$name] = $value;
        }
    }

    public function __get($name)
    {
        if (isset($this->_data[$name])) {
            return $this->_data[$name];
        }
    }

    public function toArray()
    {
        return $this->_data;
    }

    public function __toString()
    {
        return json_encode($this->_data);
    }

    public function __sleep()
    {
        return $this->_data;
    }

    public function __wakeUp()
    {
        // ;
    }

}
