From 33f00442f1667d57f94433834e0da4985670025b Mon Sep 17 00:00:00 2001 From: Fbenas Date: Mon, 7 May 2018 14:42:15 +0100 Subject: Get filtering working with output --- src/Script/Console.php | 15 +++++++++------ src/Script/Input.php | 27 +++++++++++++++++++++++---- src/Script/Output.php | 23 +++++++++++++++++++++++ 3 files changed, 55 insertions(+), 10 deletions(-) (limited to 'src/Script') diff --git a/src/Script/Console.php b/src/Script/Console.php index bedbc1d..e1d7df5 100644 --- a/src/Script/Console.php +++ b/src/Script/Console.php @@ -2,9 +2,9 @@ namespace App\Script; -// use App\Model\Vendor; +use App\Model\Vendor; use App\Script\Input; -// use App\Script\Output; +use App\Script\Output; /** * Main application class @@ -32,6 +32,9 @@ class Console { // Define the root of the application define('APP_ROOT', realpath(dirname(__FILE__) . '/../../') . '/'); + + // Set default tiemzone + date_default_timezone_set('Europe/London'); } /** @@ -41,12 +44,12 @@ class Console */ public function exec() { - $vendors = Vendor::loadAll(); $input = new Input; + $vendors = Vendor::loadAll($input->getOption('f')); $vendors->filterByInput($input); - // $output = new Output; - // - // $output->printCollection($vendors); + + $output = new Output; + $output->printCollection($vendors); } } diff --git a/src/Script/Input.php b/src/Script/Input.php index 6b15c51..4e437dd 100644 --- a/src/Script/Input.php +++ b/src/Script/Input.php @@ -19,7 +19,15 @@ class Input * * @var string */ - protected $availableOptions = 'fdtlc::'; + protected $shortOpts = 'f:d::t::l::c::'; + + protected $longOpts = [ + 'filename:', + 'day::', + 'time::', + 'location::', + 'covers::' + ]; /** * The loaded CLI options @@ -45,7 +53,7 @@ class Input */ protected function loadOptions() { - $this->options = getopt($this->getOptionString()); + $this->options = getopt($this->getShortOptionString(), $this->getLongOptionString()); if (!array_key_exists('f', $this->options)) { throw new Exception('Filename Option `-f` is required'); @@ -63,9 +71,20 @@ class Input * @author Phil Burton * @return string */ - public function getOptionString(): string + public function getShortOptionString(): string + { + return $this->shortOpts; + } + + /** + * Return the option string for the options we want to load + * + * @author Phil Burton + * @return string + */ + public function getLongOptionString(): array { - return $this->availableOptions; + return $this->longOpts; } /** diff --git a/src/Script/Output.php b/src/Script/Output.php index e69de29..8f7a689 100644 --- a/src/Script/Output.php +++ b/src/Script/Output.php @@ -0,0 +1,23 @@ +toString()); + } + + echo implode("\n\n", $out) . "\n"; + } +} -- cgit v1.2.3