Documented some stuff, refactoring some other stuff
Moved re-used object instances to the Object class and added object loader logic to the constructor.
This commit is contained in:
parent
74f0adb4f8
commit
64dc006b5f
6 changed files with 77 additions and 68 deletions
|
@ -295,11 +295,11 @@ class Controller extends Object
|
|||
|
||||
if (!is_array($module_return))
|
||||
{
|
||||
$module_return = $module->return_data;
|
||||
$module_return = $module->return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$module_return = array_merge($module_return, $module->return_data);
|
||||
$module_return = array_merge($module_return, $module->return);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -310,7 +310,7 @@ class Controller extends Object
|
|||
}
|
||||
|
||||
// @todo Set this in the module and use $module->return and rename module->return to module->data?
|
||||
$module->return = ['template', 'json'];
|
||||
$module->display = ['template', 'json'];
|
||||
|
||||
// Checks if we have any templates
|
||||
$parent_template = $module->template;
|
||||
|
@ -334,8 +334,10 @@ class Controller extends Object
|
|||
}
|
||||
}
|
||||
|
||||
// @todo Should simplify this, give Display direct acess to
|
||||
// $module instead of all these variable assignment
|
||||
$display = new Display();
|
||||
$display->return = $module->return;
|
||||
$display->output = $module->output;
|
||||
$display->templates = $module->template;
|
||||
$display->module = isset($module_return) ? $module_return : ['status' => 'error', 'message' => $error_message];
|
||||
|
||||
|
|
|
@ -34,14 +34,6 @@ class Model extends Object
|
|||
*/
|
||||
private $model = null;
|
||||
|
||||
/**
|
||||
* Database Object
|
||||
*
|
||||
* @access protected
|
||||
* @var object
|
||||
*/
|
||||
protected $db = null;
|
||||
|
||||
/**
|
||||
* Columns
|
||||
*
|
||||
|
@ -52,14 +44,6 @@ class Model extends Object
|
|||
*/
|
||||
protected $columns = null;
|
||||
|
||||
/**
|
||||
* Cache Object
|
||||
*
|
||||
* @access
|
||||
* @var object
|
||||
*/
|
||||
protected $cache = null;
|
||||
|
||||
/**
|
||||
* Whether or not to use cache
|
||||
*
|
||||
|
@ -327,16 +311,14 @@ class Model extends Object
|
|||
}
|
||||
|
||||
// Runs the parent constructor so we have the config
|
||||
parent::__construct();
|
||||
parent::__construct(['cache', 'db']);
|
||||
|
||||
// Gets an instance of the database and check which it is
|
||||
$this->db = Database::getInstance();
|
||||
// Interrogates our database object
|
||||
$this->use_cache = $this->db->cache;
|
||||
$this->mysql = ($this->db->driver == 'pdo_mysql');
|
||||
$this->postgresql = ($this->db->driver == 'pdo_pgsql');
|
||||
|
||||
// Sets up the cache object and grabs the class name to use in our cache keys
|
||||
$this->cache = Cache::getInstance();
|
||||
// Grabs the class name to use in our cache keys
|
||||
$this->model = get_class($this);
|
||||
|
||||
// Default column mapping
|
||||
|
|
|
@ -27,28 +27,12 @@
|
|||
*/
|
||||
class Module extends Object
|
||||
{
|
||||
/**
|
||||
* Cache Object
|
||||
*
|
||||
* @access protected
|
||||
* @var object
|
||||
*/
|
||||
protected $cache = null;
|
||||
|
||||
/**
|
||||
* Database Object
|
||||
*
|
||||
* @access protected
|
||||
* @var object
|
||||
*/
|
||||
protected $db = null;
|
||||
|
||||
/**
|
||||
* Page Title
|
||||
*
|
||||
* @access protected
|
||||
* @var string, null by default
|
||||
* @todo Move to public scope
|
||||
* @todo Move to public scope, then abandon for $this->meta
|
||||
*/
|
||||
protected $title = null;
|
||||
|
||||
|
@ -57,7 +41,7 @@ class Module extends Object
|
|||
*
|
||||
* @access protected
|
||||
* @var string, null by default
|
||||
* @todo Move to public scope
|
||||
* @todo Move to public scope, then abandon for $this->meta
|
||||
*/
|
||||
protected $description = null;
|
||||
|
||||
|
@ -66,10 +50,21 @@ class Module extends Object
|
|||
*
|
||||
* @access protected
|
||||
* @var string, null by default
|
||||
* @todo Move to public scope
|
||||
* @todo Move to public scope, then abandon for $this->meta
|
||||
*/
|
||||
protected $keywords = null;
|
||||
|
||||
/**
|
||||
* Meta Data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $meta = [
|
||||
'title' => '',
|
||||
'description' => '',
|
||||
'keywords' => '',
|
||||
];
|
||||
|
||||
/**
|
||||
* Secure
|
||||
*
|
||||
|
@ -98,6 +93,9 @@ class Module extends Object
|
|||
* @access protected
|
||||
* @var boolean, false (not AJAX) by default
|
||||
* @todo Move to public scope
|
||||
* @todo Doesn't seem to be in use, but I have it defined on Clipinary
|
||||
* don't want to remove until I drop it else it would end up in the
|
||||
* module return array.
|
||||
*/
|
||||
protected $ajax = false;
|
||||
|
||||
|
@ -146,11 +144,20 @@ class Module extends Object
|
|||
* @access protected
|
||||
* @var array
|
||||
* @todo Move to public scope and rename __return so it's kinda obscured
|
||||
* @todo Will need to update leaderbin and sndcrd to use new variable
|
||||
*/
|
||||
protected $return_data = array();
|
||||
protected $return = array();
|
||||
|
||||
// @todo Document me
|
||||
public $return = array();
|
||||
/**
|
||||
* Output
|
||||
*
|
||||
* What should the class render as output? This can be a string or an array
|
||||
* containing either 'json', 'rss', 'template' or 'xml'. Default is to use
|
||||
* templates and if the template is not present, fall back to JSON.
|
||||
*
|
||||
* @var mixed string or array
|
||||
*/
|
||||
public $output = ['template', 'json'];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -165,10 +172,7 @@ class Module extends Object
|
|||
*/
|
||||
public function __construct($autorun = false, $validate = true)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->cache = Cache::getInstance();
|
||||
$this->db = Database::getInstance();
|
||||
parent::__construct(['cache', 'db']);
|
||||
|
||||
if ($autorun === true)
|
||||
{
|
||||
|
@ -217,7 +221,7 @@ class Module extends Object
|
|||
}
|
||||
else
|
||||
{
|
||||
$this->return_data[$name] = $value;
|
||||
$this->return[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,9 +29,9 @@ class Object
|
|||
*
|
||||
* @static
|
||||
* @access private
|
||||
* @var mixed
|
||||
* @var array
|
||||
*/
|
||||
protected static $instances = array();
|
||||
protected static $instances = [];
|
||||
|
||||
/**
|
||||
* Instance of the Config object
|
||||
|
@ -42,8 +42,23 @@ class Object
|
|||
protected $config = null;
|
||||
|
||||
/**
|
||||
* Profiler flag
|
||||
* Instance of the Cache object
|
||||
*
|
||||
* @access protected
|
||||
* @var object
|
||||
*/
|
||||
protected $cache = null;
|
||||
|
||||
/**
|
||||
* Instance of the Database object
|
||||
*
|
||||
* @access protected
|
||||
* @var object
|
||||
*/
|
||||
protected $db = null;
|
||||
|
||||
/**
|
||||
* Profiler flag
|
||||
*
|
||||
* @access private
|
||||
* @var mixed
|
||||
|
@ -55,7 +70,7 @@ class Object
|
|||
*
|
||||
* Establishes a Config instance for all children to enjoy
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct($objects = null)
|
||||
{
|
||||
// Gets an instance of the config, unless we ARE the config
|
||||
if (get_class($this) == 'Config')
|
||||
|
@ -67,6 +82,23 @@ class Object
|
|||
$this->config = Config::getInstance();
|
||||
}
|
||||
|
||||
if ($objects)
|
||||
{
|
||||
if (!is_array($objects))
|
||||
{
|
||||
$objects = [$objects];
|
||||
}
|
||||
|
||||
foreach ($objects as $object)
|
||||
{
|
||||
switch ($object)
|
||||
{
|
||||
case 'cache': $this->cache = Cache::getInstance(); break;
|
||||
case 'db': $this->db = Database::getInstance(); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Assigns the profiler flag
|
||||
$this->profiler = (isset($this->config->pickles['profiler']) && $this->config->pickles['profiler'] != '' ? $this->config->pickles['profiler'] : false);
|
||||
|
||||
|
|
|
@ -105,17 +105,6 @@ class Session extends Object
|
|||
*/
|
||||
private $table = null;
|
||||
|
||||
/**
|
||||
* Database
|
||||
*
|
||||
* Our database object to interact with the aforementioned datasource
|
||||
* and table. This object is shared with other PICKLES internals.
|
||||
*
|
||||
* @access private
|
||||
* @var object
|
||||
*/
|
||||
private $db = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue