summaryrefslogtreecommitdiff
path: root/src/Script/Console.php
blob: ee8114ea84d1f3db0f9c9cd2b2a8bf63a5ca7caa (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
53
54
55
56
57
58
59
60
61
62
<?php

namespace App\Script;

use App\Model\Vendor;
use App\Script\Input;
use App\Script\Output;
use Exception;

/**
 * Main application class
 *
 * @author Phil Burton <phil@pgburton.com>
 */
class Console
{
    /**
     * Create symfony application and add commands
     *
     * @author Phil Burton <phil@pgburton.com>
     */
    public function __construct()
    {
        $this->init();
    }

    /**
     * Initalise
     *
     * @author Phil Burton <phil@pgburton.com>
     */
    protected function init()
    {
        // Define the root of the application
        define('APP_ROOT', realpath(dirname(__FILE__) . '/../../') . '/');

        // Set default tiemzone
        date_default_timezone_set('Europe/London');
    }

    /**
     * Run main application code
     *
     * @author Phil Burton <phil@pgburton.com>
     */
    public function exec()
    {
        $output = new Output;

        try {
            $input = new Input;
            // Get vendor data
            $vendors = Vendor::loadAll($input->getOption('f'));
            // Filter data
            $vendors->filterByInput($input);
            // Output data
            $output->printCollection($vendors);
        } catch (Exception $e) {
            $output->printException($e);
        }
    }
}