Class: PHPShorthand
- Package: saf.Misc
Converts a shorthand code syntax into PHP code. The syntax is as follows:
Case-insensitive keywords are replaced by their respective operators. These include:
- AND becomes "&&"
- NOT becomes "!"
- OR becomes "||"
- GT becomes ">"
- LT becomes "<"
- GE becomes ">="
- LE becomes "<="
- NE becomes "!="
- NEQ becomes "!=="
- EQ becomes "=="
- EQQ becomes "==="
- MOD becomes "%"
- X becomes "*"
- PLUS becomes "+"
In addition to this, the following translations happen:
- HTML entities for "<" and ">" are converted into their proper symbols
- "." is converted to "->"
- "_" is converted to "."
- "->" with a space on either side of it is converted back into a "."
- Object references are converted to $GLOBALS['object']->property
- Single- and double-quoted strings are handled as special cases and are not transformed.
- [key] array indexes are expanded to their quoted form of ['key']
Here are some examples of the conversion process:
- becomes
Usage Example
foo.bar ('foo.bar')
Properties
$vals
- Access: public
List of values to alternate between.
$counter
- Access: private
The internal position counter.
$current
- Access: private
Always keeps the value of the current array position here.
$headers = array ()
List of HTTP headers to be sent with the document. @see addHeader()
$meta = array ()
List of metadata attributes, which can be rendered as HTML meta tags using
the makeMeta() method. To render them into your XT templates, simply
add an xt:var tag with the name "makeMeta".
$scripts = array ()
List of javascript scripts, which can be rendered as HTML script tags using
the makeJavascript() method. To render them into your XT templates, simply
add an xt:var tag with the name "makeJavascript".
$styles = array ()
Array used to prevent duplicate loading of stylesheets.
$template_set = false
The template set to use for output.
$compiling = false
Whether compile() is underway or not.
$extra_head_elements = array ()
Extra elements to load in the <head> after the page is rendered.
$trues = array ('on', 'On', 'yes', 'Yes', 'true', 'True')
$falses = array ('off', 'Off', 'no', 'No', 'false', 'False')
$list = array ()
$iterator = 0
$strReplacements = array (
'>' => '>', // convert HTML '>' entity into proper symbol
'<' => '<', // convert HTML '<' entity into proper symbol
'.' => '->', // convert '.' into '->'
' ->' => ' .', // convert ' ->' back into ' .'
'-> ' => '. ', // convert '-> ' back into '. '
' _ ' => ' . ', // convert ' _ ' into ' . '
' AND ' => ' && ',
' and ' => ' && ',
' OR ' => ' || ',
' or ' => ' || ',
' GT ' => ' > ',
' gt ' => ' > ',
' GE ' => ' >= ',
' ge ' => ' >= ',
' LT ' => ' < ',
' lt ' => ' < ',
' LE ' => ' <= ',
' le ' => ' <= ',
' NE ' => ' != ',
' ne ' => ' != ',
' NEQ ' => ' !== ',
' neq ' => ' !== ',
' EQ ' => ' == ',
' eq ' => ' == ',
' EQQ ' => ' === ',
' eqq ' => ' === ',
' MOD ' => ' %% ',
' mod ' => ' %% ',
' PLUS ' => ' + ',
' plus ' => ' + ',
' X ' => ' * ',
' x ' => ' * ',
// see below for NOT => !
)
'>' => '>', // convert HTML '>' entity into proper symbol
'<' => '<', // convert HTML '<' entity into proper symbol
'.' => '->', // convert '.' into '->'
' ->' => ' .', // convert ' ->' back into ' .'
'-> ' => '. ', // convert '-> ' back into '. '
' _ ' => ' . ', // convert ' _ ' into ' . '
' AND ' => ' && ',
' and ' => ' && ',
' OR ' => ' || ',
' or ' => ' || ',
' GT ' => ' > ',
' gt ' => ' > ',
' GE ' => ' >= ',
' ge ' => ' >= ',
' LT ' => ' < ',
' lt ' => ' < ',
' LE ' => ' <= ',
' le ' => ' <= ',
' NE ' => ' != ',
' ne ' => ' != ',
' NEQ ' => ' !== ',
' neq ' => ' !== ',
' EQ ' => ' == ',
' eq ' => ' == ',
' EQQ ' => ' === ',
' eqq ' => ' === ',
' MOD ' => ' %% ',
' mod ' => ' %% ',
' PLUS ' => ' + ',
' plus ' => ' + ',
' X ' => ' * ',
' x ' => ' * ',
// see below for NOT => !
)
The list of str_replace()-able tokens within the expression.
$pregReplacements = array (
// convert '"somename->' or '"somename[' back into '"somename.'
'/(\'|")([a-zA-Z0-9_-]+)(->|\[)/' => '\1\2.',
// convert '->"' back into '".'
'/(->|\[)(\'|")/' => '.\2',
// convert '"->' back into '".'
'/(\'|")(->|\[)/' => '\1.',
// convert ' somename->' or '(somename['
// into ' $somevar->' or '($somevar['
'/([ \(])([a-zA-Z0-9_-]+)(->|\[)/' => '\1$GLOBALS[\'\2\']\3',
// convert '[somevar]' to '['somevar']'
'/\[([a-zA-Z0-9_-]+)\]/' => '[\'\1\']',
// not to !
'/ ?not /i' => ' ! ',
)
// convert '"somename->' or '"somename[' back into '"somename.'
'/(\'|")([a-zA-Z0-9_-]+)(->|\[)/' => '\1\2.',
// convert '->"' back into '".'
'/(->|\[)(\'|")/' => '.\2',
// convert '"->' back into '".'
'/(\'|")(->|\[)/' => '\1.',
// convert ' somename->' or '(somename['
// into ' $somevar->' or '($somevar['
'/([ \(])([a-zA-Z0-9_-]+)(->|\[)/' => '\1$GLOBALS[\'\2\']\3',
// convert '[somevar]' to '['somevar']'
'/\[([a-zA-Z0-9_-]+)\]/' => '[\'\1\']',
// not to !
'/ ?not /i' => ' ! ',
)
The list of preg_replace()-able tokens within the expression.
$sprintfVars = array ()
The list of quoted parts of the current expression.
Methods
replaceGlobals ($newReg, $replace = false)
Replaces the keyword GLOBALS with the specified $newReg in all
regexp transformations. Alternately, if $replace is provided, it
will add a new regular expression to the list of transformations
to perform.
addSprintf ($data, $quote = "'")
- Access: private
- Return: string
Adds a quoted value to the $sprintfVars list and returns a quoted %s
for temporary insertion into an expression. This allows vsprintf()
to be used to expand quoted strings from an expression into their
original form, untouched by the transformations being performed
to the expression.
transform ($data)
- Return: string
Transforms the specified expression into valid PHP
