zukars3

index.php

Apr 2nd, 2020
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.00 KB | None | 0 0
  1. <?php
  2.  
  3. require 'classes/Product.php';
  4. require 'classes/ProductList.php';
  5.  
  6.  
  7. class Application
  8. {
  9.     private $control;
  10.  
  11.     public function __construct(ProductList $control)
  12.     {
  13.         $this->control = $control;
  14.     }
  15.  
  16.  
  17.     function run()
  18.     {
  19.         echo 'Welcome!' . PHP_EOL;
  20.  
  21.         while (true) {
  22.  
  23.             $this->control->loadProducts();
  24.  
  25.             echo 'Press 1 to add product' . PHP_EOL;
  26.             echo 'Press 2 to remove product' . PHP_EOL;
  27.             echo 'Press 3 to show all products' . PHP_EOL;
  28.             echo 'Press 0 to exit' . PHP_EOL;
  29.  
  30.             $input = readline('Your choice!') . PHP_EOL;
  31.             switch ($input) {
  32.                 case 1 :
  33.                     system('clear');
  34.                     $name = readline('Enter name of the product: ');
  35.                     $exist = $this->control->checkExistance($name);
  36.                     if ($exist == false) {
  37.                         $amount = readline('Enter amount of the product: ');
  38.                         $type = readline('Enter type of amount (kg or pieces): ');
  39.                         $this->control->addProduct($name, $amount, $type);
  40.                     } else {
  41.                         system('clear');
  42.                         $amount = readline('This product already exists! Enter the amount in ' . $exist . ' : ');
  43.                         $this->control->editProduct($name, $amount);
  44.                     }
  45.                     break;
  46.                 case 2:
  47.                     $name = readline('Enter name of the product: ');
  48.                     $this->control->removeProduct($name);
  49.                     break;
  50.                 case 3:
  51.                     system('clear');
  52.                     echo implode('', $this->control->showProducts()) . PHP_EOL;
  53.                     readline();
  54.                     break;
  55.                 case 0:
  56.                     echo 'Bye!' . PHP_EOL;
  57.                     die;
  58.             }
  59.         }
  60.     }
  61. }
  62.  
  63. $app = new Application(new ProductList());
  64. $app->run();
Advertisement
Add Comment
Please, Sign In to add comment