CodeReflectionClass.class.php
Go to the documentation of this file.00001 <?php
00021 class CodeReflectionClass extends ExtendedReflectionClass
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
00046 public function getClassName()
00047 {
00048 $strName = parent::getName();
00049 $arrName = explode( "::" ,$strName) ;
00050 return array_pop( $arrName );
00051 }
00052
00058 public function getNamespace()
00059 {
00060 $strName = parent::getName();
00061 $arrName = explode( "::" ,$strName) ;
00062 return array_shift( $arrName );
00063 }
00064
00074 public final function getRealClassName()
00075 {
00076 $strName = ExtendedReflectionClass::getName();
00077 $arrName = explode( "::" ,$strName) ;
00078 return array_pop( $arrName );
00079 }
00080
00086 public function createClassDefinitionCode()
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 }
00107
00113 public function createAttributesDefinitionCode()
00114 {
00115 $strCode = "";
00116 $arrProperties = $this->getProperties();
00117 foreach( $arrProperties as $objReflectionProperty )
00118 {
00119
00120 $strCode .= $objReflectionProperty->getCode();
00121 }
00122 $arrConstants = $this->getConstants();
00123 foreach( $arrConstants as $strKey => $mixValue )
00124 {
00125
00126 $strCode .= "const " . $strKey . ' = ' . var_export( $mixValue , true ) . ";\n";
00127 }
00128 return $strCode;
00129 }
00130
00136 public function createMethodsDefinitionCode()
00137 {
00138 $strCode = "";
00139 $arrMethods = $this->getMethods();
00140 foreach( $arrMethods as $objReflectionMethod )
00141 {
00142
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 }
00157
00167 public function getCode()
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 }
00188
00197 protected function createExtendedReflectionClass( ReflectionClass $objOriginalReflectionClass )
00198 {
00199 return new CodeReflectionClass( $objOriginalReflectionClass->getName() );
00200 }
00201
00210 protected function createExtendedReflectionProperty( ReflectionProperty $objOriginalReflectionProperty )
00211 {
00212 return new CodeReflectionProperty( $this->getName() , $objOriginalReflectionProperty->getName() );
00213 }
00214
00223 protected function createExtendedReflectionMethod( ReflectionMethod $objOriginalReflectionMethod )
00224 {
00225 return new CodeReflectionMethod( $this->getName() , $objOriginalReflectionMethod->getName() );
00226 }
00227 }
00228
00229 ?>