Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Proxy Manager Laravel Package

ocramius/proxy-manager

ProxyManager generates and manages PHP proxy classes (virtual proxies, lazy-loading value holders, etc.) to implement the Proxy Pattern. Useful for lazy-loading, interceptors, and advanced DI/ORM scenarios. Install via Composer and use factory helpers to create proxies.

View on GitHub
Deep Wiki
Context7

Remote Object Proxy

The remote object implementation is a mechanism that enables a local object to control another object on another server. Each call method on the local object will do a network call to get information or execute operations on the remote object.

What is remote object proxy?

A remote object is based on an interface. The remote interface defines the API that a consumer can call. This interface must be implemented both by the client and the RPC server.

Adapters

Laminas's RPC components (XmlRpc, JsonRpc & Soap) can be used with the remote object. You will need to require the one you need via composer:

$ php composer.phar require laminas/laminas-xmlrpc:2.*
$ php composer.phar require laminas/laminas-json:2.*
$ php composer.phar require laminas/laminas-soap:2.*

ProxyManager comes with 3 adapters:

  • ProxyManager\Factory\RemoteObject\Adapter\XmlRpc
  • ProxyManager\Factory\RemoteObject\Adapter\JsonRpc
  • ProxyManager\Factory\RemoteObject\Adapter\Soap

Usage examples

RPC server side code (xmlrpc.php in your local webroot):

interface FooServiceInterface
{
    public function foo();
}

class Foo implements FooServiceInterface
{
    /**
     * Foo function
     * [@return](https://github.com/return) string
     */
    public function foo()
    {
        return 'bar remote';
    }
}

$server = new Laminas\XmlRpc\Server();
$server->setClass('Foo', 'FooServiceInterface');  // my FooServiceInterface implementation
$server->handle();

Client side code (proxy) :


interface FooServiceInterface
{
    public function foo();
}

$factory = new \ProxyManager\Factory\RemoteObjectFactory(
    new \ProxyManager\Factory\RemoteObject\Adapter\XmlRpc(
        new \Laminas\XmlRpc\Client('https://localhost/xmlrpc.php')
    )
);

$proxy = $factory->createProxy('FooServiceInterface');

var_dump($proxy->foo()); // "bar remote"

Implementing custom adapters

Your adapters must implement ProxyManager\Factory\RemoteObject\AdapterInterface:

interface AdapterInterface
{
    /**
     * Call remote object
     *
     * [@param](https://github.com/param) string $wrappedClass
     * [@param](https://github.com/param) string $method
     * [@param](https://github.com/param) array $params
     *
     * [@return](https://github.com/return) mixed
     */
    public function call($wrappedClass, $method, array $params = []);
}

To create your implementation (for RESTful web services, for example), pass your adapter instance to your factory at construction time.

Known limitations

  • methods using func_get_args(), func_get_arg() and func_num_arg() will not function properly for parameters that are not part of the proxied object interface: use variadic arguments instead.

Tuning performance for production

See Tuning ProxyManager for Production.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport