mirror
is a PHP library that allows you to access and invoke remote classes and functions as if they were local. By exposing classes and functions on a remote server, and generating their mirrored counterparts on the client, this library provides a seamless way to work with remote entities through serialized communication.
- Remote Class and Function Mapping: Expose classes and functions on a server and map them to mirrored versions on the client side.
- Seamless Remote Access: Invoke remote methods and functions from the client as if they were local.
- Serialized Data Communication: Send parameters and receive results through serialized HTTP communication, making the process efficient and transparent.
- Client-Server Symmetry: Acts as both a client and a server, providing flexible and dynamic integration of remote entities.
Use the prepare
method to expose the classes and functions you want to make available remotely:
mirror::prepare(Dog::class);
mirror::prepare('sum');
echo mirror::expose($page);
On the client side, use discover to retrieve the available classes and functions, and generate to create local mirrored versions:
use divengine\mirror;
$model = mirror::discover("http://localhost:9090/");
echo mirror::generate($model, "MyClient");
Once the mirrored classes are generated, you can invoke them as if they were local:
use divengine\mirror;
mirror::setServer("http://localhost:9090/");
include __DIR__ .'/Dog.php';
$result = \MyClient\sum(1, 2);
var_dump($result);
The server receives calls from the client and processes them:
$call = mirror::receiveCall();
To install Div PHP Mirror, you can use Composer (or other relevant instructions depending on your setup):
composer require divengine/mirror
Contributions are welcome! Feel free to submit issues or pull requests to help improve Div PHP Mirror.
For more information, please refer to the official documentation.