Witam,
mam pytanie, chciałbym zautomatyzować wykonywanie poszczególnych funkcji w klasie. Podam przykład:
class fTemplate {
private $response = array(
'001' => true,
'002' => 'Błędne dane wejściowe, spodziewana tablica, otrzymano inne dane',
'003' => 'Nie podano akcji'
);
public function action($act=null) {
if($act==null) throw new Exception($this->response['003']);
switch($act){
case 'update': return $this->updateTemplate($id); break;
case 'create': return $this->createTemplate($id); break;
case 'delete': return $this->deleteTemplate($id); break;
default: return false; break;
}
}
private function updateTemplate($data = null) {
//kod funkcji
}
private function createTemplate($data = null) {
//kod funkcji
}
private function deleteTemplate($data = null) {
//kod funkcji
}
public function getTemplateList($uid = null) {
//kod funkcji
}
...
}
Konkretnie chodzi o funkcję action, nie chcę używać switcha, wolałbym żeby w jakiś magiczny sposób system sam wiedział jaką funkcję ma wykonać na podstawie np. podania jakiejś zmiennej.