Sitellite Application Framework
Class Tree         Index         All Elements

Class: PHPShorthand

Source Location: Program_Root/Misc/Shorthand.php

Class Overview


Converts a shorthand code syntax into PHP code. The syntax is as follows:


Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 55]
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:


  • 1 foo.bar ('foo.bar')
    becomes

    1 $GLOBALS['foo']->bar ('foo.bar')

  • 1 not isset (someArray[keyname])
    becomes

    1 ! isset ($GLOBALS['someArray']['keyname'])

  • 1 foo.bar ge bar.foo and not empty (foo.asdf)
    becomes

    1 $GLOBALS['foo']->bar >= $GLOBALS['bar']->foo && ! empty ($GLOBALS['foo']->asdf)
Additionally, you can use the replaceGlobals() method to expand object references to refer to an alternate source, or even to add regular expression replacements to the list of existing syntax transformations, for example:


1 <?php
2
3 $sh = new PHPShorthand ();
4 $sh->replaceGlobals ('mypackage->private_register');
5 echo $sh->transform ('foo.bar ()');
6
7 ? >

This will output:


1 $mypackage->private_register['foo']->bar ()




[ Top ]


Class Variables

$pregReplacements = array (
            '/(\'|")([a-zA-Z0-9_-]+)(->|\[)/' => '\1\2.',

            '/(->|\[)(\'|")/' => '.\2',

            '/(\'|")(->|\[)/' => '\1.',

                  '/([ \(])([a-zA-Z0-9_-]+)(->|\[)/' => '\1$GLOBALS[\'\2\']\3',

            '/\[([a-zA-Z0-9_-]+)\]/' => '[\'\1\']',

            '/ ?not /i' => ' ! ',
   )

[line 99]

The list of preg_replace()-able tokens within the expression.


Type:   mixed


[ Top ]

$sprintfVars = array ()

[line 123]

The list of quoted parts of the current expression.


Type:   mixed


[ Top ]

$strReplacements = array (
      '&gt;' => '>',         '&lt;' => '<',         '.' => '->',         ' ->' => ' .',         '-> ' => '. ',         ' _ ' => ' . ',       ' 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 ' => ' * ',
         )

[line 60]

The list of str_replace()-able tokens within the expression.


Type:   mixed


[ Top ]



Class Methods


method replaceGlobals [line 135]

void replaceGlobals( string $newReg, [string $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.



Parameters:

string   $newReg  
string   $replace  

[ Top ]

method transform [line 172]

string transform( string $data)

Transforms the specified expression into valid PHP



Parameters:

string   $data  

[ Top ]


Copyright © 2007, SIMIAN systems Inc.
All rights reserved. Privacy policy
Documentation generated on Tue, 13 Feb 2007 17:19:19 -0600 by Sitellite AppDoc and phpDocumentor 1.2.2