Skip to content
Snippets Groups Projects
Commit 2198131d authored by Taddes Kroes's avatar Taddes Kroes
Browse files

Added variable alias fucntionality.

parent e96bbce1
No related branches found
No related tags found
No related merge requests found
......@@ -47,6 +47,20 @@ class pQuery {
*/
static $accepts = array('boolean', 'integer', 'double', 'string', 'array', 'object', 'NULL');
/**
* A list of names of plugins that are required to run a plugin.
*
* @var array
*/
static $require_plugins = array();
/**
* Aliases for the variable setter and getter.
*
* @var string|array
*/
static $variable_alias = array();
/**
* The current variable.
*
......@@ -128,6 +142,40 @@ class pQuery {
return $obj;
}
/**
* Try to load the file containing the utility class for a specific variable type.
*
* @param mixed $type the variable type of the class to load.
*/
static function load_plugin($type) {
$path = PQUERY_ROOT.sprintf(self::PLUGIN_FILENAME_PATTERN, $type);
if( !file_exists($path) )
return false;
include_once $path;
return true;
}
/**
* Include the nescessary files for the given plugins.
*/
static function require_plugins(/* $plugin1 [ , $plugin2, ... ] */) {
$plugins = func_get_args();
foreach( $plugins as $plugin ) {
$path = PQUERY_ROOT.sprintf(self::PLUGIN_FILENAME_PATTERN, $plugin);
if( !file_exists($path) ) {
return self::error('Required plugin "%s" could not be located (looked in "%s").',
$plugin, $path);
}
include_once $path;
}
}
/**
* Parse the type of the given variable, and convert it if needed.
*
......@@ -158,37 +206,27 @@ class pQuery {
}
/**
* Try to load the file containing the utility class for a specific variable type.
* Getter for {@link variable}.
*
* @param mixed $type the variable type of the class to load.
* @see variable_alias
*/
static function load_plugin($type) {
$path = PQUERY_ROOT.sprintf(self::PLUGIN_FILENAME_PATTERN, $type);
if( !file_exists($path) )
return false;
include_once $path;
function __get($name) {
$class_name = get_class($this);
return true;
if( in_array($name, (array)$class_name::$variable_alias) )
return $this->variable;
}
/**
* Include the nescessary files for the given plugins.
* Setter for {@link variable}.
*
* @see variable_alias
*/
static function require_plugins(/* $plugin1 [ , $plugin2, ... ] */) {
$plugins = func_get_args();
function __set($name, $value) {
$class_name = get_class($this);
foreach( $plugins as $plugin ) {
$path = PQUERY_ROOT.sprintf(self::PLUGIN_FILENAME_PATTERN, $plugin);
if( !file_exists($path) ) {
return self::error('Required plugin "%s" could not be located (looked in "%s").',
$plugin, $path);
}
include_once $path;
}
if( in_array($name, (array)$class_name::$variable_alias) )
$this->variable = $value;
}
}
......@@ -231,6 +269,9 @@ function _p($variable, $plugin=null) {
return new $class_name($variable);
}
/**
* Set an alias for the bas class consistent with plugin aliases.
*/
class_alias('pQuery', '__p');
?>
\ No newline at end of file
......@@ -21,6 +21,12 @@ class pQuerySql extends pQuery implements pQueryExtension {
*/
static $link;
/**
* @see pQuery::$variable_alias
* @var string|array
*/
static $variable_alias = 'query';
/**
* The result of the current query.
*
......@@ -158,22 +164,6 @@ class pQuerySql extends pQuery implements pQueryExtension {
return $func($this->result);
}
/**
* Getter for property 'query'.
*/
function __get($name) {
if( $name == 'query' )
return $this->variable;
}
/**
* Setter for property 'query'.
*/
function __set($name, $value) {
if( $name == 'query' )
$this->variable = $value;
}
/**
* Assert that the current query has been executed.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment