-
-
Save teresko/c4860f970f64995198cb0419d3eda1c2 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 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