Passed
Push — master ( 48261f...058de4 )
by Nate
03:29
created

UrlManager::getRules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
ccs 0
cts 8
cp 0
crap 2
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/transformer/license
6
 * @link       https://www.flipboxfactory.com/software/transformer/
7
 */
8
9
namespace flipbox\rest;
10
11
use Craft;
12
use craft\events\RegisterUrlRulesEvent;
13
14
/**
15
 * @inheritdoc
16
 *
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 */
20
class UrlManager extends \yii\web\UrlManager
21
{
22
23
    const EVENT_REGISTER_REST_URL_RULES = 'registerRestUrlRules';
24
25
    /**
26
     * @inheritdoc
27
     */
28
    public function __construct(array $config = [])
29
    {
30
        $config['rules'] = $this->getRules();
31
        parent::__construct($config);
32
    }
33
34
    /**
35
     * @return array
36
     */
37
    private function getRules()
38
    {
39
        $event = new RegisterUrlRulesEvent();
40
        $this->trigger(
41
            self::EVENT_REGISTER_REST_URL_RULES,
42
            $event
43
        );
44
45
        return array_filter($event->rules);
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51
    public function parseRequest($request)
52
    {
53
        if (!$result = parent::parseRequest($request)) {
54
            Craft::warning("Unable to parse request: " . $request->getUrl());
55
        }
56
57
        return $result;
58
    }
59
}
60