Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Class Resp Used to simulate WS response
- */
- class Resp {
- private $r = array(1 => 'A', 2 => 'B');
- public function re() {
- return $this->r[rand(1,2)];
- }
- }
- /**
- * Class Some Used to show PHP GOTO functionality
- */
- class Some {
- /**
- * @var string Holds request answer
- */
- private $result = '';
- /**
- * @param null $service
- * @return string
- */
- public function request($service = null) {
- $_req = new Resp();
- if ($service == 'WS') {
- // hypothetical call to the REST webservice
- // cURL...
- $this->result = $_req->re();
- if ($this->result === 'A') {
- return "WS";
- } else {
- goto Go1;
- }
- } else {
- Go1:
- // execute direct DB call to get result
- $this->result = "DB";
- return $this->result;
- }
- }
- }
- $r1 = new Some();
- echo $r1->request('WS') . "\n";
- echo $r1->request('WS') . "\n";
- echo $r1->request('WS') . "\n";
- echo $r1->request('WS') . "\n";
- echo $r1->request('WS') . "\n";
- echo $r1->request('WS') . "\n";
- echo $r1->request() . "\n";
- echo $r1->request() . "\n";
- echo $r1->request() . "\n";
- ?>
- Random answers:
- WS
- DB
- DB
- DB
- WS
- WS
- DB
- DB
- DB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement