Class Statement

Description

Processes variables and PHP blocks inside strings

A statement represents a string that can contain references to variables and pieces of PHP code. Based on a variable delimiter, the class parses the declared variables and offers an API to manually assign values to them or search them in the global scope.

The default variable syntax is "~variable~". That means that "~" and "~" are the prefix and suffix that identify a variable. A pair of "#" chars inside the delimiters represent a block of PHP code that should be evaluated.

Examples:

  1.  $st new Statement();
  2.  $st->setStatement("Hello, this is ~name~. I'm ~age~ years old.");
  3.  $st->bindByName('name''John'FALSE);
  4.  $st->bindByName('age'30);
  5.  $st->displayResult();
  6.  $st->setStatement("Hi, this is ~name~. Today is ~#date('d/m/Y')#~.");
  7.  $st->bindByName('name''Paul'FALSE);
  8.  $st->displayResult();

Located in /core/util/Statement.class.php (line 62)

PHP2Go
   |
   --Statement
Variable Summary
array $code
string $prefix
bool $prepared
string $result
string $source
string $suffix
array $variables
Method Summary
static string evaluate (string $value, [string $prefix = '~'], [string $suffix = '~'], [bool $showUnassigned = TRUE])
Statement Statement ([string $source = ''])
bool appendByName (string $variable, mixed $value, [bool $quote = TRUE])
bool bindByName (string $variable, mixed $value, [bool $quote = TRUE])
bool bindFromRequest (string $name, [bool $quote = TRUE], [string $searchOrder = NULL])
int bindVariables ([bool $quote = TRUE], [string $searchOrder = 'ROEGPCS'], [bool $replace = TRUE])
void debugVariables ([bool $pre = TRUE])
void displayResult ([bool $pre = TRUE])
void displayStatement ([bool $pre = TRUE])
array getDefinedVars ()
string getResult ()
string getStatement ()
mixed getVariableValue (string $variable)
bool isAllBound ()
bool isBound (string $variable)
bool isDefined (string $variable)
bool isEmpty ()
bool isPrepared ()
void loadFromFile (string $fileName)
void setShowUnassigned ([bool $setting = TRUE])
void setStatement (string $source)
void setVariablePattern ([string $prefix = ''], [string $suffix = ''])
void _parseStatement ()
Variables
array $code = array() (line 104)

Declared PHP blocks

string $prefix = '~' (line 83)

Variables prefix

bool $prepared = FALSE (line 118)

Is this an already parsed statement?

string $result = '' (line 76)

Statement result (after variables binding)

bool $showUnassigned = FALSE (line 111)

Whether unassigned variables should be displayed

string $source = '' (line 69)

Statement source

string $suffix = '~' (line 90)

Variables suffix

array $variables = array() (line 97)

Declared variables

Methods
static method evaluate (line 146)

Resolves all variables declared in a string based on the global scope

static string evaluate (string $value, [string $prefix = '~'], [string $suffix = '~'], [bool $showUnassigned = TRUE])
  • string $value: Statement's source
  • string $prefix: Variables prefix
  • string $suffix: Variables suffix
  • bool $showUnassigned: Show or hide unassigned variables
Constructor Statement (line 126)

Class constructor

Statement Statement ([string $source = ''])
  • string $source: Statement's source
appendByName (line 360)

Appends a value in a variable

bool appendByName (string $variable, mixed $value, [bool $quote = TRUE])
  • string $variable: Variable name
  • mixed $value: Value to append
  • bool $quote: Add double quotes if $value is a string
bindByName (line 309)

Assigns a value to a given variable

bool bindByName (string $variable, mixed $value, [bool $quote = TRUE])
  • string $variable: Variable name
  • mixed $value: Value
  • bool $quote: Whether double quotes should be added when $value is a string
bindFromRequest (line 330)

Tries to assign value to a variable from the global scope

The default search order is: ROEGPCS.

bool bindFromRequest (string $name, [bool $quote = TRUE], [string $searchOrder = NULL])
  • string $name: Variable name
  • bool $quote: Add quotes on string values
  • string $searchOrder: Search order
bindVariables (line 385)

Tries to assign values to all declared variables based on the global scope

For each declared variable, bindFromRequest is called. Inside it, the variable is searched in the superglobals POST, GET, SESSION, COOKIE and ENV, besides of being searched in the Registry singleton and in the session objects. The search order (which repository must be read first, and so on) is defined by the $searchOrder argument.

int bindVariables ([bool $quote = TRUE], [string $searchOrder = 'ROEGPCS'], [bool $replace = TRUE])
  • bool $quote: Add quotes on string values
  • string $searchOrder: Search order
  • bool $replace: Whether existent values should be replaced
debugVariables (line 402)

Prints debug information about all declared variables

void debugVariables ([bool $pre = TRUE])
  • bool $pre: Add PRE tags
displayResult (line 459)

Processes the statement and displays it

void displayResult ([bool $pre = TRUE])
  • bool $pre: Add PRE tags
displayStatement (line 171)

Display the statement's source

void displayStatement ([bool $pre = TRUE])
  • bool $pre: Add PRE tags or not
getDefinedVars (line 242)

Get all declared variables

array getDefinedVars ()
getResult (line 419)

Applies all variable values and returns the processed statement

string getResult ()
getStatement (line 162)

Get the statement's source

string getStatement ()
getVariablesCount (line 251)

Get the number of declared variables

int getVariablesCount ()
getVariableValue (line 261)

Gets the current value of a variable

mixed getVariableValue (string $variable)
  • string $variable: Variable name
isAllBound (line 290)

Check if all statement's variables are bound

bool isAllBound ()
isBound (line 281)

Checks if a given variable has a value

bool isBound (string $variable)
  • string $variable: Variable name
isDefined (line 271)

Checks if a given variable is declared

bool isDefined (string $variable)
  • string $variable: Variable name
isEmpty (line 233)

Checks if the statement contains any variables or code blocks

bool isEmpty ()
isPrepared (line 224)

Checks if the instance contains an already parsed statement

bool isPrepared ()
loadFromFile (line 193)

Loads the statement from a file

void loadFromFile (string $fileName)
  • string $fileName: File path
setShowUnassigned (line 215)

Enable/disable the display of unassigned variables

void setShowUnassigned ([bool $setting = TRUE])
  • bool $setting: Flag value
setStatement (line 180)

Restarts the object with a new statement

void setStatement (string $source)
  • string $source: Statement's source
setVariablePattern (line 203)

Set the variables pattern

void setVariablePattern ([string $prefix = ''], [string $suffix = ''])
  • string $prefix: Variables prefix
  • string $suffix: Variables suffix
_parseStatement (line 469)

Parses code blocks and variables from the statement's source

  • access: private
void _parseStatement ()

Inherited Methods

Inherited From PHP2Go

PHP2Go::PHP2Go()
PHP2Go::equals()
PHP2Go::generateUniqueId()
PHP2Go::getClassName()
PHP2Go::getConfigVal()
PHP2Go::getLangVal()
PHP2Go::getObjectName()
PHP2Go::getParentName()
PHP2Go::hasDestructor()
PHP2Go::hashCode()
PHP2Go::isA()
PHP2Go::isSubclassOf()
PHP2Go::logError()
PHP2Go::raiseError()
PHP2Go::registerDestructor()
PHP2Go::registerShutdownFunc()
PHP2Go::retrieve()
PHP2Go::store()
PHP2Go::__toString()

Documentation generated on Sun, 07 Oct 2007 19:29:49 -0300 by phpDocumentor 1.3.2