Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. <?php
  2. /**
  3. * Class Resp Used to simulate WS response
  4. */
  5. class Resp {
  6. private $r = array(1 => 'A', 2 => 'B');
  7.  
  8. public function re() {
  9. return $this->r[rand(1,2)];
  10. }
  11. }
  12.  
  13. /**
  14. * Class Some Used to show PHP GOTO functionality
  15. */
  16. class Some {
  17.  
  18. /**
  19. * @var string Holds request answer
  20. */
  21. private $result = '';
  22.  
  23. /**
  24. * @param null $service
  25. * @return string
  26. */
  27. public function request($service = null) {
  28. $_req = new Resp();
  29. if ($service == 'WS') {
  30. // hypothetical call to the REST webservice
  31. // cURL...
  32. $this->result = $_req->re();
  33.  
  34. if ($this->result === 'A') {
  35. return "WS";
  36. } else {
  37. goto Go1;
  38. }
  39. } else {
  40. Go1:
  41. // execute direct DB call to get result
  42. $this->result = "DB";
  43.  
  44. return $this->result;
  45. }
  46. }
  47. }
  48.  
  49. $r1 = new Some();
  50. echo $r1->request('WS') . "\n";
  51. echo $r1->request('WS') . "\n";
  52. echo $r1->request('WS') . "\n";
  53. echo $r1->request('WS') . "\n";
  54. echo $r1->request('WS') . "\n";
  55. echo $r1->request('WS') . "\n";
  56. echo $r1->request() . "\n";
  57. echo $r1->request() . "\n";
  58. echo $r1->request() . "\n";
  59. ?>
  60.  
  61. Random answers:
  62. WS
  63. DB
  64. DB
  65. DB
  66. WS
  67. WS
  68. DB
  69. DB
  70. DB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement