Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $videos = [];
- $videoStore = new VideoStore($videos);
- class Application
- {
- private $videoStore;
- public function __construct(VideoStore $videoStore)
- {
- $this->videoStore=$videoStore;
- }
- function run()
- {
- while (true) {
- echo "Choose the operation you want to perform \n";
- echo "Choose 0 for EXIT\n";
- echo "Choose 1 to fill video store\n";
- echo "Choose 2 to rent video (as user)\n";
- echo "Choose 3 to return video (as user)\n";
- echo "Choose 4 to list inventory\n";
- $command = (int)readline();
- switch ($command) {
- case 0:
- echo "Bye!";
- die;
- case 1:
- $this->add_movies();
- break;
- case 2:
- $this->rent_video();
- break;
- case 3:
- $this->return_video();
- break;
- case 4:
- $this->list_inventory();
- break;
- default:
- echo "Sorry, I don't understand you..";
- }
- }
- }
- private function add_movies()
- {
- $this->videoStore->addVideo();
- }
- private function rent_video()
- {
- //todo
- }
- private function return_video()
- {
- }
- private function list_inventory()
- {
- return implode("|",$this->videoStore->getUserRaiting());
- }
- }
- class Video
- {
- private $title;
- private $userRaiting = 0;
- public function __construct(string $title)
- {
- $this->title = $title;
- }
- public function getVideoTitle ():string
- {
- return $this->title;
- }
- public function getUserRaiting():int
- {
- return $this->userRaiting;
- }
- }
- class VideoStore
- {
- protected $videos;
- public function __construct(array $videos)
- {
- $this->videos = $videos;
- }
- public function getVideos ():array
- {
- $videos = [];
- var_dump($videos);
- foreach ($this->videos as $video)
- {
- $videos[] = $video->getVideoTitle();
- }
- return $videos;
- }
- public function getUserRaiting ():array
- {
- $rating = [];
- foreach ($this->videos as $video)
- {
- $videos[] = $video->getUserRaiting();
- }
- return $rating;
- }
- public function addVideo()
- {
- $title = readline("Enter new Movie title: ");
- $videos[] = new Video($title);
- // var_dump($videos);
- }
- }
- //echo implode("|" ,$videoStore->getVideos());
- $app = new Application($videoStore);
- $app->run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement