Skip to content

Commit

Permalink
Merge pull request #47 from TAMULib/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
jsavell authored Oct 25, 2016
2 parents ff20993 + 6b173e4 commit b5980ba
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions Core/Classes/Loaders/CoreLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ protected function getConfig() {
return $this->config;
}

/**
* Gets the Site context
* @return Core\Interfaces\Site The active Site implementation
*/
protected function getSite() {
return $this->site;
}

/**
* Sets the Site context
* @param Core\Interfaces\Site The active Site implementation
*/
protected function setSite($site) {
$this->site = $site;
}

/**
* load() is responsible for taking us from the request to the rendered response.
* - Kick off the seesion
Expand All @@ -62,17 +78,17 @@ public function load() {
* Check for and execute any $config requested redirects
*
*/
private function checkRedirect() {
protected function checkRedirect() {
if (!empty($this->getConfig()['forceRedirectUrl'])) {
$this->site->setRedirectUrl("{$this->getConfig()['forceRedirectUrl']}");
$this->site->redirect();
$this->getSite()->setRedirectUrl("{$this->getConfig()['forceRedirectUrl']}");
$this->getSite()->redirect();
}
}

/**
* Looks for a configured Site implementation to utilize, falls back to CoreSite if none are found
*/
private function loadSiteClass() {
protected function loadSiteClass() {
$site = null;
$config = $this->getConfig();
if (!empty($config['SITE_CLASS'])) {
Expand All @@ -87,19 +103,19 @@ private function loadSiteClass() {
$this->logger->error("Site Class not found");
exit;
}
$this->site = $site;
$this->setSite($site);
}

/**
* Finds an appropriate ViewRenderer and sets it up for use
*/
private function applyViewRenderer() {
protected function applyViewRenderer() {
//set the ViewRenderer
$config = $this->getConfig();
$inputData = $this->site->getSanitizedInputData();
$inputData = $this->getSite()->getSanitizedInputData();
$viewRendererFlag = false;
if (!empty($inputData['json'])) {
$this->site->setViewRenderer(new CoreClasses\ViewRenderers\JSONViewRenderer());
$this->getSite()->setViewRenderer(new CoreClasses\ViewRenderers\JSONViewRenderer());
$viewRendererFlag = true;
} else {
if (!empty($config['VIEW_RENDERER'])) {
Expand All @@ -112,7 +128,7 @@ private function applyViewRenderer() {
if (!$className) {
$className = "{$config['NAMESPACE_CORE']}Classes\\ViewRenderers\\HTMLViewRenderer";
}
$this->site->setViewRenderer(new $className($this->site->getGlobalUser(),$this->site->getPages(),$inputData,(!empty($config['controllerConfig']) ? $config['controllerConfig']['name']:null)));
$this->getSite()->setViewRenderer(new $className($this->getSite()->getGlobalUser(),$this->getSite()->getPages(),$inputData,(!empty($config['controllerConfig']) ? $config['controllerConfig']['name']:null)));
$viewRendererFlag = true;
}
if (!$viewRendererFlag) {
Expand All @@ -124,35 +140,35 @@ private function applyViewRenderer() {
/**
* Looks for the configured Controller and hands over control by executing its evaluate() method
*/
private function loadController() {
protected function loadController() {
//try to load the controller
$config = $this->getConfig();
$controller = null;
if (!empty($config['controllerConfig']['name'])) {
$className = $this->site->getControllerClass($config['controllerConfig']['name']);
$className = $this->getSite()->getControllerClass($config['controllerConfig']['name']);
if (class_exists($className)) {
$controller = new $className($this->site,$config['controllerConfig']);
$controller = new $className($this->getSite(),$config['controllerConfig']);
$controller->evaluate();
}
}
if (!$controller) {
$this->logger->warn("Did not find Controller Class");
$this->site->setRedirectUrl($config['PATH_HTTP']);
$this->getSite()->setRedirectUrl($config['PATH_HTTP']);
}
}

/**
* Asks the ViewRenderer to render the response
*/
private function render() {
if ($this->site->hasRedirectUrl()) {
$this->site->redirect();
protected function render() {
if ($this->getSite()->hasRedirectUrl()) {
$this->getSite()->redirect();
}
//send system messages to the ViewRenderer
$this->site->getViewRenderer()->registerAppContextProperty("systemMessages", $this->site->getSystemMessages());
$this->getSite()->getViewRenderer()->registerAppContextProperty("systemMessages", $this->getSite()->getSystemMessages());

//display the content
$this->site->getViewRenderer()->renderView();
$this->getSite()->getViewRenderer()->renderView();
}
}
?>

0 comments on commit b5980ba

Please sign in to comment.