Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PageSpecial extends AStringEnum
- {
- static final function conditions()
- {
- return self::get(__FUNCTION__);
- }
- static final function home()
- {
- return self::get(__FUNCTION__);
- }
- static final function HOMEPAGE()
- {
- return self::home();
- }
- static final function DOMOV()
- {
- return self::get('home');
- }
- }
- abstract class AStringEnum
- {
- private static $instances, $list;
- private $value;
- private function __construct($value)
- {
- $this->value = (string) $value;
- }
- final function __toString()
- {
- return $this->value;
- }
- static final function getList()
- {
- if (is_null(self::$list)) {
- $class = get_called_class();
- $c = new \ReflectionClass($class);
- self::$list = array();
- foreach ($c->getMethods() as $m) {
- $name = strtoupper($m->getName());
- if ($m->isFinal() && $m->isStatic() && !in_array($name, array(
- 'GET', 'GETLIST'
- ))) {
- self::$list[$name] = (string) $class::$name();
- }
- }
- }
- return self::$list;
- }
- protected static final function get($value)
- {
- $value = (string) $value;
- if (empty(self::$instances[$value])) {
- $class = get_called_class();
- self::$instances[$value] = new $class($value);
- }
- return self::$instances[$value];
- }
- }
- var_dump(
- PageSpecial::HOME() === PageSpecial::HOMEPAGE() &&
- PageSpecial::HOMEPAGE() === PageSpecial::DOMOV()
- );
- print_r(PageSpecial::getList());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement