From 64379360f0db99200a9204e5a4a78882313cae18 Mon Sep 17 00:00:00 2001 From: tmont Date: Mon, 13 Oct 2008 05:45:49 +0000 Subject: [PATCH] moved wiki into panacea --- src/inc/WikiControllerFactory.php | 67 ++++++++++++++++++++++++++++ src/inc/WikiPageController.php | 66 ++++++++++++++++++++++++++++ src/inc/WikiViewFactory.php | 71 ++++++++++++++++++++++++++++++ src/inc/views/WikiPageView.php | 73 +++++++++++++++++++++++++++++++ 4 files changed, 277 insertions(+) create mode 100644 src/inc/WikiControllerFactory.php create mode 100644 src/inc/WikiPageController.php create mode 100644 src/inc/WikiViewFactory.php create mode 100644 src/inc/views/WikiPageView.php diff --git a/src/inc/WikiControllerFactory.php b/src/inc/WikiControllerFactory.php new file mode 100644 index 0000000..57edd7a --- /dev/null +++ b/src/inc/WikiControllerFactory.php @@ -0,0 +1,67 @@ +WikiControllerFactory instance + * + * @var Dispatcher + */ + protected static $instance = null; + + /** + * Gets the {@link ControllerFactory} instance + * + * @author Tommy Montgomery + * @since 2008-10-05 + * + * @return ControllerFactory + */ + public static function getInstance() { + if (self::$instance === null) { + self::$instance = new self(); + } + + return self::$instance; + } + + /** + * Parses the URI fragments and determines which + * {@link Controller} to instantiate + * + * @author Tommy Montgomery + * @since 2008-10-05 + * + * @param array $uriFragments The URI fragments + * @throws {@link ClassNotFoundException} + * @return WikiPageController + */ + public function getController(array $uriFragments) { + if (count($uriFragments) !== 1) { + throw new InvalidTypeException(1, 'array of size 1', $uriFragments); + } + + return new WikiPageController($uriFragments[0]); + } + + } + +?> \ No newline at end of file diff --git a/src/inc/WikiPageController.php b/src/inc/WikiPageController.php new file mode 100644 index 0000000..ca79a94 --- /dev/null +++ b/src/inc/WikiPageController.php @@ -0,0 +1,66 @@ +::VIEWTYPE_* constants + * @throws {@link InvalidTypeException} + */ + public function __construct($page = '', $viewType = View::VIEWTYPE_HTML) { + parent::__construct($page, $viewType); + $this->viewFactory = WikiViewFactory::getInstance(); + } + + /** + * 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 View + */ + public function handleRequest(Request $request = null) { + if (!($request instanceof Request)) { + $request = Request::create(HttpUtil::getRequestMethod()); + } + + try { + return $this->viewFactory->getView($this->page, $request->__toString()); + } + catch (ClassNotFoundException $e) { + throw new InvalidRequestException($request); + } + } + + } + +?> \ No newline at end of file diff --git a/src/inc/WikiViewFactory.php b/src/inc/WikiViewFactory.php new file mode 100644 index 0000000..76506b0 --- /dev/null +++ b/src/inc/WikiViewFactory.php @@ -0,0 +1,71 @@ +newInstanceArgs($args); + } + else { + return $refclass->newInstance(); + } + } + catch (ReflectionException $e) { + throw new ClassNotFoundException($viewName); + } + } + + } + +?> \ No newline at end of file diff --git a/src/inc/views/WikiPageView.php b/src/inc/views/WikiPageView.php new file mode 100644 index 0000000..159ffb6 --- /dev/null +++ b/src/inc/views/WikiPageView.php @@ -0,0 +1,73 @@ +wikiText = $wikiText; + } + + /** + * Gets all meta data associated with this view + * + * @author Tommy Montgomery + * @since 2008-10-05 + * + * @return ViewMetaData + */ + public function getMetaData() { + return new ViewMetaData(); + } + + /** + * Renders the view + * + * @author Tommy Montgomery + * @since 2008-10-05 + * + * @param bool $sendHeaders Whether to send the response headers or not + */ + public function send() { + WikiParser::parseText($this->wikiText); + echo $this->wikiText; + } + + } + +?> \ No newline at end of file