Failed Conditions
Push — master ( b74acd...f46d35 )
by Maximo
04:31 queued 48s
created

Swoole   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 37
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setup() 0 9 1
A run() 0 16 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gewaer\Bootstrap;
6
7
use function Gewaer\Core\appPath;
8
use Phalcon\Di\FactoryDefault;
9
use Phalcon\Mvc\Micro;
10
use Dmkit\Phalcon\Auth\Middleware\Micro as AuthMicro;
11
use Baka\Http\RouterCollection;
12
13
/**
14
 * Class Api
15
 *
16
 * @package Gewaer\Bootstrap
17
 *
18
 * @property Micro $application
19
 */
20
class Swoole extends AbstractBootstrap
21
{
22
    /**
23
     * Run the application
24
     *
25
     * @return mixed
26
     */
27
    public function run()
28
    {
29
        $config = $this->container->getConfig()->jwt->toArray();
30
31
        //if the router has jwt ignore url we always overwrite the app config
32
        $routerJwtIgnoreUrl = RouterCollection::getJwtIgnoreRoutes();
33
        if (!empty($routerJwtIgnoreUrl)) {
34
            $config['ignoreUri'] = $routerJwtIgnoreUrl;
35
        } elseif (!$this->container->getConfig()->application->jwtSecurity) {
36
            //ignore token validation if disable
37
            $config['ignoreUri'] = ['regex: *'];
38
        }
39
        //JWT Validation
40
        new AuthMicro($this->application, $config);
41
42
        return $this->application->handle($this->container->getRequest()->getServer('request_uri', null, '/'));
43
    }
44
45
    /**
46
     * @return mixed
47
     */
48
    public function setup()
49
    {
50
        //set the default DI
51
        $this->container = new FactoryDefault();
52
        //set all the services
53
        $this->providers = require appPath('api/config/providers.php');
54
55
        //run my parents setup
56
        parent::setup();
57
    }
58
}
59