/** * Constructor method to instantiate the default controller object * * @param Request $request * @param Response $response * @param Project $project * @param string $viewPath * @return self */ public function __construct(Request $request = null, Response $response = null, Project $project = null, $viewPath = null) { if (null === $viewPath) { $cfg = $project->module('Phire')->asArray(); $viewPath = __DIR__ . '/../../../../../view/phire/install'; if (isset($cfg['view'])) { $class = get_class($this); if (is_array($cfg['view']) && isset($cfg['view'][$class])) { $viewPath = $cfg['view'][$class]; } else { if (is_array($cfg['view']) && isset($cfg['view']['*'])) { $viewPath = $cfg['view']['*'] . '/install'; } else { if (is_string($cfg['view'])) { $viewPath = $cfg['view'] . '/install'; } } } } } $lang = isset($_GET['lang']) ? $_GET['lang'] : 'en_US'; if (!defined('POP_LANG')) { define('POP_LANG', $lang); } $this->i18n = I18n::factory(); $this->i18n->loadFile($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . '/vendor/Phire/data/assets/i18n/' . $this->i18n->getLanguage() . '.xml'); parent::__construct($request, $response, $project, $viewPath); $this->sess = Session::getInstance(); }
public function __construct(Request $request = null, Response $response = null, Project $project = null, $viewPath = null) { // Set the view path if (null === $viewPath) { $viewPath = __DIR__; } // Create a request if (null === $request) { $request = new Request(); } parent::__construct($request, $response, $project, $viewPath); }
/** * Get action from request within the current controller * * @return string */ public function getAction() { $action = null; if (null !== $this->controller && null !== $this->controller->getRequest()) { // If the URI is root '/', then set to 'index' if ($this->controller->getRequest()->getRequestUri() == '/') { $action = 'index'; // Else, figure out the action from the path stems } else { if ($this->controller->getRequest()->getPath(0) != '') { $path = $this->controller->getRequest()->getPath(); $basePath = explode('/', substr($this->basePath, 1)); $pathDiff = array_values(array_diff($path, $basePath)); if (isset($pathDiff[0])) { $realBasePath = substr($this->controller->getRequest()->getBasePath(), -1) == '/' ? substr($this->controller->getRequest()->getBasePath(), 0, -1) : $this->controller->getRequest()->getBasePath(); $this->controller->getRequest()->setRequestUri('/' . implode('/', $pathDiff), $realBasePath); $action = $pathDiff[0]; } } } } return $action; }
public function testSendException() { $this->setExpectedException('Pop\\Mvc\\Exception'); $c = new Controller(); $c->send(); }