I have the following class structure:
class Parent
{
public function process($action)
{
// i.e. processCreateMyEntity
$this->{'process' . $action};
}
}
class Child extends Parent
{
protected function processCreateMyEntity
{
echo 'kiss my indecisive ass';
}
}
I need to write some unified method in Child class to process several very similar actions for creating entities. I can't change the Parent::process and I need those methods to be called from it.
The first thing that comes to mind is magic __call method. The entity name is parsed from the first __call argument. So the structure turns to:
class Parent
{
public function process($action)
{
// i.e. processCreateMyEntity
$this->{'process' . $action};
}
}
class Child extends Parent
{
protected function __call($methodName, $args)
{
$entityName = $this->parseEntityNameFromMethodCalled($methodName);
// some actions common for a lot of entities
}
}
But the thing is that __call can't be protected as I need it. I put a hack method call at the beginning of __call method that checks via debug_backtrace that this method was called inside Parent::process, but this smells bad.
Any ideas?