File: methods/test/test.php

Recommend this page to a friend!
  Classes of Chris Jeffries  >  PHP JSON RPC 2.0 Server  >  methods/test/test.php  >  Download  
File: methods/test/test.php
Role: Example script
Content type: text/plain
Description: Example method
Class: PHP JSON RPC 2.0 Server
Handle to HTTP requests in JSON RPC v2.0 format
Author: By
Last change:
Date: 2 years ago
Size: 2,699 bytes
 

Contents

Class file image Download
<?php
namespace test;
/***
 * test - to illustrate the writing of a method
 *
 * This stub illustrates how to create a method file.
 * Notice especially the 'namespace' declaration above. It should appear
 * in all your scripts that support the method. The namespace name must
 * be the same as the method name.
 * *
 * The 'main' function must be in a file with the same name as the
 * method and contain a function with the same name as the method.
 * In this case the method is 'test'.
 * *
 * This file must be in a sub-directory of the methods directory. The
 * sub-directory must also have the method name as its name.
 * *
 * Note also that method names are case-sensitive. 'Test' is NOT the
 * same as 'test'.
 * *
 * Notice also that on a Linux server you could have two methods
 * 'Test' and 'test', but on a Windows server this is not possible
 * since Windows will not you have sub-directories (or files) with the
 * names 'Test' and 'test' in the same directory.
 * *
 * It is a good idea, though not enforced, to give function and methods
 * in your code a header like this one (See PHPDocumenter for more
 * details)
 *
 * @param object $params- PHP encoded version of the 'params' property
 * of the call request. Note that dates will
 * arrive as strings
 *
 * @throws Exception Any error should be reported using throw.
 * The server will catch it and format a
 * JSON-RPC v2.0 compliant response to return to
 * the client. Your error should report a
 * message and a code number.
 * Errors are more verbose when the server is in
 * MaintenanceMode, giving the method name and
 * the file and line number where the error
 * occurred.
 *
 * @return object This should be a php object with properties
 * for each of the items you wish to send to
 * your client. Note that arrays with
 * non-numeric keys will be returned as objects
 * @version 0.1.1
 * @author Chris Jeffries
 * @copyright 2018 C G Jeffries
 * @licence https://www.gnu.org/licenses/gpl-3.0.en.html GPL, version 3
 ***/
function test($params)
{
    if(
false) {
       
//Getting data from some other method
       
$methodResult = call_method($methodname, $params);
       
//Getting data back from a service
       
$serviceResult = call_service($servicename, $params);
        throw new
Exception("Error message", $errorCode);
    }
    return
$params;
}
?>


For more information send a message to info at phpclasses dot org.