PHP code example of duan617 / laravel-hprose

1. Go to this page and download the library: Download duan617/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/ */

    

duan617 / laravel-hprose example snippets


    'providers' => [
        // ...

        duan617\LaravelHprose\ServiceProvider::class,
    ]
    

    'aliases' => [
        // ...

        'LaravelHproseMethodManage' => duan617\LaravelHprose\Facades\HproseMethodManage::class,
    ]
    

    'uris' => json_decode(env('HPROSE_URIS', '["tcp://0.0.0.0:1314"]')),
    

    'demo' => env('HPROSE_DEMO'),
    

    'parameter' => 'App\\Controllers\\Parameters'
    

    'controller' => 'App\\Controllers',
    

\LaravelHproseRouter::add(string $name, string|callable $action, array $options = []);

\LaravelHproseRouter::add('getUserByName', function ($name) {
    return 'name: ' . $name;
});

\LaravelHproseRouter::add('userUpdate', 'App\Controllers\User@update', ['model' => \Hprose\ResultMode::Normal]);



namespace App\Controllers;

class User
{
    public function update($name)
    {
        return 'update name: ' . $name;
    }
}

\LaravelHproseRouter::add('userStore', 'User@store')->parameter('UserStore');



namespace App\Controllers\Parameters;

use duan617\LaravelHprose\Parameters\Base;

class UserStore extends Base
{
    public function rules()
    {
        return [
            'name'  => '



namespace App\Controllers\Parameters;

use duan617\LaravelHprose\Parameters\Base;

class UserStore extends Base
{
    public function rules()
    {
        return [
            'name'  => 'pport\MessageBag $errorMessage)
    {
        return [
            'status_code'   => 400,
            'message'       => $errorMessage->first(),
        ];
    }
}

$client->getUserByName('zhuqipeng');
$client->userStore('zhuqipeng');
$client->userUpdate('zhuqipeng');

\LaravelHproseRouter::group(array $attributes, callable $callback);

\LaravelHproseRouter::group(['namespace' => 'App\Controllers'], function ($route) {
    $route->add('getUserByName', function ($name) {
        return 'name: ' . $name;
    });

    $route->add('userUpdate', 'User@update');
});

$client->getUserByName('zhuqipeng');
$client->userUpdate('zhuqipeng');

\LaravelHproseRouter::group(['namespace' => 'App\Controllers', 'prefix' => 'user'], function ($route) {
    $route->add('getByName', function ($name) {
        return 'name: ' . $name;
    });

    $route->add('update', 'User@update');
});

$client->user->getByName('zhuqipeng');
$client->user->update('zhuqipeng');
// 或者
$client->user_getByName('zhuqipeng');
$client->user_update('zhuqipeng');
shell
    php artisan vendor:publish --provider="duan617\LaravelHprose\ServiceProvider"
    

routes/rpc.php
shell
php artisan hprose:socket_server