[ Index ]

PHP Cross Reference of phpBB-3.3.11-deutsch

title

Body

[close]

/vendor/ocramius/proxy-manager/docs/ -> remote-object.md (source)

   1  ---
   2  title: Remote Object Proxy
   3  ---
   4  
   5  # Remote Object Proxy
   6  
   7  The remote object implementation is a mechanism that enables an local object to control an other object on an other server.
   8  Each call method on the local object will do a network call to get information or execute operations on the remote object.
   9  
  10  ## What is remote object proxy ?
  11  
  12  A remote object is based on an interface. The remote interface defines the API that a consumer can call. This interface 
  13  must be implemented both by the client and the RPC server.
  14  
  15  ## Adapters
  16  
  17  ZendFramework's RPC components (XmlRpc, JsonRpc & Soap) can be used easily with the remote object.
  18  You will need to require the one you need via composer, though:
  19  
  20  ```sh
  21  $ php composer.phar require zendframework/zend-xmlrpc:2.*
  22  $ php composer.phar require zendframework/zend-json:2.*
  23  $ php composer.phar require zendframework/zend-soap:2.*
  24  ```
  25  
  26  ProxyManager comes with 3 adapters:
  27  
  28   * `ProxyManager\Factory\RemoteObject\Adapter\XmlRpc`
  29   * `ProxyManager\Factory\RemoteObject\Adapter\JsonRpc`
  30   * `ProxyManager\Factory\RemoteObject\Adapter\Soap`
  31  
  32  ## Usage examples
  33  
  34  RPC server side code (`xmlrpc.php` in your local webroot):
  35  
  36  ```php
  37  interface FooServiceInterface
  38  {
  39      public function foo();
  40  }
  41  
  42  class Foo implements FooServiceInterface
  43  {
  44      /**
  45       * Foo function
  46       * @return string
  47       */
  48      public function foo()
  49      {
  50          return 'bar remote';
  51      }
  52  }
  53  
  54  $server = new Zend\XmlRpc\Server();
  55  $server->setClass('Foo', 'FooServiceInterface');  // my FooServiceInterface implementation
  56  $server->handle();
  57  ```
  58  
  59  Client side code (proxy) :
  60  
  61  ```php
  62  
  63  interface FooServiceInterface
  64  {
  65      public function foo();
  66  }
  67  
  68  $factory = new \ProxyManager\Factory\RemoteObjectFactory(
  69      new \ProxyManager\Factory\RemoteObject\Adapter\XmlRpc(
  70          new \Zend\XmlRpc\Client('https://localhost/xmlrpc.php')
  71      )
  72  );
  73  
  74  $proxy = $factory->createProxy('FooServiceInterface');
  75  
  76  var_dump($proxy->foo()); // "bar remote"
  77  ```
  78  
  79  ## Implementing custom adapters
  80  
  81  Your adapters must implement `ProxyManager\Factory\RemoteObject\AdapterInterface` :
  82  
  83  ```php
  84  interface AdapterInterface
  85  {
  86      /**
  87       * Call remote object
  88       *
  89       * @param string $wrappedClass
  90       * @param string $method
  91       * @param array $params
  92       *
  93       * @return mixed
  94       */
  95      public function call($wrappedClass, $method, array $params = []);
  96  }
  97  ```
  98  
  99  It is very easy to create your own implementation (for RESTful web services, for example). Simply pass
 100  your own adapter instance to your factory at construction time
 101  
 102  ## Known limitations
 103  
 104   * methods using `func_get_args()`, `func_get_arg()` and `func_num_arg()` will not function properly
 105     for parameters that are not part of the proxied object interface: use 
 106     [variadic arguments](http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list)
 107     instead.
 108  
 109  ## Tuning performance for production
 110  
 111  See [Tuning ProxyManager for Production](tuning-for-production.md).


Generated: Sat Nov 4 14:26:03 2023 Cross-referenced by PHPXref 0.7.1