Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. <?php
  2.  
  3. interface Storage
  4. {
  5. public function set($data);
  6. public function get();
  7. public function store();
  8. }
  9.  
  10.  
  11. class MySQL implements Storage
  12. {
  13. private $data;
  14.  
  15. public function set($data){
  16. echo "MySQL Set";
  17. $this->data = $data;
  18. }
  19.  
  20. public function get(){
  21. echo "MySQL Get";
  22. return $this->data;
  23. }
  24.  
  25. public function store(){
  26. echo "MySQL Store";
  27. }
  28. }
  29.  
  30. class ElasticSearch implements Storage
  31. {
  32. private $data;
  33.  
  34. public function set($data){
  35. echo "ElasticSearch Set";
  36. $this->data = $data;
  37. }
  38.  
  39. public function get(){
  40. echo "ElasticSearch Get";
  41. return $this->data;
  42. }
  43.  
  44. public function store(){
  45. echo "ElasticSearch Store";
  46. }
  47. }
  48.  
  49. class Redis implements Storage
  50. {
  51. private $data;
  52.  
  53. public function set($data){
  54. echo "Redis Set";
  55. $this->data = $data;
  56. }
  57.  
  58. public function get(){
  59. echo "Redis Get";
  60. return $this->data;
  61. }
  62.  
  63. public function store(){
  64. echo "Redis Store";
  65. }
  66. }
  67.  
  68. class Base
  69. {
  70. private $storage_handler;
  71.  
  72. public function __construct(Storage $storage_handler)
  73. {
  74. $this->storage_handler = $storage_handler;
  75. }
  76.  
  77. public function test()
  78. {
  79. $this->storage_handler->set("Hello World");
  80. echo "<br/>";
  81. $this->storage_handler->get();
  82. echo "<br/>";
  83. $this->storage_handler->store();
  84. }
  85. }
  86.  
  87. $base = new Base(new MySQL());
  88. $base->test();
  89. echo "<br/><br/>";
  90. $base = new Base(new ElasticSearch());
  91. $base->test();
  92. echo "<br/><br/>";
  93. $base = new Base(new Redis());
  94. $base->test();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement