. */ namespace Volkszaehler\Controller; use Volkszaehler\View; /** * Controller superclass for all controllers * * @author Steffen Vogel * @package default */ abstract class Controller { protected $view; protected $em; /** * Constructor * * @param View $view * @param EntityManager $em */ public function __construct(View\View $view, \Doctrine\ORM\EntityManager $em) { $this->view = $view; $this->em = $em; } /** * Run operation * * @param string $operation runs the operation if class method is available */ public function run($op, array $arg = array()) { if (!method_exists($this, $op)) { throw new \Exception('Invalid context operation: ' . $op); } switch(count($arg)) { // improved performence case 0: return $this->{$op}(); case 1: return $this->{$op}($arg[0]); case 2: return $this->{$op}($arg[0], $arg[1]); case 3: return $this->{$op}($arg[0], $arg[1], $arg[2]); default: return call_user_func_array(array($this, $op), $arg); } } } ?>