Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pquery
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
pquery
Commits
2198131d
Commit
2198131d
authored
13 years ago
by
Taddes Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added variable alias fucntionality.
parent
e96bbce1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pquery.php
+64
-23
64 additions, 23 deletions
pquery.php
pquery.sql.php
+6
-16
6 additions, 16 deletions
pquery.sql.php
with
70 additions
and
39 deletions
pquery.php
+
64
−
23
View file @
2198131d
...
...
@@ -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
This diff is collapsed.
Click to expand it.
pquery.sql.php
+
6
−
16
View file @
2198131d
...
...
@@ -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.
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment