/** @param int $offset */ protected function parseRequestVars($offset) { if ($_SERVER["REQUEST_METHOD"] === "GET") { CleanRequestUrlParser::instance()->parseGetVars($offset); } else { // assume it is a "POST" CleanRequestUrlParser::instance()->parsePostVars($offset); } }
/** Date and Title will be parsed assuming the * Request Url is in the format /path/to/module/<date_str>/<title_str> * For Example: /post/1989-05-24/this-is-a-post-title * * @param int $offset */ protected function parseRequestVars($offset) { $explodedCleanRequestUrl = CleanRequestUrlParser::instance()->getExplodedCleanRequestUrl(); if ($_SERVER["REQUEST_METHOD"] === "GET") { $_GET['date'] = empty($explodedCleanRequestUrl[$offset + 0]) ? null : $explodedCleanRequestUrl[$offset + 0]; $_GET['title'] = empty($explodedCleanRequestUrl[$offset + 1]) ? null : $explodedCleanRequestUrl[$offset + 1]; } else { // assume it is a "POST" $_POST['date'] = empty($explodedCleanRequestUrl[$offset + 0]) ? null : $explodedCleanRequestUrl[$offset + 0]; $_POST['title'] = empty($explodedCleanRequestUrl[$offset + 1]) ? null : $explodedCleanRequestUrl[$offset + 1]; } }
public function test_parsePostVars() { $_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['REQUEST_URI'] = '/home/page/1'; /** @var CleanRequestUrlParser $cleanRequestUrlParser */ require_once 'components/CleanRequestUrlParser.php'; $cleanRequestUrlParser = CleanRequestUrlParser::instance(); $cleanRequestUrlParser->parsePostVars(1); $this->assertEquals(count($_POST), 1); $this->assertArrayHasKey('page', $_POST); $this->assertEquals($_POST['page'], '1'); }
function __construct($title, $subtitle, $author_name, $created, $body_text) { // detect if we need to populate with test data if (empty(CleanRequestUrlParser::instance()->getExplodedCleanRequestUrl()[1])) { $this->populateWithTestData(); } else { $this->title = $title; $this->subtitle = $subtitle; $this->author = $author_name; $this->date = $created; $this->postBody = $body_text; } }
public function routeToModuleController() { $explodedCleanRequestUrl = CleanRequestUrlParser::instance()->getExplodedCleanRequestUrl(); $moduleToRun = $this->getModuleNameFromRequestUrl($explodedCleanRequestUrl); // return the correct intialized module's controller $controllerUrlRegex = $this->moduleToControllerMap[$moduleToRun][1]; $controllerName = $this->moduleToControllerMap[$moduleToRun][0]; $defaultControllerName = $this->moduleToControllerMap['notfound'][0]; if (!preg_match($controllerUrlRegex, CleanRequestUrlParser::instance()->getCleanRequestUrl())) { $controllerName = $defaultControllerName; } require_once 'controllers/' . $controllerName . '.php'; $fullyQualifiedControllerName = 'framework\\controllers\\' . $controllerName; return new $fullyQualifiedControllerName(array_slice($explodedCleanRequestUrl, 0, 1)); }