summaryrefslogtreecommitdiff
path: root/src/File/Handler.php
blob: eecedc0e761adf3381ecdd00d56f05bfe6d10621 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php

namespace App\File;

use Exception;

/**
 * File handler
 */
class Handler
{
    protected $filename;
    protected $file;

    /**
     * Check file can be read
     * Read and parse file into array
     *
     * @author Phil Burton <phil@pgburton.com>
     * @param string $filename string
     */
    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);
    }

    /**
     * Retun the raw file contents
     *
     * @author Phil Burton <phil@pgburton.com>
     * @return string
     */
    public function getFileContents(): string
    {
        return $this->file;
    }
}