diff options
Diffstat (limited to 'src/File')
| -rw-r--r-- | src/File/Handler.php | 56 | 
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; +    } +}  | 
