Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- interface Storage
- {
- public function set($data);
- public function get();
- public function store();
- }
- class MySQL implements Storage
- {
- private $data;
- public function set($data){
- echo "MySQL Set";
- $this->data = $data;
- }
- public function get(){
- echo "MySQL Get";
- return $this->data;
- }
- public function store(){
- echo "MySQL Store";
- }
- }
- class ElasticSearch implements Storage
- {
- private $data;
- public function set($data){
- echo "ElasticSearch Set";
- $this->data = $data;
- }
- public function get(){
- echo "ElasticSearch Get";
- return $this->data;
- }
- public function store(){
- echo "ElasticSearch Store";
- }
- }
- class Redis implements Storage
- {
- private $data;
- public function set($data){
- echo "Redis Set";
- $this->data = $data;
- }
- public function get(){
- echo "Redis Get";
- return $this->data;
- }
- public function store(){
- echo "Redis Store";
- }
- }
- class Base
- {
- private $storage_handler;
- public function __construct(Storage $storage_handler)
- {
- $this->storage_handler = $storage_handler;
- }
- public function test()
- {
- $this->storage_handler->set("Hello World");
- echo "<br/>";
- $this->storage_handler->get();
- echo "<br/>";
- $this->storage_handler->store();
- }
- }
- $base = new Base(new MySQL());
- $base->test();
- echo "<br/><br/>";
- $base = new Base(new ElasticSearch());
- $base->test();
- echo "<br/><br/>";
- $base = new Base(new Redis());
- $base->test();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement