レジストリクラス

ふと思い立って、レジストリクラスを作る。global変数でもいいんだけど、なんか格好悪い。全部staticメソッドね。

class Moony_Registry
{
    var $registries = array();

    function set($name, $value)
    {
        $registry = Moony_Registry::_getInstance();
        $registry->registries[$name] = $value;
    }

    function get($name, $default = null)
    {
        $registry = Moony_Registry::_getInstance();
        if (array_key_exists($name, $registry->registries)) {
            return $registry->registries[$name];
        }
        return $default;
    }

    function exists($name)
    {
        $registry = Moony_Registry::_getInstance();
        return array_key_exists($name, $registry->registries);
    }

    function &_getInstance()
    {
        static $instance;
        if (is_null($instance)) {
            $instance = new Moony_Registry();
        }
        return $instance;
    }
}