hey all i want to use ReflectionClass to load some classes defined in my xml file
but i am getting an error
Error while register class :Class ReportErrorHandler does not exist
i will not get this error when i will use
require_once( 'handlers/system/ReportErrorHandler.php' );
but i dont want to require_once the class ,this is why i am using reflection and in my xml file i am writing only the class name with no full path ,so i cant dynamically 'require_once'
here is my code
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());
}
}
my xml file
<?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>