CodeReflectionClass Class Reference

Inheritance diagram for CodeReflectionClass:

ExtendedReflectionClass ReflectionClass CodeInstrumentationClass

List of all members.

Public Member Functions

 __construct ($strClassName, $strEvalContent="")
 getClassName ()
 getNamespace ()
 getRealClassName ()
 createClassDefinitionCode ()
 createAttributesDefinitionCode ()
 createMethodsDefinitionCode ()
 getCode ()

Protected Member Functions

 createExtendedReflectionClass (ReflectionClass $objOriginalReflectionClass)
 createExtendedReflectionProperty (ReflectionProperty $objOriginalReflectionProperty)
 createExtendedReflectionMethod (ReflectionMethod $objOriginalReflectionMethod)


Detailed Description

Code reflection class it is a class what is a extension of the php reflection with improvments to show the php code of the reflected class

With this class you can see the code of some class, method, attribute just as it is and extending this class you can create a similary class of the original one.

This class can be used to debug, detail of some execution or stack and to code instrumentation.

Author:
Thiago Henrique Ramos da Mata <thiago.henrique.mata@gmail.com>

Definition at line 21 of file CodeReflectionClass.class.php.


Constructor & Destructor Documentation

__construct ( strClassName,
strEvalContent = "" 
)

Construct the Code Reflection of the class.

It must receive the eval content if the class it was created into a eval command.

Parameters:
string $strClassName
string $strEvalContent

Reimplemented in CodeInstrumentationClass.

Definition at line 32 of file CodeReflectionClass.class.php.

00033     {
00034         parent::__construct( $strClassName );
00035         if( $strEvalContent != "" )
00036         {
00037             new CodeReflectionFile( $this->getFileName() , $strEvalContent , false );
00038         }
00039     }


Member Function Documentation

createAttributesDefinitionCode (  ) 

Create a php attribute definition code

Returns:
string code of attribute

Definition at line 113 of file CodeReflectionClass.class.php.

References ExtendedReflectionClass::getProperties().

Referenced by getCode().

00114         {
00115                 $strCode = "";
00116                 $arrProperties = $this->getProperties();
00117                 foreach( $arrProperties as $objReflectionProperty )
00118                 {
00119                         /*@var $objReflectionProperty CodeReflectionProperty */
00120                         $strCode .= $objReflectionProperty->getCode();
00121                 }
00122         $arrConstants = $this->getConstants();
00123                 foreach( $arrConstants as $strKey => $mixValue )
00124                 {
00125                         /*@var $objReflectionProperty CodeReflectionProperty */
00126                         $strCode .= "const " . $strKey . ' = ' . var_export( $mixValue , true ) . ";\n";
00127                 }
00128                 return $strCode;
00129         }

createClassDefinitionCode (  ) 

Create a php class definition code

Returns:
string code of class creation

Definition at line 86 of file CodeReflectionClass.class.php.

References getClassName(), ExtendedReflectionClass::getInterfaces(), and ExtendedReflectionClass::getParentClass().

Referenced by getCode().

00087         {
00088                 $strCode = "";
00089                 $strCode .= " class " . $this->getClassName();
00090                 if( $this->getParentClass() != "" )
00091                 {
00092                         $strCode .= " extends " . $this->getParentClass()->getClassName();
00093                 }
00094                 if( sizeof( $this->getInterfaceNames() ) > 0)
00095                 {
00096                         $arrInterfacesClassName = array();
00097                         $arrInterfaces = $this->getInterfaces();
00098                         foreach(  $arrInterfaces as $objInterfaces )
00099                         {
00100                                 $arrInterfacesClassName[] = $objInterfaces->getClassName();
00101                         }
00102                         $strCode .= " implements " . implode( ", " , $arrInterfacesClassName );
00103                 }
00104                 $strCode .= "\n";
00105                 return $strCode;
00106         }

createExtendedReflectionClass ( ReflectionClass objOriginalReflectionClass  )  [protected]

Make the recursive calls and indirectly call return the extended reflection object and not a native reflection class.

See also:
ExtendedReflectionClass::createExtendedReflectionClass( ReflectionClass )
Parameters:
ReflectionClass $objOriginalReflectionClass
Returns:
CodeReflectionClass

Reimplemented from ExtendedReflectionClass.

Reimplemented in CodeInstrumentationClass.

Definition at line 197 of file CodeReflectionClass.class.php.

00198         {
00199                 return new CodeReflectionClass( $objOriginalReflectionClass->getName() );
00200         }

createExtendedReflectionMethod ( ReflectionMethod objOriginalReflectionMethod  )  [protected]

Make the recursive calls and indirectly call return the extended reflection object and not a native reflection method.

See also:
ExtendedReflectionClass::createExtendedReflectionMethod( ReflectionMethod )
Parameters:
ReflectionMethod $objOriginalReflectionClass
Returns:
CodeReflectionMethod

Reimplemented from ExtendedReflectionClass.

Reimplemented in CodeInstrumentationClass.

Definition at line 223 of file CodeReflectionClass.class.php.

00224         {
00225                 return new CodeReflectionMethod( $this->getName() , $objOriginalReflectionMethod->getName() );
00226         }

createExtendedReflectionProperty ( ReflectionProperty objOriginalReflectionProperty  )  [protected]

Make the recursive calls and indirectly call return the extended reflection object and not a native reflection property.

See also:
ExtendedReflectionClass::createExtendedReflectionProperty( ReflectionProperty )
Parameters:
ReflectionProperty $objOriginalReflectionClass
Returns:
CodeReflectionProperty

Reimplemented from ExtendedReflectionClass.

Reimplemented in CodeInstrumentationClass.

Definition at line 210 of file CodeReflectionClass.class.php.

00211         {
00212                 return new CodeReflectionProperty( $this->getName() , $objOriginalReflectionProperty->getName() );
00213         }

createMethodsDefinitionCode (  ) 

Create a php method definiton code

Returns:
string code of method

Reimplemented in CodeInstrumentationClass.

Definition at line 136 of file CodeReflectionClass.class.php.

References ExtendedReflectionClass::getMethods(), and getRealClassName().

Referenced by getCode().

00137         {
00138                 $strCode = "";
00139                 $arrMethods = $this->getMethods();
00140                 foreach( $arrMethods as $objReflectionMethod )
00141                 {
00142                         /*@var $objReflectionMethod CodeReflectionMethod */
00143             if( $objReflectionMethod->getDeclaringClass()->getRealClassName() == $this->getRealClassName())
00144                         {
00145                 if( !$this->isInterface() )
00146                 {
00147                     $strCode .= $objReflectionMethod->getCode();
00148                 }
00149                 else
00150                 {
00151                     $strCode .= $objReflectionMethod->createMethodHeaderCode();
00152                 }
00153             }
00154                 }
00155                 return $strCode;
00156         }

getClassName (  ) 

Get the class name

Returns:
string

Reimplemented in CodeInstrumentationClass.

Definition at line 46 of file CodeReflectionClass.class.php.

Referenced by createClassDefinitionCode().

00047         {
00048         $strName = parent::getName();
00049         $arrName = explode( "::" ,$strName) ;
00050                 return array_pop( $arrName );
00051         }

getCode (  ) 

Create the code of the reflected object

See also:
CodeReflectionClass::createClassDefinitionCode

CodeReflectionClass::createInterfaceDefinitionCode

CodeReflectionClass::createAttributesDefinitionCode

CodeReflectionClass::createMethodsDefinitionCode

Returns:
string code of the reflected object

Definition at line 167 of file CodeReflectionClass.class.php.

References createAttributesDefinitionCode(), createClassDefinitionCode(), and createMethodsDefinitionCode().

00168         {
00169         $strCode = "";
00170         if( !$this->isInterface() )
00171         {
00172             $strCode .= $this->createClassDefinitionCode();
00173             $strCode .= "{\n";
00174             $strCode .= $this->createAttributesDefinitionCode();
00175             $strCode .= $this->createMethodsDefinitionCode();
00176             $strCode .= "\n}\n";
00177         }
00178         else
00179         {
00180             $strCode .= $this->createInterfaceDefinitionCode();
00181             $strCode .= "{\n";
00182             $strCode .= $this->createAttributesDefinitionCode();
00183             $strCode .= $this->createMethodsDefinitionCode();
00184             $strCode .= "\n}\n";
00185         }
00186                 return $strCode;
00187         }

getNamespace (  ) 

Get the namespace name

Returns:
string

Definition at line 58 of file CodeReflectionClass.class.php.

00059         {
00060         $strName = parent::getName();
00061         $arrName = explode( "::" ,$strName) ;
00062                 return array_shift( $arrName );
00063         }

getRealClassName (  )  [final]

A version of the get class name what cannot be replaced.

Should be used when the execution need the real original class name

Returns:
string

Definition at line 74 of file CodeReflectionClass.class.php.

Referenced by createMethodsDefinitionCode().

00075     {
00076         $strName = ExtendedReflectionClass::getName();
00077         $arrName = explode( "::" ,$strName) ;
00078                 return array_pop( $arrName );
00079     }


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

Generated on Thu Feb 3 03:55:03 2011 for CodeToDiagram by  doxygen 1.5.9