00001 <?php 00014 class CodeReflectionMethod extends ExtendedReflectionMethod 00015 { 00016 00022 public function getCode() 00023 { 00024 $strCode = ""; 00025 $strCode .= $this->createMethodHeaderCode(); 00026 $strCode .= "{"; 00027 $strCode .= $this->createMethodContentCode(); 00028 $strCode .= "}\n"; 00029 00030 return $strCode; 00031 } 00032 00038 public function getCodeContent() 00039 { 00040 return $this->createMethodContentCode(); 00041 } 00042 00051 protected function createExtendedReflectionClass( ReflectionClass $objOriginalReflectionClass ) 00052 { 00053 return new CodeReflectionClass( $objOriginalReflectionClass->getName() ); 00054 } 00055 00064 protected function createExtendedReflectionParameter( ReflectionParameter $objReflectionParameter ) 00065 { 00066 return new CodeReflectionParameter( Array( $this->getDeclaringClass()->getName() , $this->getName() ) , $objReflectionParameter->getName() ); 00067 } 00068 00074 protected function createModifiersCode() 00075 { 00076 $strCode = ""; 00077 if( $this->isFinal() ) 00078 { 00079 $strCode .= " final "; 00080 } 00081 if( $this->isPrivate() ) 00082 { 00083 $strCode .= " private "; 00084 } 00085 if( $this->isProtected()) 00086 { 00087 $strCode .= " protected "; 00088 } 00089 if( $this->isPublic()) 00090 { 00091 $strCode .= " public "; 00092 } 00093 if( $this->isStatic() ) 00094 { 00095 $strCode .= " static "; 00096 } 00097 return $strCode; 00098 } 00099 00105 protected function createParametersCode() 00106 { 00107 $strCode = ""; 00108 $arrParameters = $this->getParameters(); 00109 $arrParametersName = array(); 00110 00111 foreach( $arrParameters as $objParameter ) 00112 { 00113 /*@var $objParameter CodeReflectionParameter */ 00114 $arrParametersName[] = $objParameter->getCode(); 00115 } 00116 00117 $strCode .= "("; 00118 $strCode .= implode( ", " , $arrParametersName); 00119 $strCode .= ")"; 00120 return $strCode; 00121 } 00122 00128 public function createMethodHeaderCode() 00129 { 00130 $strCode = $this->getDocComment(); 00131 $strCode .= $this->createModifiersCode(); 00132 $strCode .= " function "; 00133 $strCode .= $this->getName(); 00134 $strCode .= $this->createParametersCode(); 00135 00136 return CorujaStringManipulation::retab( $strCode , 1 ); 00137 } 00138 00144 protected function createMethodContentCode() 00145 { 00146 $strCode = ""; 00147 00148 $strFileName = $this->getFileName(); 00149 00150 $objFile = CodeReflectionFile::getCodeInstrFileName( $strFileName ); 00151 00152 $strCode = $objFile->getFileBit( $this->getStartLine() , $this->getEndLine() ); 00153 00154 $strCode = trim( $strCode ); 00155 00156 // remove the { } 00157 if( $strCode[0] == "{" ) 00158 { 00159 $strCode = substr( $strCode , 1 , -1); 00160 } 00161 return $strCode; 00162 } 00163 } 00164 ?>
1.5.9