Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Chaning some strings to constants

  • Loading branch information...
commit 5a5ab48d46a32884506742be228a79ba348a28fa 1 parent c41af40
@tlhunter authored
Showing with 35 additions and 18 deletions.
  1. +10 −6 Core.php
  2. +2 −2 Error.php
  3. +23 −10 Request.php
View
16 Core.php
@@ -2,6 +2,10 @@
namespace Sleek;
class Core {
+ const CONTROLLER_PREFIX = '\\App\\Controller_';
+ const ACTION_PREFIX = 'action_';
+ const NO_ACTION = 'noAction';
+
/**
* @var string
*/
@@ -27,8 +31,8 @@ class Core {
*/
public function __construct() {
$request = Request::getInstance();
- $this->controllerName = '\\App\\Controller_' . $request->urlController();
- $this->actionName = 'action_' . $request->urlAction();
+ $this->controllerName = self::CONTROLLER_PREFIX . $request->urlController();
+ $this->actionName = self::ACTION_PREFIX . $request->urlAction();
$this->arguments = $request->urlArguments();
try {
@@ -42,10 +46,10 @@ public function __construct() {
$this->controller->preAction();
self::loadController($this->controller, $this->actionName, $this->arguments);
$this->controller->postAction();
- } else if (method_exists($this->controller, 'noAction')) {
+ } else if (method_exists($this->controller, self::NO_ACTION)) {
// If the controller exists, but the action doesn't, and we have a noAction, run that
$this->controller->preAction();
- self::loadController($this->controller, 'noAction', $this->arguments);
+ self::loadController($this->controller, self::NO_ACTION, $this->arguments);
$this->controller->postAction();
} else {
// Oh no, I can't find anything! Just run the 404 stuff!
@@ -59,7 +63,7 @@ public function __construct() {
* @return void
*/
public static function display404() {
- $errorControllerName = '\\App\\Controller_' . Config::get('error_controller');
+ $errorControllerName = self::CONTROLLER_PREFIX . Config::get('error_controller');
$errorController = new $errorControllerName;
self::loadController(
$errorController,
@@ -78,7 +82,7 @@ public static function display404() {
*/
public static function loadController($controller, $action, $arguments = array()) {
if (is_string($controller)) {
- $controller = '\\App\\Controller_' . $controller;
+ $controller = self::CONTROLLER_PREFIX . $controller;
}
call_user_func_array(
array(
View
4 Error.php
@@ -16,7 +16,7 @@ class Error {
* @return void
*/
public static function handler($errno, $errstr, $errfile, $errline, $errcontext) {
- $errorClassName = '\\App\\Controller_' . Config::get('error_controller');
+ $errorClassName = Core::CONTROLLER_PREFIX . Config::get('error_controller');
/**
* @var $errorClass \App\Controller_Error
*/
@@ -33,7 +33,7 @@ public static function handler($errno, $errstr, $errfile, $errline, $errcontext)
public static function shutdown() {
$error = error_get_last();
if ($error['type'] == 1) {
- $errorClassName = '\\App\\Controller_' . Config::get('error_controller');
+ $errorClassName = Core::CONTROLLER_PREFIX . Config::get('error_controller');
/**
* @var $errorClass \App\Controller_Error
*/
View
33 Request.php
@@ -3,6 +3,13 @@
class Request {
/**
+ * These values need to match the values used in the .htaccess file
+ */
+ const GET_VAR_CONTROLLER = 'controller';
+ const GET_VAR_ACTION = 'action';
+ const GET_VAR_ARGUMENTS = 'arguments';
+
+ /**
* @var Request The singleton instance of our request class
*/
static private $_instance = NULL;
@@ -10,16 +17,22 @@ class Request {
/**
* @var array Array containing URL data
*/
- static protected $url = array();
+ static protected $url = array();
/**
* Initializes the Request singleton, sets data from $_GET variables
*/
private function __construct() {
- self::$url['controller'] = (isset($_GET['controller']) ? ucfirst($_GET['controller']) : Config::get('default_controller'));
- self::$url['action'] = (isset($_GET['action']) ? $_GET['action'] : Config::get('default_action'));
- self::$url['arguments'] = isset($_GET['arg']) ? $_GET['arg'] : array();
- unset($_GET['controller'], $_GET['action'], $_GET['arg']); // This data shouldn't be available to GET
+ self::$url[self::GET_VAR_CONTROLLER] = (isset($_GET[self::GET_VAR_CONTROLLER]) ? ucfirst($_GET[self::GET_VAR_CONTROLLER]) : Config::get('default_controller'));
+ self::$url[self::GET_VAR_ACTION] = (isset($_GET[self::GET_VAR_ACTION]) ? $_GET[self::GET_VAR_ACTION] : Config::get('default_action'));
+ self::$url[self::GET_VAR_ARGUMENTS] = isset($_GET[self::GET_VAR_ARGUMENTS]) ? $_GET[self::GET_VAR_ARGUMENTS] : array();
+
+ // We don't want the URL paramaters accessible via GET
+ unset(
+ $_GET[self::GET_VAR_CONTROLLER],
+ $_GET[self::GET_VAR_ACTION],
+ $_GET[self::GET_VAR_ARGUMENTS]
+ );
}
/**
@@ -92,7 +105,7 @@ public function server($key) {
* @return string
*/
public function urlController() {
- return self::$url['controller'];
+ return self::$url[self::GET_VAR_CONTROLLER];
}
/**
@@ -100,7 +113,7 @@ public function urlController() {
* @return string
*/
public function urlAction() {
- return self::$url['action'];
+ return self::$url[self::GET_VAR_ACTION];
}
/**
@@ -112,12 +125,12 @@ public function urlAction() {
*/
public function urlArguments($index = NULL) {
if ($index != NULL) {
- if (isset(self::$url['arguments'][$index])) {
- return self::$url['arguments'][$index];
+ if (isset(self::$url[self::GET_VAR_ARGUMENTS][$index])) {
+ return self::$url[self::GET_VAR_ARGUMENTS][$index];
} else {
return NULL;
}
}
- return self::$url['arguments'];
+ return self::$url[self::GET_VAR_ARGUMENTS];
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.