Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace MarcoPivetta;
- /**
- * Makes elements accessible as an array
- * Proxies all calls to an array offset to getter/setter methods of the class
- * Inflater getter/setter has to be created
- *
- * @author Ocramius
- */
- class Entity implements \ArrayAccess {
- /**
- * Empty default constructor to allow parent constructor invocation
- */
- public function __construct(){
- }
- /**
- * ArrayAccess implementation
- */
- public function offsetExists($offset) {
- return $this->__isset($offset);
- }
- /**
- * ArrayAccess implementation
- */
- public function offsetGet($offset) {
- return $this->__get($offset);
- }
- /**
- * ArrayAccess implementation
- */
- public function offsetSet($offset, $value) {
- return $this->__set($offset,$value);
- }
- /**
- * ArrayAccess implementation
- */
- public function offsetUnset($offset) {
- return $this->__unset($offset);
- }
- /**
- * proxy to setter of $name
- */
- public function __set($name, $value) {
- return $this->{'set'.ucfirst($name)}($value);
- }
- /**
- * proxy to getter of $name
- */
- public function __get($name) {
- return $this->{'get'.ucfirst($name)}();
- }
- /**
- * proxy to issetter of $name
- */
- public function __isset($name) {
- return $this->{'get'.ucfirst($name)}() !== null;
- }
- /**
- * proxy to unsetter of $name
- */
- public function __unset($name) {
- return $this->__set($name,null);
- }
- /**
- * Allows usage of set$Parameter when the method is not defined though inflection
- */
- public function __call($name, $arguments) {
- if(strpos($name,'set')===0){
- return $this->{lcfirst(substr($name,3))}=$arguments[0];
- }elseif(strpos($name,'get')===0){
- return $this->{lcfirst(substr($name,3))};
- }
- //ADD METHODS TO PUSH/POP/ADD/REMOVE ON ARRAY ELEMENTS
- throw new \MarcoPivetta\Exception('Undefined method \'' . $name . '\' called on ' . get_class($this), 6000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement