PHP code example of flc / laravel-hprose

1. Go to this page and download the library: Download flc/laravel-hprose library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

flc / laravel-hprose example snippets


    'providers' => [

        ...

        Flc\Laravel\Hprose\HproseServiceProvider::class,
    ]
    

    'aliases' => [

        ...

        'HproseRoute' => Flc\Laravel\Hprose\Facades\HproseRoute::class,
        'HproseServer' => Flc\Laravel\Hprose\Facades\HproseServer::class,
        'HproseClient' => Flc\Laravel\Hprose\Facades\HproseClient::class,
    ]
    

'providers' => [

    ...

    App\Providers\HproseRouteServiceProvider::class,
]



return [
    'server' => [
        'default'     => 'http',
        'connections' => [
            'http' => [
                'protocol' => 'http',
            ],
        ],
    ],

    'client' => [
        'default'     => 'http',
        'connections' => array(
            'http' => array(
                'protocol' => 'http',
                'uri'      => 'http://192.168.2.67:9001/api/server',  // 此处为服务端的连接地址
                'async'    => false,
            ),
        ),
    ]
];



Route::any('hprose-server', 'HproseController@server');



namespace App\Http\Controllers;

use HproseServer;
use HproseRoute;

class HproseController
{
    public function server()
    {
        HproseServer::setRouter(HproseRoute::getRouter())->start();
    }
}



HproseRoute::add('tests', 'Controller@tests');
HproseRoute::add('tests_one', 'Controller@tests')->option(['...']);



namespace App\Http\Controllers;

use HproseClient;

class HproseController
{
    public function client()
    {
        $result = HproseClient::tests('tests');
        $result = HproseClient::connection('other')->tests('tests');  // 其他连接
        $result = HproseClient::connection()->tests->one('tests');

        print_r($result);
    }
}



$router = new \Flc\Laravel\Hprose\Routing\Router;
$router->group(['prefix' => 'tests', 'namespace' => 'App\\Controllers'], function ($router) {
    $router->add('one', 'Controller@one');
    $router->add('two', 'Controller@two')->option(['...']);

    $router->group(['prefix' => 'group'], function ($router) {
        $router->add('one', 'Controller@group_one');

        ...

    });
});

$app = [
    'config' => [
        'hprose.server.default' => 'http',
        'hprose.server.connections' => [
            'http' => [
                'protocol' => 'http',
            ],
        ],
    ],
];

$server = new \Flc\Laravel\Hprose\Server($app);
$server->setRouter($router)->start();


$app = [
    'config' => [
        'hprose.client.default' => 'http',
        'hprose.client.connections' => [
            'http' => [
                'protocol' => 'http',
                'uri'      => 'http://localhost/server.php',
                'async'    => false
            ]
        ]
    ]
];

$client = new \Flc\Laravel\Hprose\Client($app);

print_r($client->tests->one('222').PHP_EOL);
sh
php artisan hprose:generator
sh
php artisan vendor:publish --provider="Flc\Laravel\Hprose\HproseServiceProvider"