Created
April 6, 2011 00:32
-
-
Save grakic/904897 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
abstract class stdConst | |
{ | |
private $c; | |
public function __construct($c) | |
{ | |
// requirement is for a class to be named <Something>Const | |
// so static methods can be called on <Something> | |
if(substr(get_called_class(), -5) != 'Const') { | |
throw new RuntimeException('stdConst class name must end with Const keyword'); | |
} | |
$this->c = $c; | |
} | |
public function __set($n, $v) | |
{ | |
throw new RuntimeException(get_called_class() . ' can not be modified'); | |
} | |
public function __get($n) | |
{ | |
return $this->c->$n; | |
} | |
public function __isset($n) | |
{ | |
return isset($this->c->$n); | |
} | |
public function __unset($n) | |
{ | |
throw new RuntimeException(get_called_class() . ' can not be modified'); | |
} | |
public function __call($n, $a) | |
{ | |
return call_user_func_array(array($this->c, $n), $a); | |
} | |
public static function __callStatic($n, $a) | |
{ | |
// get non-constant class name, and call a static method | |
$class_name = substr(get_called_class(), 0, -5); | |
return call_user_func_array(array($class_name, $n), $a); | |
} | |
public function __toString() | |
{ | |
return $this->c->__toString(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment