From 4eb51ee6ae90a84e7a766287f4e23506a29c9f67 Mon Sep 17 00:00:00 2001 From: tmont Date: Sun, 2 Nov 2008 02:16:33 +0000 Subject: [PATCH] updated controllers and views to use new configuration-driven database objects --- src/index.php | 9 ++++++- src/lib/PanaceaWikiPageObject.php | 4 +-- src/lib/PanaceaWikiParser.php | 27 ++----------------- .../controllers/PanaceaDefaultController.php | 2 +- .../controllers/PanaceaTrackerController.php | 2 +- src/lib/controllers/PanaceaWikiController.php | 10 ++++--- src/lib/views/wiki/WikiPageView.php | 5 ++-- 7 files changed, 22 insertions(+), 37 deletions(-) diff --git a/src/index.php b/src/index.php index 81af1ba..8a11d42 100644 --- a/src/index.php +++ b/src/index.php @@ -15,6 +15,13 @@ $uriRegex = str_replace('\\', '/', $uriRegex); $uriRegex = '^' . $uriRegex . '/([^/]*)(?:/([^\?]*)(?:\?(.*))?)?'; + $configFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . + 'lib' . DIRECTORY_SEPARATOR . + 'config' . DIRECTORY_SEPARATOR . + 'panacea.ini'; + + $config = new Configuration($configFile); + /* * $uriRegex: ^/webroot/([^/]*)(?:/(.*)(?:\?(.*))?)? * @@ -27,6 +34,6 @@ Dispatcher::getInstance()->setUriRegex($uriRegex) ->setThrowExceptions(true) ->setControllerFactory(PanaceaControllerFactory::getInstance()) - ->dispatch($_SERVER['REQUEST_URI']); + ->dispatch($_SERVER['REQUEST_URI'], $config); ?> \ No newline at end of file diff --git a/src/lib/PanaceaWikiPageObject.php b/src/lib/PanaceaWikiPageObject.php index 6f1186a..0c663cb 100644 --- a/src/lib/PanaceaWikiPageObject.php +++ b/src/lib/PanaceaWikiPageObject.php @@ -32,8 +32,8 @@ * * @param WikiPage $page A wiki page */ - public function __construct(WikiPage $page) { - parent::__construct($page, PanaceaWikiParser::getInstance()); + public function __construct(WikiPage $page, Configuration $config) { + parent::__construct($page, new PanaceaWikiParser($config)); } } diff --git a/src/lib/PanaceaWikiParser.php b/src/lib/PanaceaWikiParser.php index 841e7c4..85154aa 100644 --- a/src/lib/PanaceaWikiParser.php +++ b/src/lib/PanaceaWikiParser.php @@ -22,13 +22,6 @@ */ class PanaceaWikiParser extends WikiParser { - /** - * The singleton instance - * - * @var WikiParser - */ - private static $instance = null; - /** * Creates a new {@link PanaceaWikiParser} * @@ -36,28 +29,12 @@ * @since 2008-10-19 * @todo Use configuration object for linkRoot */ - protected function __construct() { - parent::__construct(); + public function __construct(Configuration $config) { + parent::__construct($config); $this->linkRoot = '/panacea/src/wiki'; } - /** - * Gets the singleton instance - * - * @author Tommy Montgomery - * @since 2008-10-19 - * - * @return PanaceaWikiParser - */ - public static function getInstance() { - if (self::$instance === null) { - self::$instance = new self(); - } - - return self::$instance; - } - } ?> \ No newline at end of file diff --git a/src/lib/controllers/PanaceaDefaultController.php b/src/lib/controllers/PanaceaDefaultController.php index 73b0cce..9ebd118 100644 --- a/src/lib/controllers/PanaceaDefaultController.php +++ b/src/lib/controllers/PanaceaDefaultController.php @@ -63,7 +63,7 @@ * @throws {@link InvalidRequestException} if a {@link View} cannot be created * @return PanaceaTemplateView */ - public function handleRequest(Request $request = null) { + public function handleRequest(Request $request = null, Configuration $config = null) { if (!($request instanceof Request)) { $request = Request::create(HttpUtil::getRequestMethod()); } diff --git a/src/lib/controllers/PanaceaTrackerController.php b/src/lib/controllers/PanaceaTrackerController.php index fcb9c25..3352ad8 100644 --- a/src/lib/controllers/PanaceaTrackerController.php +++ b/src/lib/controllers/PanaceaTrackerController.php @@ -50,7 +50,7 @@ * @throws {@link InvalidRequestException} if a {@link View} cannot be created * @return PanaceaTemplateView */ - public function handleRequest(Request $request = null) { + public function handleRequest(Request $request = null, Configuration $config = null) { if (!($request instanceof Request)) { $request = Request::create(HttpUtil::getRequestMethod()); } diff --git a/src/lib/controllers/PanaceaWikiController.php b/src/lib/controllers/PanaceaWikiController.php index 7f5ef86..3eb7cc7 100644 --- a/src/lib/controllers/PanaceaWikiController.php +++ b/src/lib/controllers/PanaceaWikiController.php @@ -53,12 +53,12 @@ * @throws {@link InvalidRequestException} if a {@link View} cannot be created * @return PanaceaTemplateView */ - public function handleRequest(Request $request = null) { + public function handleRequest(Request $request = null, Configuration $config = null) { if (!($request instanceof Request)) { $request = Request::create(HttpUtil::getRequestMethod()); } - $mysql = MySql::getInstance('wiki', 'localhost', 'root', 'layne', 'wiki'); + $mysql = new MySql($config); //handle request metadata if ($request->method === HttpUtil::HTTP_METHOD_POST) { @@ -68,7 +68,7 @@ try { try { - $wikiObject = new PanaceaWikiPageObject(WikiPage::loadByPageName($mysql, $this->page)); + $wikiObject = new PanaceaWikiPageObject(WikiPage::loadByPageName($mysql, $this->page), $config); $wikiObject->setRevision(WikiHistory::REV_LATEST, $mysql); } catch (DomainException $e) { @@ -77,8 +77,10 @@ $this->action = 'new'; } + $vendor = new MySql($config); + $templateView = new PanaceaTemplateView('Wiki :: ' . $this->page); - $templateView->mainView->addView($this->viewFactory->getView($this->page, $wikiObject, $this->action, $this->page)); + $templateView->mainView->addView($this->viewFactory->getView($this->page, $wikiObject, $vendor, $this->action, $this->page)); return $templateView; } diff --git a/src/lib/views/wiki/WikiPageView.php b/src/lib/views/wiki/WikiPageView.php index b01f862..af4be12 100644 --- a/src/lib/views/wiki/WikiPageView.php +++ b/src/lib/views/wiki/WikiPageView.php @@ -30,17 +30,16 @@ * @uses addView() * * @param WikiPageObject $page The wiki page to display + * @param DatabaseVendor $vendor A database connection object * @param string $action The action to take * @param int $priority The priority of the view * @param string $pageName The name of the page */ - public function __construct(WikiPageObject $page = null, $action = null, $pageName = '', $priority = 0) { + public function __construct(WikiPageObject $page = null, DatabaseVendor $vendor = null, $action = null, $pageName = '', $priority = 0) { parent::__construct($page, $action, $priority); $this->addView(new WikiPageMenuView($page, $action, 1)); - $vendor = MySql::getInstance('wiki', 'localhost', 'root', 'layne', 'wiki'); - switch ($this->action) { case 'new': $this->addView(new WikiPageNewView($pageName, 2));