Failed Conditions
Pull Request — master (#10)
by Maximo
03:08
created

library/Bootstrap/AbstractBootstrap.php (1 issue)

1
<?php
0 ignored issues
show
End of line character is invalid; expected "\n" but found "\r\n"
Loading history...
2
3
declare(strict_types=1);
4
5
namespace Gewaer\Bootstrap;
6
7
use Gewaer\Http\Response;
8
use Phalcon\Cli\Console;
9
use Phalcon\Di\FactoryDefault;
10
use Phalcon\Di\FactoryDefault\Cli as PhCli;
11
use Phalcon\Di\ServiceProviderInterface;
12
use Phalcon\Mvc\Micro;
13
14
/**
15
 * Absstract class that provides the boostrap structure for any Micro PhalconPHP App
16
 */
17
abstract class AbstractBootstrap
18
{
19
    /** @var Micro|Console */
20
    protected $application;
21
22
    /** @var FactoryDefault|PhCli */
23
    protected $container;
24
25
    /** @var array */
26
    protected $options = [];
27
28
    /** @var array */
29
    protected $providers = [];
30
31
    /**
32
     * @return Console|Micro
33
     */
34 1
    public function getApplication()
35
    {
36 1
        return $this->application;
37
    }
38
39
    /**
40
     * @return FactoryDefault|PhCli
41
     */
42 1
    public function getContainer()
43
    {
44 1
        return $this->container;
45
    }
46
47
    /**
48
     * @return Response
49
     */
50
    public function getResponse()
51
    {
52
        return $this->container->getShared('response');
53
    }
54
55
    /**
56
     * @return mixed
57
     */
58
    abstract public function run();
59
60
    /**
61
     * Runs the application
62
     */
63 4
    public function setup()
64
    {
65 4
        $this->container->set('metrics', microtime(true));
66 4
        $this->setupApplication();
67 4
        $this->registerServices();
68 4
    }
69
70
    /**
71
     * Setup the application object in the container
72
     *
73
     * @return void
74
     */
75 4
    protected function setupApplication()
76
    {
77
        //setup the phalcon micro application
78 4
        $this->application = new Micro($this->container);
79 4
        $this->container->setShared('application', $this->application);
80 4
    }
81
82
    /**
83
     * Registers available services
84
     *
85
     * @return void
86
     */
87 4
    private function registerServices()
88
    {
89
        /** @var ServiceProviderInterface $provider */
90 4
        foreach ($this->providers as $provider) {
91 4
            (new $provider())->register($this->container);
92
        }
93 4
    }
94
}
95