/** * Initialize controller and run action * * Requires **$app->in('controller')** and **$app->in('action')** * parameters to be defined. * * @see TipyController * @todo Different exceptions handling in production and development modes */ public function run() { $this->logger->debug($this->request->method() . ': ' . $this->request->uri()); try { // Get controller and action name $controllerName = $this->in->get('controller'); $actionName = $this->in->get('action'); // Some basic checking if (!$controllerName || preg_match('/^\\W*$/', $controllerName)) { throw new TipyException('Controller name is missing'); } if (!$actionName || preg_match('/^\\W*$/', $actionName)) { throw new TipyException('Action name is missing'); } $controllerName = TipyInflector::controllerize($controllerName) . 'Controller'; if (class_exists($controllerName)) { $controller = new $controllerName(); } else { throw new TipyException('Unable to find ' . $controllerName . ' class'); } $actionName = TipyInflector::camelCase($actionName); if (in_array($actionName, get_class_methods($controllerName))) { $this->logger->debug('Executing ' . $controllerName . '::' . $actionName . '();'); $controller->execute($actionName); } else { throw new TipyException('Undefined action ' . $controllerName . '::' . $actionName . '()'); } } catch (Exception $exception) { throw new TipyException($exception->getMessage(), $exception->getCode(), $exception); } }
/** * Shortcut to $this->in->get() * @param string $key * @param mixed $defaultValue * @return mixed */ public function in($key, $defaultValue = null) { return $this->in->get($key, $defaultValue); }