EN | CS | Login | Register

(this page is translated by Google; We're working hard on a human translation)

Reflections

Nette\Reflection is a set of classes extending the standard classes reflective of PHP, especially on the annotation and some properties Nette\Object .

Reflection is a programmatic approach to certain reverse engineering. It allows us to identify such information as what properties and methods of the class has.

Types of reflection

There are several types of reflection:

For a detailed overview of available methods to study the API documentation and the PHP manual .

Getting reflection

Reflection can be obtained either directly by using its constructor ...

 // získání reflexe třídy Nette\Application\Presenter 
$classReflection = new Nette\Reflection\ClassReflection( 'Nette\Application\Presenter' );

// získání reflexe metody forward třídy Nette\Application\Presenter
$methodReflection = new Nette\Reflection\MethodReflection( 'Nette\Application\Presenter' , 'forward' );

... Or as the return value of "superior reflection":

 // získání reflexe metody forward třídy Nette\Application\Presenter 
$methodReflection = $classReflection ->getMethod( 'forward' );

Facilitate work with the reflection

Classes inheriting Nette\Object to the method getReflection () to facilitate work with reflections. This allows us to work so simply reflections

 class Foo extends Nette\Object 
{
/** @var string */
public $bar ;

public function getBarType()
{
return $this ->getReflection() //získáme objekt reflexe třídy Foo
->getProperty( 'bar' ) //získáme objekt reflexe vlastnosti bar
->getAnnotation( 'var' ); //získáme hodnotu anotace var
}
}

Login to submit a comment