bakaphp /
phalcon-api
| 1 | <?php |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
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 | public function getApplication() |
||
| 35 | {
|
||
| 36 | return $this->application; |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @return FactoryDefault|PhCli |
||
| 41 | */ |
||
| 42 | public function getContainer() |
||
| 43 | {
|
||
| 44 | 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 | public function setup() |
||
| 64 | {
|
||
| 65 | $this->container->set('metrics', microtime(true));
|
||
| 66 | $this->setupApplication(); |
||
| 67 | $this->registerServices(); |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Setup the application object in the container |
||
| 72 | * |
||
| 73 | * @return void |
||
| 74 | */ |
||
| 75 | protected function setupApplication() |
||
| 76 | {
|
||
| 77 | //setup the phalcon micro application |
||
| 78 | $this->application = new Micro($this->container); |
||
| 79 | $this->container->setShared('application', $this->application);
|
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Registers available services |
||
| 84 | * |
||
| 85 | * @return void |
||
| 86 | */ |
||
| 87 | private function registerServices() |
||
| 88 | {
|
||
| 89 | /** @var ServiceProviderInterface $provider */ |
||
| 90 | foreach ($this->providers as $provider) {
|
||
| 91 | (new $provider())->register($this->container); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 |