fmihel/php-router

php,router

v4.0.0 2022-10-18 08:04 UTC

README

simple php router

Install

Server side

composer require fmihel/php-router

Client side

npm i fmihel-php-router-client

Simple use

create index.js

import router from 'fmihel-php-router-client';

router({
    id:'MSG_SEND',
    data:{ msg: 'send msg to server',any_num:10,arr:[1,32,4,2]},
})
.then(data=>{
    console.info(data);
})
.catch(e=>{
    console.error(e);
})

create mod1.php

<?php

class Mod1 extends fmihel\router\Route{
    
    public function route_MSG_SEND($from){
        error_log(print_r($from,true));
        return $this->ok("send Ok on response MSG_SEND");
    }    
    
}
?>

create index.php

<?php
require_once __DIR__.'/vendor/autoload.php';

new \fmihel\router\Router([
    'add'       =>['mod1.php'],
    'suspend'   =>false,
]);

?>