Last active
August 29, 2015 13:56
-
-
Save codenamegary/9216235 to your computer and use it in GitHub Desktop.
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 | |
namespace Vent; | |
trait VentTrait { | |
/** | |
* Handle a write request | |
* @param $name | |
* @param $value | |
*/ | |
public function __set($name, $value) | |
{ | |
$ventMethodName = 'ventWrite' . ucfirst($name); | |
if(method_exists($this, $ventMethodName)) return $this->$ventMethodName(); | |
} | |
/** | |
* Handle read request | |
* @param $name | |
* @return mixed | |
* @throws \Exception | |
*/ | |
public function &__get($name) | |
{ | |
$ventMethodName = 'ventRead' . ucfirst($name); | |
if(method_exists($ventMethodName)) return $this->$ventMethodName(); | |
} | |
public function ventThrow($message) | |
{ | |
throw new Exception($message); | |
} | |
} | |
class Ventable { | |
use VentTrait; | |
private $foo; | |
private function ventReadFoo() | |
{ | |
$this->ventThrow('No. No $foo for you!'); | |
} | |
private function ventWriteFoo() | |
{ | |
$this->ventThrow('No.'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment