class ReflectionSource implements Reflector

The source reflector

Traits

Basic implementation of the \Reflector::export() method
This trait defines magic getters and setters for read-only object's properties

Properties

static array $default_context

Methods

static  string|null
export( mixed $argument, bool $return = false)

Creation of a new instance of the mother class on-the-fly

void
setReadOnlyProperties( array $data)

Defines the read-only properties names and accessors.

mixed
__get( string $name)

Magic getter for read-only properties.

void
__set( string $name, mixed $value)

Magic setter to avoid setting read-only properties.

void
__unset( string $name)

Magic un-setter to avoid un-setting read-only properties.

__construct( string $file_path, null $lineno = null, array $context = null)

No description

string
getFilePath()

Returns the path of concerned file

int|null
getLineNo()

Returns the concerned line number (if defined)

array|mixed
getContext( null $item = null)

Returns the context or one of its items

mixed
getSource()

Get the source code of the file in a line-by-line array

string
render( bool $return = false, bool $info = false)

Renders the source as plain text

string
renderHighlight( bool $return = false, bool $info = false)

Renders the source highlighted in HTML

string
__toString()

Representation of the object

Details

in ReflectorTrait at line 54
static string|null export( mixed $argument, bool $return = false)

Creation of a new instance of the mother class on-the-fly

Keep in mind that this method only consider the FIRST argument passed to transmit to the constructor. If your mother class requires more than one argument, you will have to over-write this method (or to not use the trait).

Parameters

mixed $argument
bool $return

Return Value

string|null

Exceptions

ErrorException if the mother class does not implement the \Reflector interface
ErrorException if the mother class constructor is not callable

void setReadOnlyProperties( array $data)

Defines the read-only properties names and accessors.

Each key => value pair of the $data array must be constructed like:

  • key is the name of the property (MUST be defined with protected access in the child class)
  • value is an accessor for that property: the name of the access method if it exists or true for the default $obj->$key accessor.

Parameters

array $data This is the table of read-only properties

Return Value

void

Exceptions

InvalidArgumentException if the $data array is malformed

mixed __get( string $name)

Magic getter for read-only properties.

This will trigger a notice if the property can not be accessed.

Parameters

string $name

Return Value

mixed

void __set( string $name, mixed $value)

Magic setter to avoid setting read-only properties.

Parameters

string $name
mixed $value

Return Value

void

Exceptions

ReflectionException if trying to set a read-only property

void __unset( string $name)

Magic un-setter to avoid un-setting read-only properties.

Parameters

string $name

Return Value

void

Exceptions

ReflectionException if trying to unset a read-only property

at line 90
__construct( string $file_path, null $lineno = null, array $context = null)

Parameters

string $file_path The file path, which MUST exist
null $lineno An optional line of the file to work around
array $context A table with optional context info: - 'unified' is the number of lines taken around concerned one (default is 3) - 'highlighting' is the table of highlight settings colors (from php.ini: http://php.net/manual/misc.configuration.php#ini.syntax-highlighting) - 'function' can be concerned function name, to increase unified if necessary

Exceptions

ReflectionException if the $file_path parameter is not a string
ReflectionException if the file does not exist

at line 116
string getFilePath()

Returns the path of concerned file

Return Value

string

at line 126
int|null getLineNo()

Returns the concerned line number (if defined)

Return Value

int|null

at line 137
array|mixed getContext( null $item = null)

Returns the context or one of its items

Parameters

null $item

Return Value

array|mixed

at line 154
mixed getSource()

Get the source code of the file in a line-by-line array

The keys of the items are the line numbers, and a special on key is used if a line exists in the trace: on => line number.

Return Value

mixed

at line 199
string render( bool $return = false, bool $info = false)

Renders the source as plain text

Parameters

bool $return Return the result or not
bool $info Add the introduction information or not

Return Value

string

at line 220
string renderHighlight( bool $return = false, bool $info = false)

Renders the source highlighted in HTML

Parameters

bool $return Return the result or not
bool $info Add the introduction information or not

Return Value

string

at line 268
string __toString()

Representation of the object

If an exception is caught, its message is returned instead of the original result (but it is not thrown ahead).

Return Value

string