[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

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

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


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1