panacea-php/src/lib/PanaceaDefaultController.php

81 lines
2.0 KiB
PHP

<?php
/**
* PanaceaDefaultController
*
* @package Panacea
* @author Tommy Montgomery
* @since 2008-10-05
*/
/** Bootstraps the NowhereConcave framework */
require_once 'NowhereConcave/bootstrap.php';
/**
* Panacea controller
*
* @package Panacea
* @author Tommy Montgomery
* @since 2008-10-05
*/
class PanaceaDefaultController extends Controller {
/**
* Creates a new {@link PanaceaDefaultController}
*
* @author Tommy Montgomery
* @since 2008-10-05
* @uses PanaceaViewFactory::getInstance()
*
* @param string $page Name of the page (view)
* @param int $viewType One of the {@link View}<kbd>::VIEWTYPE_*</kbd> constants
* @throws {@link InvalidTypeException}
*/
public function __construct($page = '', $viewType = View::VIEWTYPE_HTML) {
parent::__construct($page, $viewType);
$this->viewFactory = PanaceaViewFactory::getInstance();
}
/**
* Gets the default page if none is specified in the URI
*
* @author Tommy Montgomery
* @since 2008-10-18
*
* @return string
*/
public static function getDefaultPageName() {
return 'Home';
}
/**
* Handles the specified request, and generates a
* suitable response
*
* @author Tommy Montgomery
* @since 2008-10-05
* @uses Request::create()
* @uses HttpUtil::getRequestMethod()
*
* @throws {@link InvalidRequestException} if a {@link View} cannot be created
* @return PanaceaTemplateView
*/
public function handleRequest(Request $request = null) {
if (!($request instanceof Request)) {
$request = Request::create(HttpUtil::getRequestMethod());
}
try {
$title = (empty($this->page) || $this->page === 'Home') ? 'It doesn\'t suck' : $this->page;
$templateView = new PanaceaTemplateView($title);
$templateView->mainView->addView($this->viewFactory->getView($this->page));
return $templateView;
}
catch (ClassNotFoundException $e) {
throw new InvalidRequestException($request);
}
}
}
?>