Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1.  
  2. $videos = [];
  3. $videoStore = new VideoStore($videos);
  4.  
  5. class Application
  6. {
  7. private $videoStore;
  8.  
  9.  
  10. public function __construct(VideoStore $videoStore)
  11. {
  12. $this->videoStore=$videoStore;
  13. }
  14.  
  15.  
  16.  
  17.  
  18. function run()
  19. {
  20. while (true) {
  21. echo "Choose the operation you want to perform \n";
  22. echo "Choose 0 for EXIT\n";
  23. echo "Choose 1 to fill video store\n";
  24. echo "Choose 2 to rent video (as user)\n";
  25. echo "Choose 3 to return video (as user)\n";
  26. echo "Choose 4 to list inventory\n";
  27.  
  28. $command = (int)readline();
  29.  
  30. switch ($command) {
  31. case 0:
  32. echo "Bye!";
  33. die;
  34. case 1:
  35. $this->add_movies();
  36. break;
  37. case 2:
  38. $this->rent_video();
  39. break;
  40. case 3:
  41. $this->return_video();
  42. break;
  43. case 4:
  44. $this->list_inventory();
  45. break;
  46. default:
  47. echo "Sorry, I don't understand you..";
  48. }
  49. }
  50. }
  51.  
  52. private function add_movies()
  53. {
  54. $this->videoStore->addVideo();
  55. }
  56.  
  57. private function rent_video()
  58. {
  59. //todo
  60. }
  61.  
  62. private function return_video()
  63. {
  64.  
  65. }
  66.  
  67. private function list_inventory()
  68. {
  69.  
  70. return implode("|",$this->videoStore->getUserRaiting());
  71.  
  72.  
  73. }
  74. }
  75.  
  76.  
  77. class Video
  78. {
  79.  
  80. private $title;
  81. private $userRaiting = 0;
  82.  
  83.  
  84. public function __construct(string $title)
  85. {
  86. $this->title = $title;
  87. }
  88.  
  89. public function getVideoTitle ():string
  90. {
  91. return $this->title;
  92.  
  93. }
  94.  
  95. public function getUserRaiting():int
  96. {
  97. return $this->userRaiting;
  98. }
  99. }
  100.  
  101.  
  102. class VideoStore
  103. {
  104. protected $videos;
  105.  
  106. public function __construct(array $videos)
  107. {
  108. $this->videos = $videos;
  109. }
  110.  
  111. public function getVideos ():array
  112. {
  113. $videos = [];
  114. var_dump($videos);
  115.  
  116. foreach ($this->videos as $video)
  117. {
  118. $videos[] = $video->getVideoTitle();
  119. }
  120. return $videos;
  121.  
  122. }
  123.  
  124. public function getUserRaiting ():array
  125. {
  126. $rating = [];
  127.  
  128. foreach ($this->videos as $video)
  129. {
  130. $videos[] = $video->getUserRaiting();
  131. }
  132. return $rating;
  133.  
  134. }
  135.  
  136. public function addVideo()
  137. {
  138. $title = readline("Enter new Movie title: ");
  139. $videos[] = new Video($title);
  140. // var_dump($videos);
  141. }
  142.  
  143.  
  144.  
  145.  
  146. }
  147.  
  148. //echo implode("|" ,$videoStore->getVideos());
  149.  
  150.  
  151.  
  152.  
  153.  
  154. $app = new Application($videoStore);
  155.  
  156. $app->run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement