Skip to content

Instantly share code, notes, and snippets.

@codenamegary
Last active August 29, 2015 13:56
Show Gist options
  • Save codenamegary/9216235 to your computer and use it in GitHub Desktop.
Save codenamegary/9216235 to your computer and use it in GitHub Desktop.
<?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