CodeInstrumentationClass.class.php
Go to the documentation of this file.00001 <?php
00015 class CodeInstrumentationClass extends CodeReflectionClass
00016 {
00021 protected $strName = null;
00022
00032 public function __construct( $strClassName, $strEvalContent = "" )
00033 {
00034 parent::__construct( $strClassName );
00035 if( $strEvalContent != "" )
00036 {
00037 new CodeReflectionFile( $this->getFileName() , $strEvalContent , false );
00038 }
00039 }
00040
00051 public function getClassName()
00052 {
00053 if( $this->strName == null )
00054 {
00055 return parent::getClassName();
00056 }
00057 else
00058 {
00059 return $this->strName;
00060 }
00061 }
00062
00077 public function setClassName( $strName )
00078 {
00079 $this->strName = $strName;
00080 return $this;
00081 }
00082
00096 public function createMethodsDefinitionCode()
00097 {
00098 if( $this->isInterface() )
00099 {
00100 return parent::createMethodsDefinitionCode();
00101 }
00102
00103 $strCode = '';
00104 $boolHasConstructor = false;
00105 $boolHasDestructor = false;
00106
00107 foreach( $this->getMethods() as $objMethodReflection )
00108 {
00109 if( $objMethodReflection->getName() == '__construct' )
00110 {
00111 $boolHasConstructor = true;
00112 }
00113 if( $objMethodReflection->getName() == '__destruct' )
00114 {
00115 $boolHasDestructor = true;
00116 }
00117 }
00118
00119 $strCode = parent::createMethodsDefinitionCode();
00120 if( $boolHasConstructor == false )
00121 {
00122 $strCode .= ' public function __construct() ' . "\n";
00123 $strCode .= ' { ' . "\n";
00124 $strCode .= ' $arrArguments = func_get_args(); ' . "\n";
00125 $strCode .= ' $mixReturn = null; ' . "\n";
00126 $strCode .= ' CodeInstrumentationReceiver::getInstance()->onEnterMethod( spl_object_hash($this) , __CLASS__ , __METHOD__ , $arrArguments );' . "\n";
00127 $strCode .= ' CodeInstrumentationReceiver::getInstance()->onLeaveMethod( spl_object_hash($this) , __CLASS__ , __METHOD__ , $mixReturn );' . "\n";
00128 $strCode .= ' } ' . "\n";
00129 }
00130 if( $boolHasDestructor == false )
00131 {
00132 $strCode .= ' public function __destruct() ' . "\n";
00133 $strCode .= ' { ' . "\n";
00134 $strCode .= ' $arrArguments = func_get_args(); ' . "\n";
00135 $strCode .= ' $mixReturn = null; ' . "\n";
00136 $strCode .= ' CodeInstrumentationReceiver::getInstance()->onEnterMethod( spl_object_hash($this) , __CLASS__ , __METHOD__ , $arrArguments );' . "\n";
00137 $strCode .= ' CodeInstrumentationReceiver::getInstance()->onLeaveMethod( spl_object_hash($this) , __CLASS__ , __METHOD__ , $mixReturn );' . "\n";
00138 $strCode .= ' } ' . "\n";
00139 }
00140 return $strCode;
00141 }
00142
00151 protected function createExtendedReflectionClass( ReflectionClass $objOriginalReflectionClass )
00152 {
00153 return new CodeInstrumentationClass( $objOriginalReflectionClass->getName() );
00154 }
00155
00164 protected function createExtendedReflectionProperty( ReflectionProperty $objOriginalReflectionProperty )
00165 {
00166 return new CodeInstrumentationProperty( $this->getName() , $objOriginalReflectionProperty->getName() );
00167 }
00168
00177 protected function createExtendedReflectionMethod( ReflectionMethod $objOriginalReflectionMethod )
00178 {
00179 return new CodeInstrumentationMethod( $this->getName() , $objOriginalReflectionMethod->getName() );
00180 }
00181 }
00182
00183 ?>