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))
|
if (!is_array($module_return))
|
||||||
{
|
{
|
||||||
$module_return = $module->return_data;
|
$module_return = $module->return;
|
||||||
}
|
}
|
||||||
else
|
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?
|
// @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
|
// Checks if we have any templates
|
||||||
$parent_template = $module->template;
|
$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 = new Display();
|
||||||
$display->return = $module->return;
|
$display->output = $module->output;
|
||||||
$display->templates = $module->template;
|
$display->templates = $module->template;
|
||||||
$display->module = isset($module_return) ? $module_return : ['status' => 'error', 'message' => $error_message];
|
$display->module = isset($module_return) ? $module_return : ['status' => 'error', 'message' => $error_message];
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ class Display extends Object
|
||||||
|
|
||||||
if (!is_array($this->return))
|
if (!is_array($this->return))
|
||||||
{
|
{
|
||||||
$this->return = [ $this->return ];
|
$this->return = [$this->return];
|
||||||
}
|
}
|
||||||
|
|
||||||
$return_json = $return_rss = $return_template = $return_xml = false;
|
$return_json = $return_rss = $return_template = $return_xml = false;
|
||||||
|
|
|
@ -34,14 +34,6 @@ class Model extends Object
|
||||||
*/
|
*/
|
||||||
private $model = null;
|
private $model = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* Database Object
|
|
||||||
*
|
|
||||||
* @access protected
|
|
||||||
* @var object
|
|
||||||
*/
|
|
||||||
protected $db = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Columns
|
* Columns
|
||||||
*
|
*
|
||||||
|
@ -52,14 +44,6 @@ class Model extends Object
|
||||||
*/
|
*/
|
||||||
protected $columns = null;
|
protected $columns = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* Cache Object
|
|
||||||
*
|
|
||||||
* @access
|
|
||||||
* @var object
|
|
||||||
*/
|
|
||||||
protected $cache = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not to use cache
|
* Whether or not to use cache
|
||||||
*
|
*
|
||||||
|
@ -327,16 +311,14 @@ class Model extends Object
|
||||||
}
|
}
|
||||||
|
|
||||||
// Runs the parent constructor so we have the config
|
// 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
|
// Interrogates our database object
|
||||||
$this->db = Database::getInstance();
|
|
||||||
$this->use_cache = $this->db->cache;
|
$this->use_cache = $this->db->cache;
|
||||||
$this->mysql = ($this->db->driver == 'pdo_mysql');
|
$this->mysql = ($this->db->driver == 'pdo_mysql');
|
||||||
$this->postgresql = ($this->db->driver == 'pdo_pgsql');
|
$this->postgresql = ($this->db->driver == 'pdo_pgsql');
|
||||||
|
|
||||||
// Sets up the cache object and grabs the class name to use in our cache keys
|
// Grabs the class name to use in our cache keys
|
||||||
$this->cache = Cache::getInstance();
|
|
||||||
$this->model = get_class($this);
|
$this->model = get_class($this);
|
||||||
|
|
||||||
// Default column mapping
|
// Default column mapping
|
||||||
|
|
|
@ -27,28 +27,12 @@
|
||||||
*/
|
*/
|
||||||
class Module extends Object
|
class Module extends Object
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Cache Object
|
|
||||||
*
|
|
||||||
* @access protected
|
|
||||||
* @var object
|
|
||||||
*/
|
|
||||||
protected $cache = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Database Object
|
|
||||||
*
|
|
||||||
* @access protected
|
|
||||||
* @var object
|
|
||||||
*/
|
|
||||||
protected $db = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page Title
|
* Page Title
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @var string, null by default
|
* @var string, null by default
|
||||||
* @todo Move to public scope
|
* @todo Move to public scope, then abandon for $this->meta
|
||||||
*/
|
*/
|
||||||
protected $title = null;
|
protected $title = null;
|
||||||
|
|
||||||
|
@ -57,7 +41,7 @@ class Module extends Object
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @var string, null by default
|
* @var string, null by default
|
||||||
* @todo Move to public scope
|
* @todo Move to public scope, then abandon for $this->meta
|
||||||
*/
|
*/
|
||||||
protected $description = null;
|
protected $description = null;
|
||||||
|
|
||||||
|
@ -66,10 +50,21 @@ class Module extends Object
|
||||||
*
|
*
|
||||||
* @access protected
|
* @access protected
|
||||||
* @var string, null by default
|
* @var string, null by default
|
||||||
* @todo Move to public scope
|
* @todo Move to public scope, then abandon for $this->meta
|
||||||
*/
|
*/
|
||||||
protected $keywords = null;
|
protected $keywords = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Meta Data
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $meta = [
|
||||||
|
'title' => '',
|
||||||
|
'description' => '',
|
||||||
|
'keywords' => '',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Secure
|
* Secure
|
||||||
*
|
*
|
||||||
|
@ -98,6 +93,9 @@ class Module extends Object
|
||||||
* @access protected
|
* @access protected
|
||||||
* @var boolean, false (not AJAX) by default
|
* @var boolean, false (not AJAX) by default
|
||||||
* @todo Move to public scope
|
* @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;
|
protected $ajax = false;
|
||||||
|
|
||||||
|
@ -146,11 +144,20 @@ class Module extends Object
|
||||||
* @access protected
|
* @access protected
|
||||||
* @var array
|
* @var array
|
||||||
* @todo Move to public scope and rename __return so it's kinda obscured
|
* @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
|
* Constructor
|
||||||
|
@ -165,10 +172,7 @@ class Module extends Object
|
||||||
*/
|
*/
|
||||||
public function __construct($autorun = false, $validate = true)
|
public function __construct($autorun = false, $validate = true)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct(['cache', 'db']);
|
||||||
|
|
||||||
$this->cache = Cache::getInstance();
|
|
||||||
$this->db = Database::getInstance();
|
|
||||||
|
|
||||||
if ($autorun === true)
|
if ($autorun === true)
|
||||||
{
|
{
|
||||||
|
@ -217,7 +221,7 @@ class Module extends Object
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->return_data[$name] = $value;
|
$this->return[$name] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,9 @@ class Object
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @access private
|
* @access private
|
||||||
* @var mixed
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected static $instances = array();
|
protected static $instances = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instance of the Config object
|
* Instance of the Config object
|
||||||
|
@ -42,8 +42,23 @@ class Object
|
||||||
protected $config = null;
|
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
|
* @access private
|
||||||
* @var mixed
|
* @var mixed
|
||||||
|
@ -55,7 +70,7 @@ class Object
|
||||||
*
|
*
|
||||||
* Establishes a Config instance for all children to enjoy
|
* 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
|
// Gets an instance of the config, unless we ARE the config
|
||||||
if (get_class($this) == 'Config')
|
if (get_class($this) == 'Config')
|
||||||
|
@ -67,6 +82,23 @@ class Object
|
||||||
$this->config = Config::getInstance();
|
$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
|
// Assigns the profiler flag
|
||||||
$this->profiler = (isset($this->config->pickles['profiler']) && $this->config->pickles['profiler'] != '' ? $this->config->pickles['profiler'] : false);
|
$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;
|
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
|
* Constructor
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue