15,25 → 15,25 |
* @var string |
*/ |
protected $_controllerPath = 'application/controllers'; |
|
|
/** |
* Default controller of the application |
* @var string |
*/ |
protected $_defaultController = 'Index'; |
|
|
/** |
* Registry key for the default database of the application |
* @var string |
*/ |
protected $_defaultDatabase; |
|
|
/** |
* Currently active controller of this application |
* @var Controller |
*/ |
protected $_currentController; |
|
|
/** |
* Singleton |
* |
40,12 → 40,12 |
* @var Application |
*/ |
private static $_instance; |
|
|
protected function __construct() |
{ |
/* Singleton pattern */ |
} |
|
|
/** |
* Gets a reference to the <code>Application</code> instance |
* |
61,10 → 61,10 |
{ |
self::$_instance = ($instance === null) ? new self() : $instance; |
} |
|
|
return self::$_instance; |
} |
|
|
/** |
* Getter for properties |
* |
80,22 → 80,22 |
$class = get_class($this); |
return $class::${$name}; |
} |
|
|
$method = 'get' . ucfirst($name); |
|
|
if (method_exists($this, $method)) |
{ |
return $this->$method(); |
} |
|
|
if (property_exists($this, "_$name")) |
{ |
return $this->{"_$name"}; |
} |
|
|
return $this->$name; |
} |
|
|
/** |
* Setter for properties |
* |
106,21 → 106,21 |
public function __set($name, $value) |
{ |
$method = 'set' . ucfirst($name); |
|
|
if (method_exists($this, $method)) |
{ |
return $this->$method($value); |
} |
|
|
if (property_exists($this, "_$name")) |
{ |
$this->{"_$name"} = $value; |
return $this->{"_$name"}; |
} |
|
|
/* NOTE: Attempts to set other properties are _silently_ _ignored_ */ |
} |
|
|
/** |
* Runs the application, setting up session management and |
* constructing the controller indicated by the URI |
128,7 → 128,7 |
public function run() |
{ |
$this->startSession(); |
|
|
$controller = self::getParam('controller', $_REQUEST); |
if (!$controller) |
{ |
136,11 → 136,11 |
} |
|
$controller = ucfirst($controller); |
|
|
$controller = $controller . 'Controller'; |
require_once "{$this->_controllerPath}/{$controller}.php"; |
$this->_currentController = new $controller(); |
|
|
return $this; |
} |
|
148,7 → 148,7 |
{ |
session_start(); |
} |
|
|
/** |
* Gets a request parameter |
* |
167,29 → 167,26 |
{ |
$array = $_GET; |
} |
|
|
return isset($array[$key]) ? $array[$key] : null; |
} |
|
|
/** |
* Registers a database |
* |
* @param string $key |
* @param Database $database |
* @return string Registry key |
* @see Application::setDefaultDatabase() |
*/ |
public function registerDatabase ($key, Database $database) |
public function registerDatabase($key, Database $database) |
{ |
Registry::set($key, $database); |
return $key; |
} |
|
/** |
* Sets the default database |
* @param string Registry key to refer to the {@link Database} |
* @param key Registry key to refer to the {@link Database} |
*/ |
public function setDefaultDatabase ($key) |
public function setDefaultDatabase($key) |
{ |
$this->_defaultDatabase = $key; |
} |
205,7 → 202,7 |
$this->_currentController = $controller; |
return $this; |
} |
|
|
/** |
* Returns the current controller for this application |
* |
264,14 → 261,14 |
} |
} |
} |
|
|
$query = (($controller !== null) ? 'controller=' . $controller : '') |
. (($action !== null) ? '&action=' . $action : '') |
. (($id !== null) ? '&id=' . $id : ''); |
|
|
return $url . ($query ? '?' . $query : ''); |
} |
|
|
/** |
* Performs a server-side redirect within the application |
*/ |