Guest User

Untitled

a guest
Oct 23rd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. <?php
  2.  
  3. Interface IPosts{}
  4. Interface IComments{}
  5.  
  6. # Models
  7. Class CommentsMysqlModel implements IComments{}
  8. Class CommentsMongoDBModel implements IComments{}
  9.  
  10. Class PostsMysqlModel implements IPosts{}
  11. Class PostsMongoDBModel implements IPosts{}
  12.  
  13. # Classes
  14. Class Posts {
  15.  
  16. private $postsModel;
  17. private $commentsModel;
  18.  
  19. public function __construct(IPosts $postsModel,IComments $commentsModel){
  20. $this->postsModel = $PostsModel;
  21. $this->commentsModel = $commentsModel;
  22. }
  23. }
  24.  
  25. // Example Of Usage
  26. # IF I would like to use mysql for both
  27. $comments = new CommentsMysqModel;
  28. $posts = new PostsMysqModel;
  29.  
  30. $postClass = new Posts($posts,$comments);
  31.  
  32. // So if i would like to use comments for mongodb
  33.  
  34. $comments = new CommentsMongoDBModel;
  35. $posts = new PostsMysqModel;
  36.  
  37. $postClass = new Posts($posts,$comments);
  38.  
  39.  
  40. // That's it
Add Comment
Please, Sign In to add comment