<?php defined('FOLDER_ROOT') || define('FOLDER_ROOT', realpath(dirname(__FILE__) . '/../')); defined('LIBRARY_ROOT') || define('LIBRARY_ROOT', FOLDER_ROOT . '/library/'); defined('SITE_ROOT') || define('SITE_ROOT', FOLDER_ROOT . '/public/'); defined('PROGRAM_ROOT') || define('PROGRAM_ROOT', FOLDER_ROOT . '/application/'); defined('ELEMENTS_ROOT') || define('ELEMENTS_ROOT', FOLDER_ROOT . '/elements/'); include LIBRARY_ROOT . 'Staple/Main.class.php'; $main = Staple_Main::get(); $main->run();
/** * * handleException catches Exceptions and displays an error page with the details. * @todo create and implement and error controller that can display custom errors * per application. * @param Exception $ex */ public function handleException(Exception $ex) { //handle the error $this->setLastException($ex); //Notify observers $this->notify(); //Clear the output buffer ob_clean(); //Get the Front Controller $main = Staple_Main::get(); //Process the Header $main->processHeader(true); //Echo the error message echo "<div class=\"section\"><div class=\"row\"><div class=\"small-12 columns\"><h1><i class=\"fi-alert\"></i> " . $ex->getMessage() . " Code: " . $ex->getCode() . "</h1></div></div></div>"; //Echo details if in dev mode if ($main->inDevMode()) { if (($p = $ex->getPrevious()) instanceof Exception) { echo "<p><b>Previous Error:</b> " . $p->getMessage . " Code: " . $p->getCode() . "</p>"; } echo "<pre>" . $ex->getTraceAsString() . "</pre>"; foreach ($ex->getTrace() as $traceln) { echo "<pre>"; var_dump($traceln); echo "</pre>"; } } //If the site uses layout, build the default layout and put the error message inside. if (Staple_Layout::layoutExists(Staple_Config::getValue('layout', 'default'))) { //Grab the current buffer contents to add to the layout $buffer = ob_get_contents(); ob_clean(); //Create the layout object and build the layout $layout = new Staple_Layout(Staple_Config::getValue('layout', 'default')); $layout->build($buffer); } }
/** * * If an array is supplied, a link is created to a controller/action. If a string is * supplied, a file link is specified. * @param string | array $link * @param array $get * @return string */ public function link($link, array $get = array()) { return Staple_Main::get()->link($link, $get); }
/** * * This function renders the view. If accepts a string representing the controller and * a string representing the requested action. With this information the correct view * is selected and rendered. * @param string $class * @param string $view */ public function build() { if ($this->_render === true) { //Load the view from the default loader $view = Staple_Main::get()->getLoader()->loadView($this->controller, $this->view); if (strlen($view) >= 1) { include $view; } } else { //skip rendering of an additional views $this->_render = false; } }
/** * * This function accepts a routing string to redirect the application internally. A * redirect of this sort clears the output buffer and redraws the header, proceeding * as if the redirected controller/action was called directly. * @param mixed $to */ protected function _redirect($to) { Staple_Main::get()->redirect($to); $this->view->noRender(); }
/** * * Dispatches to the AuthController -> index action. Throws an Exception if the controller does * not extend Staple_AuthController. * @throws Exception */ private function dispatchAuthController() { $conString = $this->_settings['controller']; $class = substr($conString, 0, strlen($conString) - 10); $authCon = Staple_Main::getController($class); if (!$authCon instanceof Staple_AuthController) { $authCon = new $conString(); } if ($authCon instanceof Staple_AuthController) { //Start the Controller $authCon->_start(); //Register Auth Controller with the Front Controller Staple_Main::get()->registerController($authCon); //Set the view's controller to match the route $authCon->view->setController($class); //Set the view's action to match the route $authCon->view->setView('index'); //Call the controller action, Send the route requested to the action //@todo Add option to customize the controller action call_user_func_array(array($authCon, 'index'), array(Staple_Main::getRoute())); //Grab the buffer contents from the controller and post it after the header. $buffer = ob_get_contents(); ob_clean(); //Process the header Staple_Main::get()->processHeader(); if ($authCon->layout instanceof Staple_Layout) { $authCon->layout->build($buffer); } else { echo $buffer; $authCon->view->build(); } } else { throw new Exception('Fatal Error connecting to Auth Controller', Staple_Error::AUTH_ERROR); } }
public function build($buffer = NULL) { if (isset($this->name)) { if (isset($buffer)) { $this->buffer = $buffer; } $layout = Staple_Main::get()->getLoader()->loadLayout($this->name); include $layout; } else { throw new Exception("Attempted to build unknown layout.", Staple_Error::APPLICATION_ERROR); } }