Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require 'classes/Product.php';
- require 'classes/ProductList.php';
- class Application
- {
- private $control;
- public function __construct(ProductList $control)
- {
- $this->control = $control;
- }
- function run()
- {
- echo 'Welcome!' . PHP_EOL;
- while (true) {
- $this->control->loadProducts();
- echo 'Press 1 to add product' . PHP_EOL;
- echo 'Press 2 to remove product' . PHP_EOL;
- echo 'Press 3 to show all products' . PHP_EOL;
- echo 'Press 0 to exit' . PHP_EOL;
- $input = readline('Your choice!') . PHP_EOL;
- switch ($input) {
- case 1 :
- system('clear');
- $name = readline('Enter name of the product: ');
- $exist = $this->control->checkExistance($name);
- if ($exist == false) {
- $amount = readline('Enter amount of the product: ');
- $type = readline('Enter type of amount (kg or pieces): ');
- $this->control->addProduct($name, $amount, $type);
- } else {
- system('clear');
- $amount = readline('This product already exists! Enter the amount in ' . $exist . ' : ');
- $this->control->editProduct($name, $amount);
- }
- break;
- case 2:
- $name = readline('Enter name of the product: ');
- $this->control->removeProduct($name);
- break;
- case 3:
- system('clear');
- echo implode('', $this->control->showProducts()) . PHP_EOL;
- readline();
- break;
- case 0:
- echo 'Bye!' . PHP_EOL;
- die;
- }
- }
- }
- }
- $app = new Application(new ProductList());
- $app->run();
Advertisement
Add Comment
Please, Sign In to add comment