Cradle  0.3.3
Simple library for creating Web-based applications
SimpleCodeParser Class Reference

Digger Simple PHP Code Parser. More...

Static Public Member Functions

static stripComments ($data)
 
static getNamespaces ($data)
 
static getFunctions ($data)
 
static getClassMethods ($data)
 
static getFirstBraceBlockPos ($data)
 
static getFirstBraceBlock ($data, $stripped=true)
 
static getObjects ($data)
 
static parseCode ($data)
 

Detailed Description

Digger Simple PHP Code Parser.

Parse source code of php-file and returns a hash array of code structure.

Version
3.0
Author
Digger mrdig.nosp@m.ger@.nosp@m.sad-s.nosp@m.yste.nosp@m.ms.ru

Example of usage:

require_once 'autoload.php';
use digger\cradle\common\SimpleCodeParser;
print_r( SimpleCodeParser::parseCode( file_get_contents('my_php_file.php') ) );

Member Function Documentation

static getClassMethods (   $data)
static

To find all methods of class into a source code of a given class

Parameters
string$dataText data contains a class source code.
Returns
array Array structure:
array(
"method1" => array(
"type" => static | abstract | "",
"scope" => private | protected | private ,
"params" => "parameters of methods"
)
"method2" => array( ... ),
...
)
static getFirstBraceBlock (   $data,
  $stripped = true 
)
static

Get the first brace block contains "{ ...some data... }"

Parameters
string$dataText data contains a class source code.
boolean$strippedIf TRUE: the first and the last braces wil be stripped from result.
Returns
string Data placed inside two braces ( { ...some data... } ).
static getFirstBraceBlockPos (   $data)
static

Get the first brace block positions contains { ...some data... }

Parameters
string$dataText data contains a class source code.
Returns
array Array structure:

array ( startPosition, endPosition )

static getFunctions (   $data)
static

To find all functions into a source code

Parameters
string$dataText data contains a source code.
Returns
array Array structure:
array(
"function1" => "parameters of function",
"function2" => "parameters of function",
...
)
static getNamespaces (   $data)
static

To split a source code into parts of namespases

Parameters
string$dataText data contains a source code.
Returns
array Array structure:
array(
"" => "...code inside the GLOBAL namespace...",
"namespace1" => "...code inside the namespace1...",
"namespace2" => "...code inside the namespace2...",
...
)
static getObjects (   $data)
static

To find all objects (classes and functions) into a source code

Parameters
string$dataText data contains a source code.
Returns
array Array structure:
array(
"classes" => array(
"class1" => array(
"method1" => array(
"type" => static | ...,
"scope" => private | protected | ... ,
"params" => "parameters of methods"
),
...
)
),
"functions" => array (
"function1" => "parameters of function",
...
)
)
static parseCode (   $data)
static

To parse a source code. It is a main method to use.

Parameters
string$dataText data contains a source code.
Returns
array Array structure:
array(
"namespace1" => array(
"classes" => array(
"class1" => array(
"method1" => array(
"type" => static | ...,
"scope" => private | protected | ... ,
"params" => "parameters of methods"
),
...
)
),
"functions" => array (
"function1" => "parameters of function",
...
)
),
...
)
static stripComments (   $data)
static

To strip input text data (code) of comments

Parameters
string$dataText data contains a source code.
Returns
string text Data without code comments (such as^ /* ... and //... ).

The documentation for this class was generated from the following file: