I have a class with an attribute and methods similar to the code shown below, only more complex. The idea is to call an element in the dispatch array and then the methods listed for that element will execute in the order that they are listed. I am stuck on how to get the methods to execute (see method called execute()). Is this even possible?
Note that setDispatch() is called in the constructor which is not shown in the code below.
// attribute
private $_dispatch = [];
// methods
public function execute()
{
$dispatch = $this->getDispatch();
// NEED LOGIC HERE THAT EXECUTES METHODS LISTED IN $dispatch['A']
}
private function setDispatch()
{
$this->_dispatch = [
'A' => [
'method1',
'method2',
'method3'
],
'B' => [
'method4',
'method3',
'method1'
]
];
}
private function getDispatch()
{
return $this->_dispatch;
}
private function method1()
{
//do something
}
private function method2()
{
//do something
}
private function method3()
{
//do something
}
private function method4()
{
//do something
}