Created
December 4, 2018 16:39
-
-
Save pokisin/e03e3ab25c72c3ecca29a66fa74e7b43 to your computer and use it in GitHub Desktop.
RPC Framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Service for basic operations from server | |
class Operacion { | |
/** | |
* Add two operands | |
* @param interge | |
* @return interge | |
*/ | |
public function add($a, $b) { | |
return $this->_add($a, $b); | |
} | |
/** | |
* subtraction | |
*/ | |
public function sub($a, $b) { | |
return $a - $b; | |
} | |
/** | |
* multiplication | |
*/ | |
public function mul($a, $b) { | |
return $a * $b; | |
} | |
/** | |
* Protected methods will not be exposed | |
* @param interge | |
* @return interge | |
*/ | |
protected function _add($a, $b) { | |
return $a + $b; | |
} | |
} | |
$server = new Yar_Server(new Operacion()); | |
$server->handle(); | |
?> | |
//_______________How to consume the service on the client's side________________ | |
<?php | |
$client = new Yar_Client("http://localhost/yarw/index.php"); | |
$result = $client->add(20,10); | |
echo $result.'<hr>'; | |
echo $client->mult(10, 20); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment