<?php
require 'QAPI.class.php';
function globalFunc()
{
return 123;
}
function usedByAPI1($a)
{
return $a;
}
class API1 implements QAPI_Interface
{
public $value = 12;
function showIt($name)
{
return array(1, 2, 3, $name, $this->value);
}
function __call($name, $params)
{
if($name == 'use')
return call_user_func_array('usedByAPI1', $params);
}
}
$API1 = new API1;
$QAPI = new QAPI;
// register methods in $API1 as API1_methodName (in our sample - API1_showIt)
$QAPI->register($API1, '$_');
// register specific (non-foundable) method in $API1 - $API1->use()
$QAPI->register(array($API1, 'use'));
// register global function
$QAPI->register('globalFunc');
// fore registering all the classes that implement QAPI_Interface (just marker, no changes to classes are needed) could be used such code:
// $QAPI->register();
// Calling API method by name from $_GET['method'] with params from $_GET['params']
echo $QAPI->call($_GET['method']);
|