updated controllers and views to use new configuration-driven database objects
This commit is contained in:
		
							parent
							
								
									10e076a269
								
							
						
					
					
						commit
						4eb51ee6ae
					
				| @ -15,6 +15,13 @@ | |||||||
| 	$uriRegex = str_replace('\\', '/', $uriRegex); | 	$uriRegex = str_replace('\\', '/', $uriRegex); | ||||||
| 	$uriRegex = '^' . $uriRegex . '/([^/]*)(?:/([^\?]*)(?:\?(.*))?)?'; | 	$uriRegex = '^' . $uriRegex . '/([^/]*)(?:/([^\?]*)(?:\?(.*))?)?'; | ||||||
| 	 | 	 | ||||||
|  | 	$configFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . | ||||||
|  | 	              'lib'             . DIRECTORY_SEPARATOR . | ||||||
|  | 	              'config'          . DIRECTORY_SEPARATOR . | ||||||
|  | 	              'panacea.ini'; | ||||||
|  | 	 | ||||||
|  | 	$config = new Configuration($configFile); | ||||||
|  | 	 | ||||||
| 	/* | 	/* | ||||||
| 	 * $uriRegex: ^/webroot/([^/]*)(?:/(.*)(?:\?(.*))?)? | 	 * $uriRegex: ^/webroot/([^/]*)(?:/(.*)(?:\?(.*))?)? | ||||||
| 	 * | 	 * | ||||||
| @ -27,6 +34,6 @@ | |||||||
| 	Dispatcher::getInstance()->setUriRegex($uriRegex) | 	Dispatcher::getInstance()->setUriRegex($uriRegex) | ||||||
| 	                         ->setThrowExceptions(true) | 	                         ->setThrowExceptions(true) | ||||||
| 	                         ->setControllerFactory(PanaceaControllerFactory::getInstance()) | 	                         ->setControllerFactory(PanaceaControllerFactory::getInstance()) | ||||||
| 	                         ->dispatch($_SERVER['REQUEST_URI']); | 	                         ->dispatch($_SERVER['REQUEST_URI'], $config); | ||||||
| 
 | 
 | ||||||
| ?>
 | ?>
 | ||||||
| @ -32,8 +32,8 @@ | |||||||
| 		 * | 		 * | ||||||
| 		 * @param WikiPage   $page   A wiki page | 		 * @param WikiPage   $page   A wiki page | ||||||
| 		 */ | 		 */ | ||||||
| 		public function __construct(WikiPage $page) { | 		public function __construct(WikiPage $page, Configuration $config) { | ||||||
| 			parent::__construct($page, PanaceaWikiParser::getInstance()); | 			parent::__construct($page, new PanaceaWikiParser($config)); | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -22,13 +22,6 @@ | |||||||
| 	 */ | 	 */ | ||||||
| 	class PanaceaWikiParser extends WikiParser { | 	class PanaceaWikiParser extends WikiParser { | ||||||
| 		 | 		 | ||||||
| 		/** |  | ||||||
| 		 * The singleton instance |  | ||||||
| 		 * |  | ||||||
| 		 * @var WikiParser |  | ||||||
| 		 */ |  | ||||||
| 		private static $instance = null; |  | ||||||
| 		 |  | ||||||
| 		/** | 		/** | ||||||
| 		 * Creates a new {@link PanaceaWikiParser} | 		 * Creates a new {@link PanaceaWikiParser} | ||||||
| 		 * | 		 * | ||||||
| @ -36,28 +29,12 @@ | |||||||
| 		 * @since  2008-10-19 | 		 * @since  2008-10-19 | ||||||
| 		 * @todo   Use configuration object for linkRoot | 		 * @todo   Use configuration object for linkRoot | ||||||
| 		 */ | 		 */ | ||||||
| 		protected function __construct() { | 		public function __construct(Configuration $config) { | ||||||
| 			parent::__construct(); | 			parent::__construct($config); | ||||||
| 			 | 			 | ||||||
| 			$this->linkRoot = '/panacea/src/wiki'; | 			$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; |  | ||||||
| 		} |  | ||||||
| 		 |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| ?>
 | ?>
 | ||||||
| @ -63,7 +63,7 @@ | |||||||
| 		 * @throws {@link InvalidRequestException} if a {@link View} cannot be created | 		 * @throws {@link InvalidRequestException} if a {@link View} cannot be created | ||||||
| 		 * @return PanaceaTemplateView | 		 * @return PanaceaTemplateView | ||||||
| 		 */ | 		 */ | ||||||
| 		public function handleRequest(Request $request = null) { | 		public function handleRequest(Request $request = null, Configuration $config = null) { | ||||||
| 			if (!($request instanceof Request)) { | 			if (!($request instanceof Request)) { | ||||||
| 				$request = Request::create(HttpUtil::getRequestMethod()); | 				$request = Request::create(HttpUtil::getRequestMethod()); | ||||||
| 			} | 			} | ||||||
|  | |||||||
| @ -50,7 +50,7 @@ | |||||||
| 		 * @throws {@link InvalidRequestException} if a {@link View} cannot be created | 		 * @throws {@link InvalidRequestException} if a {@link View} cannot be created | ||||||
| 		 * @return PanaceaTemplateView | 		 * @return PanaceaTemplateView | ||||||
| 		 */ | 		 */ | ||||||
| 		public function handleRequest(Request $request = null) { | 		public function handleRequest(Request $request = null, Configuration $config = null) { | ||||||
| 			if (!($request instanceof Request)) { | 			if (!($request instanceof Request)) { | ||||||
| 				$request = Request::create(HttpUtil::getRequestMethod()); | 				$request = Request::create(HttpUtil::getRequestMethod()); | ||||||
| 			} | 			} | ||||||
|  | |||||||
| @ -53,12 +53,12 @@ | |||||||
| 		 * @throws {@link InvalidRequestException} if a {@link View} cannot be created | 		 * @throws {@link InvalidRequestException} if a {@link View} cannot be created | ||||||
| 		 * @return PanaceaTemplateView | 		 * @return PanaceaTemplateView | ||||||
| 		 */ | 		 */ | ||||||
| 		public function handleRequest(Request $request = null) { | 		public function handleRequest(Request $request = null, Configuration $config = null) { | ||||||
| 			if (!($request instanceof Request)) { | 			if (!($request instanceof Request)) { | ||||||
| 				$request = Request::create(HttpUtil::getRequestMethod()); | 				$request = Request::create(HttpUtil::getRequestMethod()); | ||||||
| 			} | 			} | ||||||
| 			 | 			 | ||||||
| 			$mysql = MySql::getInstance('wiki', 'localhost', 'root', 'layne', 'wiki'); | 			$mysql = new MySql($config); | ||||||
| 			 | 			 | ||||||
| 			//handle request metadata
 | 			//handle request metadata
 | ||||||
| 			if ($request->method === HttpUtil::HTTP_METHOD_POST) { | 			if ($request->method === HttpUtil::HTTP_METHOD_POST) { | ||||||
| @ -68,7 +68,7 @@ | |||||||
| 			 | 			 | ||||||
| 			try { | 			try { | ||||||
| 				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); | 					$wikiObject->setRevision(WikiHistory::REV_LATEST, $mysql); | ||||||
| 				} | 				} | ||||||
| 				catch (DomainException $e) { | 				catch (DomainException $e) { | ||||||
| @ -77,8 +77,10 @@ | |||||||
| 					$this->action = 'new'; | 					$this->action = 'new'; | ||||||
| 				} | 				} | ||||||
| 				 | 				 | ||||||
|  | 				$vendor = new MySql($config); | ||||||
|  | 				 | ||||||
| 				$templateView = new PanaceaTemplateView('Wiki :: ' . $this->page); | 				$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; | 				return $templateView; | ||||||
| 			} | 			} | ||||||
|  | |||||||
| @ -30,17 +30,16 @@ | |||||||
| 		 * @uses   addView() | 		 * @uses   addView() | ||||||
| 		 * | 		 * | ||||||
| 		 * @param WikiPageObject $page     The wiki page to display | 		 * @param WikiPageObject $page     The wiki page to display | ||||||
|  | 		 * @param DatabaseVendor $vendor   A database connection object | ||||||
| 		 * @param string         $action   The action to take | 		 * @param string         $action   The action to take | ||||||
| 		 * @param int            $priority The priority of the view | 		 * @param int            $priority The priority of the view | ||||||
| 		 * @param string         $pageName The name of the page | 		 * @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); | 			parent::__construct($page, $action, $priority); | ||||||
| 			 | 			 | ||||||
| 			$this->addView(new WikiPageMenuView($page, $action, 1)); | 			$this->addView(new WikiPageMenuView($page, $action, 1)); | ||||||
| 			 | 			 | ||||||
| 			$vendor = MySql::getInstance('wiki', 'localhost', 'root', 'layne', 'wiki'); |  | ||||||
| 			 |  | ||||||
| 			switch ($this->action) { | 			switch ($this->action) { | ||||||
| 				case 'new': | 				case 'new': | ||||||
| 					$this->addView(new WikiPageNewView($pageName, 2)); | 					$this->addView(new WikiPageNewView($pageName, 2)); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user