summaryrefslogtreecommitdiff
path: root/src/Script
diff options
context:
space:
mode:
Diffstat (limited to 'src/Script')
-rw-r--r--src/Script/Console.php15
-rw-r--r--src/Script/Input.php27
-rw-r--r--src/Script/Output.php23
3 files changed, 55 insertions, 10 deletions
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 <phil@pgburton.com>
* @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 <phil@pgburton.com>
+ * @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 @@
+<?php
+
+namespace App\Script;
+
+use App\Model\Collection;
+
+class Output
+{
+ public function printCollection(Collection $collection)
+ {
+ if (count($collection) === 0) {
+ echo "No results found\n";
+ return;
+ }
+
+ $out = [];
+ foreach ($collection as $vendor) {
+ $out[] = implode("\n", $vendor->toString());
+ }
+
+ echo implode("\n\n", $out) . "\n";
+ }
+}