summaryrefslogtreecommitdiff
path: root/src/File
diff options
context:
space:
mode:
authorFbenas <philbeansburton@gmail.com>2018-04-29 22:24:25 +0100
committerFbenas <philbeansburton@gmail.com>2018-04-29 22:24:25 +0100
commitc223ab602cbe7f6db7321ba547164971d63d7bcd (patch)
treea4a73aab1d8082b2f96f899fc4d51040fe5ed85e /src/File
parentaf0cd60fc5fd2939477dfccd4c0e78892e76d5ba (diff)
WIP
Diffstat (limited to 'src/File')
-rw-r--r--src/File/Handler.php56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/File/Handler.php b/src/File/Handler.php
new file mode 100644
index 0000000..61c78a8
--- /dev/null
+++ b/src/File/Handler.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace App\File\Handler;
+
+use Exception;
+
+/**
+ * File handler
+ */
+class Handler
+{
+ protected $filename;
+ protected $file;
+ protected $array;
+
+ /**
+ * Check file can be read
+ * Read and parse file into array
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param string $filename [description]
+ */
+ public function __construct(string $filename)
+ {
+ $this->filename = $filename;
+ if (!is_readable($filename)) {
+ throw new Exception('Cannot read from file: ' . $filename);
+ }
+ $this->load;
+ }
+
+ /**
+ * Load the file
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ */
+ public function load()
+ {
+ $this->file = file_get_contents($this->filename);
+ }
+
+ /**
+ * Parse file and return array
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @return array
+ */
+ public function getVendorArray(): array
+ {
+ if (!$this->array) {
+ $this->array = [];
+ }
+
+ return $this->array;
+ }
+}