Giter VIP home page Giter VIP logo

php-json-rpc's Introduction

PHP JSON-RPC Lib

##Build Status

Build Status

Version

The current version is considered Beta. This means that it is ready enough to test and use, but beware that you should update frequently.

As this software is BETA, Use at your own risk!

About

JSON-RPC Server/Client for PHP 5.3

Installation

PHAR

Download the latest phar build. Then, just require the phar in your code!

require_once '/path/to/JsonRpcLib.phar';

Composer

Add a composer.json file to your project with the following:

{
    "require": {
        "json-rpc-lib/json-rpc-lib": "dev-master"
    }
}

Then, inside that folder, just run php composer.phar install.

Then, in your code, just use the composer autoloader:

require_once 'vendor/autoload.php';

That's it!

Usage - Server

Most use-cases can simply use the root JsonRpcLib\Server\Server class.

<?php

require_once 'vendor/autoload.php';

$server = new \JsonRpcLib\Server\Server();

$server->addService($service);

$server->handle();

Service Closure

<?php

require_once 'vendor/autoload.php';

$server = new \JsonRpcLib\Server\Server();

$server->addService(function($a, $b) {
    return $a + $b;
}, 'sum'); // sum

$server->handle();

Service Object

<?php

require_once 'vendor/autoload.php';

class MockService {
    public function sum($a, $b) {
        return $a + $b;
    }
}

$service = new MockService();

$server = new \JsonRpcLib\Server\Server();
$server->addService($service); // sum
$server->handle();

or

<?php

// ...

$server->addService($service, 'math'); // math.sum

// ...

Multiple services

<?php

// ...

$server->addService($service, 'math'); // math.sum

$server->addService(function($data){
    // update data
}, 'update'); // update

$server->addService(function($a, $b){
    return $a + $b;
}, 'sum'); // sum

$server->addService($userService, 'user'); // user.getName, user.getSurname, user.*

// ...

Full configuration

<?php

$in = new JsonRpcLib\Server\Input\Data\Input();
$out = new JsonRpcLib\Server\Output\Data\Output();

$inputMessage = new JsonRpcLib\Server\Input\Message($in);
$outputMessage = new JsonRpcLib\Server\Output\Message($out);

$resolver = new \JsonRpcLib\Server\Service\Resolver\Resolver();

$manager = new JsonRpcLib\Server\Service\Manager\Manager($resolver);

$server = new JsonRpcLib\Server\Server($manager);

$server->addService(new \JsonRpcLib\Server\Service\Wrapper\ClosureWrapper($closure), 'getYear');
$server->addService(new \JsonRpcLib\Server\Service\Wrapper\ObjectWrapper($object), 'getName');

$server->dispatch($inputMessage, $outputMessage);

Design Goals

Well Designed

The code will use industry standard design patterns as well as follow guidelines for clean and testable code.

Well Tested

That means that the code should be well covered by unit tests.

Easy To Install

PHP JsonRpcLib will support two install methods. The first method is a single file PHAR archive. The second is support via Composer.

Easy To Extend

The library should be very easy to extend and add new functionality.

php-json-rpc's People

Contributors

marcinsoja avatar thecrissaegrim avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.