I am building an MVC application in PHP, using Zend Framework.
My model includes Domain Model and Mapper layers. I am trying to keep the domain model in pristine condition and have managed to keep it free from persistence-related code. Now I am trying to find a solution for ACL.
I have ‘general’ ACL rules that can be easily enforced in a service layer, but I also have some very fine grained rules. The fine grained rules apply at the property level and affect whether the current user can alter a field, and if so, what the range of allowable values is.
Currently I am thinking of using the proxy pattern, and that the proxy should extend the real object (to save me having to redirect 100% of calls). Does this sound reasonable? Is there a better option?
If you extend your ACL class from the original class, you’re not following the Proxy pattern. A Proxy controlls the access to a given subject, implementing the same interface as the subject.
Using traits in PHP, you can build a generic Decorator, which you can use for all Proxies and Decorators.
interface MyModel {...}
class ConcreteModel implements MyModel
{
// Your properties and methods as usual
}
trait Decorator
{
private $subject;
public function __call($method, $args)
{
return call_user_func_array($method, $args);
}
// You might want to implement __callStatic, __get, and __set, too
}
class AclProxy implements MyModel
{
use Decorator;
public function __construct(MyModel $model)
{
$this->subject = $model;
}
// Your specific overrides go here
}
0