|
|
@@ -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');
|
|
|
|
|
|
?>
|