Last active
December 10, 2015 08:58
-
-
Save a-suenami/4411372 to your computer and use it in GitHub Desktop.
ENUM値をオブジェクトにしたい。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Status | |
{ | |
private $value; | |
private static $instances = array(); | |
private function __construct($value) | |
{ | |
$this->value = $value; | |
} | |
private function _getCacheKey($value) | |
{ | |
return sha1('status_'.$value); | |
} | |
public static function getInstance($value) | |
{ | |
$key = $this->_getCacheKey($value); | |
$cached_instance = apc_fetch($key); | |
if ($cached_instance) return $cached_instance; | |
if (isset($this->instances[$value])) return $this->instances[$value]; | |
$instance = new Status($value); | |
$this->instances[$value] = $instance; | |
apc_add($key, $instance); | |
return $instance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment