php ReflectionClass

0 Cevap php

hey all i want to use ReflectionClass to load some classes defined in benim xml dosyası

ama bir hata alıyorum

Error while register class :Class ReportErrorHandler does not exist

i kullanma zaman ben bu hatayı almazsınız

require_once( 'handlers/system/ReportErrorHandler.php' );

but i dont want to require_once the class ,this is why i am using reflection and in benim xml dosyası i am writing only the class name with no full path ,so i cant dynamically 'require_once'

İşte benim kod

 public function init(){
$doc = new DOMDocument();
$doc->load( 'server.xml' );

$handlers = $doc->getElementsByTagName( "handler" );
foreach( $handlers as $handler ) {
  $this->register($handler->nodeValue);
}
}

public function register(&$name) {
try{
  $intercafe = new ReflectionClass('Handler');

  $reflectionClass = new ReflectionClass($name);

  if(!$reflectionClass->isSubclassOf($intercafe)){
    //LOG ERROR
    error_log("Init-> Error ," + name + " is not a subclass of [net/Handler]");

    throw new InvalidArgumentException();
  }

  error_log("register: " . $reflectionClass);

  $handler  = $reflectionClass->newInstance();
  $type = $handler->getType();

  //LOG DEBUG
  syslog(LOG_DEBUG ,"Registering handler = " . $name . " TYPE = " . $type);

  $key = $type << 32;

  $this->table[$key] = $reflectionClass;
}catch(Exception $ee){
  error_log("Error while register class :" . $ee->getMessage());
}
}

benim xml dosyası

<?xml version="1.0" encoding="UTF-8"?>
  <server>
     <server-version>0.1</server-version>

     <handlers>
       <handler>AuthenticateHandler</handler>
       <handler>ReportErrorHandler</handler>

       <handler>DisconnectedHandler</handler>
       <handler>NoSuchRequestHandler</handler>
     </handlers>
  </server>

0 Cevap