Skip to content

Instantly share code, notes, and snippets.

@teresko
Created February 17, 2017 18:23
Show Gist options
  • Save teresko/c4860f970f64995198cb0419d3eda1c2 to your computer and use it in GitHub Desktop.
Save teresko/c4860f970f64995198cb0419d3eda1c2 to your computer and use it in GitHub Desktop.
<?php
namespace Something\LibName;
use Something\LibName\Exceptions;
class Membrane
{
private $wrappedObject;
private $accessControl;
/**
* @codeCoverageIgnore
*/
public function __construct($wrappedObject, $accessControl)
{
$this->wrappedObject = $wrappedObject;
$this->accessControl = $accessControl;
}
public function hasMethod($method)
{
return method_exists($this->wrappedObject, $method);
}
public function __call($method, $arguments)
{
if (!$this->accessControl->isAllowed(get_class($this->wrappedObject))) {
throw new Exceptions\AccessDenied;
}
if (!method_exists($this->wrappedObject, $method)) {
throw new Exceptions\MethodNotFound;
}
return call_user_func_array(array($this->wrappedObject, $method), $arguments);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment