PHP Classes

File: QAPI_Sample.php

Recommend this page to a friend!
  Classes of Ingvar Stepanyan   QuickAPI   QAPI_Sample.php   Download  
File: QAPI_Sample.php
Role: Example script
Content type: text/plain
Description: Sample that shows using of QuickAPI
Class: QuickAPI
Implement an API with other classes or functions
Author: By
Last change:
Date: 13 years ago
Size: 1,062 bytes
 

Contents

Class file image Download
<?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']);