04-14-2009, 03:00 PM
|
#8 (permalink)
|
|
The Visitor
Join Date: Jul 2008
Posts: 1
Thanks: 0
|
maybe it is faster to use the php functions class_exists, class_implements and method_exists
but I havent test that ... here my idea. Note I havent test this code.
PHP Code:
<?php
# ... your code ...
if(file_exists($szModulePath))
{
require_once($szModulePath);
if(class_exists($szModuleName, false) === true)
{
$interfaces = class_implements($szModuleName, false);
if($interfaces !== false && in_array('IModule', $interfaces))
{
if(method_exists($szModuleName, 'Main') === true)
{
# we have an static method available
$szModuleName::Main();
}
else
{
# whether non-static or not existing method
$instance = new $szModuleName();
if(method_exists($instance, 'Main') === true)
{
$instance->Main();
}
else
{
throw new Exception('main method not defined');
}
}
}
else
{
throw new Exception('File is not a valid module');
}
}
else
{
throw new Exception('Could not find module.');
}
}
?>
The fastest way is to trust your developers ... because it is necessary to prove whether a user has implement an interface?
|
|
|
|