/** * Main Function to Handle the HTTP Requests */ public function main() { // Creating controller Instance $controller = new HomeController(); if (isset($_GET['view'])) { switch ($_GET['view']) { case 'list': $controller->colorList(); break; case 'signin': $controller->signin(); break; case 'logout': $controller->logout(); break; case 'colors-list': $controller->getColorsList(); break; default: $controller->E404(); } } else { $controller->login(); } }
<?php use Controllers\HomeController; /** * Any User */ $controller = new HomeController(); $controller->getAuthor();
<?php /* * This file is part of the Knob-base package. * * (c) José María Valera Reales <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use Controllers\HomeController; /** * Search. * * @link https://codex.wordpress.org/Creating_a_Search_Page * @link https://codex.wordpress.org/Theme_Development */ $controller = new HomeController(); echo $controller->getSearch();
<?php use Controllers\HomeController; /** * Any Page by default */ $controller = new HomeController(); $controller->getPage();
<?php use Controllers\HomeController; /** * Any Page we don't know */ $controller = new HomeController(); $controller->getError();
<?php /* * This file is part of the Knob-base package. * * (c) José María Valera Reales <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use Controllers\HomeController; /** * Page. * * @link https://codex.wordpress.org/Page_Templates * @link https://codex.wordpress.org/Theme_Development */ $controller = new HomeController(); echo $controller->getSingle('page');
<?php use Controllers\HomeController; /** * Home Page */ $controller = new HomeController(); $controller->getHome();
<?php /* * This file is part of the Knob-base package. * * (c) José María Valera Reales <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use Controllers\HomeController; /** * Single. * * @link https://codex.wordpress.org/Theme_Development */ $controller = new HomeController(); echo $controller->getSingle('post');
<?php /* * This file is part of the Knob-base package. * * (c) José María Valera Reales <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use Controllers\HomeController; /** * Tag. * * @link https://codex.wordpress.org/Tag_Templates * @link https://codex.wordpress.org/Theme_Development */ $controller = new HomeController(); echo $controller->getTag();
<?php use Controllers\HomeController; /** * Any Post */ $controller = new HomeController(); $controller->getPost();
<?php /* * This file is part of the Knob-base package. * * (c) José María Valera Reales <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use Controllers\HomeController; /** * Home. * * @link https://codex.wordpress.org/Category_Templates * @link https://codex.wordpress.org/Theme_Development */ $controller = new HomeController(); echo $controller->getCategory();
/** * Return routes required by ControllerProviderInterface * * @param Application $app * * @return ControllerCollection */ public function connect(Application $app) { $controllers = $app['controllers_factory']; // controller level exception handler $exceptionHandler = function ($exception) use($app) { // CollectionValidatorException will be handled automatically for ALL controllers if ($exception instanceof CollectionValidatorException) { throw new HttpException($exception->getCode(), $exception->getMessage(), $exception); } if ($exception instanceof AssertException) { // rethrow this exception to let the app handle it throw $exception; } // 1. if we've made it here, just let the main exception handler handle this // 2. $app->abort() is just a short cut to throw an HttpException. // Here we also pass in the previous exception such that we can log all errors from the main exception handler. throw new HttpException(500, '', $exception); }; /* Description: Root of the api with a very long description and newlines that shouldn't break the generated code */ // GET / $controllers->get('/', function (Request $request) use($app, $exceptionHandler) { try { $parameters = array(); $validParameters = self::validateRequestParameters($parameters, $request); $data = \Controllers\HomeController::index(); if ($data instanceof Response) { return $data; } } catch (\Exception $exception) { // action level exception handler // controller level exception handler $exceptionHandler($exception); } // respond in json for now...probably shouldn't handle it from here $headers = array('Content-Type' => 'application/json'); return new Response(json_encode($data), 200, $headers); })->bind('home'); /* Description: Root of the api */ // POST /post $controllers->post('/post', function (Request $request) use($app, $exceptionHandler) { try { $parameters = array(); $validParameters = self::validateRequestParameters($parameters, $request); $data = \Controllers\HomeController::posted(); if ($data instanceof Response) { return $data; } } catch (\Exception $exception) { // action level exception handler // controller level exception handler $exceptionHandler($exception); } // respond in json for now...probably shouldn't handle it from here $headers = array('Content-Type' => 'application/json'); return new Response(json_encode($data), 200, $headers); })->bind('home.post'); return $controllers; }
<?php /* * This file is part of the Knob-base package. * * (c) José María Valera Reales <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use Controllers\HomeController; /** * 404. * * @link https://codex.wordpress.org/Creating_an_Error_404_Page * @link https://codex.wordpress.org/Theme_Development */ $controller = new HomeController(); echo $controller->get404();
<?php /* * This file is part of the Knob-base package. * * (c) José María Valera Reales <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use Controllers\HomeController; /** * Archive. * * @link https://codex.wordpress.org/Creating_an_Archive_Index * @link https://codex.wordpress.org/Theme_Development */ $controller = new HomeController(); echo $controller->getArchive();
/** * Get all posts * * @param integer $max * total posts to show * @return array<Post> */ public function getPosts($max = self::TOTAL_POSTS_TO_SHOW) { $moreQuerySettings['author'] = $this->ID; return HomeController::getPosts(Post::TYPE_POST, $max, [], false, $moreQuerySettings); }