powered by nequal
Home » PHP_Object » Timeline » 292

Changeset 292 -- 2008-12-30 12:21:18

Author
lagos
Comment
Booleanオブジェクトもシングルトンにする

Diffs

PHP_Object/trunk/PHP/Object/Null.php

@@ -51,11 +51,11 @@
protected function __construct() {}
-    public static function getInstance()
+    protected static function getInstance()
{
static $instance = null;
if (is_null($instance)) {
-            $instance = new PHP_Object_Null();
+            $instance = new self;
}
return $instance;
}

PHP_Object/trunk/PHP/Object/Boolean.php

@@ -149,4 +149,13 @@
'XMLWRITER_START_DTD_ENTITY' => 2,
);
+    protected static function getInstance($data)
+    {
+        static $instances = array();
+        $key = ($data === true) ? 'true' : 'false';
+        if (!array_key_exists($key, $instances)) {
+            $instances[$key] = new self($data);
+        }
+        return $instances[$key];
+    }
}

PHP_Object/trunk/PHP/Object.php

@@ -138,7 +138,7 @@
} else if (is_array($data)) {
return new PHP_Object_Array($data);
} else if (is_bool($data)) {
-            return new PHP_Object_Boolean($data);
+            return PHP_Object_Boolean::getInstance($data);
} else if (is_null($data)) {
return PHP_Object_Null::getInstance();
} else if (is_object($data)) {