ParserAbstract::doneProcess()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 3
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Route
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Route\Parser;
16
17
use Phossa2\Route\Message\Message;
18
use Phossa2\Shared\Base\ObjectAbstract;
19
use Phossa2\Shared\Debug\DebuggableTrait;
20
use Phossa2\Route\Interfaces\ParserInterface;
21
use Phossa2\Shared\Debug\DebuggableInterface;
22
23
/**
24
 * ParserAbstract
25
 *
26
 * @package Phossa2\Route
27
 * @author  Hong Zhang <[email protected]>
28
 * @see     ObjectAbstract
29
 * @see     ParserInterface
30
 * @see     DebuggableInterface
31
 * @version 2.0.0
32
 * @since   2.0.0 added
33
 */
34
abstract class ParserAbstract extends ObjectAbstract implements ParserInterface, DebuggableInterface
35
{
36
    use DebuggableTrait;
37
38
    /**
39
     * flag for new route added.
40
     *
41
     * @var    bool
42
     * @access protected
43
     */
44
    protected $modified = false;
45
46
    /**
47
     * regex storage
48
     *
49
     * @var    string[]
50
     * @access protected
51
     */
52
    protected $regex = [];
53
54
    /**
55
     * pattern shortcuts
56
     *
57
     * @var    string[]
58
     * @access protected
59
     */
60
    protected $shortcuts = [
61
        ':d}'   => ':[0-9]++}',             // digit only
62
        ':l}'   => ':[a-z]++}',             // lower case
63
        ':u}'   => ':[A-Z]++}',             // upper case
64
        ':a}'   => ':[0-9a-zA-Z]++}',       // alphanumeric
65
        ':c}'   => ':[0-9a-zA-Z+_\-\.]++}', // common chars
66
        ':nd}'  => ':[^0-9/]++}',           // not digits
67
        ':xd}'  => ':[^0-9/][^/]*+}',       // no leading digits
68
    ];
69
70
    /**
71
     * @var    string
72
     */
73
    const MATCH_GROUP_NAME = "\s*([a-zA-Z][a-zA-Z0-9_]*)\s*";
74
    const MATCH_GROUP_TYPE = ":\s*([^{}]*(?:\{(?-1)\}[^{}]*)*)";
75
    const MATCH_SEGMENT = "[^/]++";
76
77
    /**
78
     * Constructor
79
     *
80
     * @param  array $properties
81
     * @access public
82
     */
83
    public function __construct(array $properties = [])
84
    {
85
        $this->setProperties($properties);
86
    }
87
88
    /**
89
     * Update regex pool etc.
90
     *
91
     * @param  string $routeName
92
     * @param  string $routePattern
93
     * @param  string $regex
94
     * @access protected
95
     */
96
    protected function doneProcess(
97
        /*# string */ $routeName,
98
        /*# string */ $routePattern,
99
        /*# string */ $regex
100
    ) {
101
        $this->regex[$routeName] = $regex;
102
        $this->modified = true;
103
104
        // debug message
105
        $this->debug(Message::get(
106
            Message::RTE_PARSER_PATTERN,
107
            $routePattern,
108
            $regex
109
        ));
110
    }
111
}
112