Completed
Pull Request — master (#6)
by Joao
08:06
created

RoutePattern::post()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 4
1
<?php
2
3
namespace ByJG\RestServer;
4
5
class RoutePattern
6
{
7
    /**
8
     * @var string[]
9
     */
10
    protected $properties = [];
11
12
    /**
13
     * RoutePattern constructor.
14
     *
15
     * @param array|string $method
16
     * @param string $pattern
17
     * @param string $handler
18
     * @param \Closure|string $function
19
     * @param string|null $class
20
     */
21
    public function __construct($method, $pattern, $handler, $function, $class = null)
22
    {
23
        $this->properties['method'] = $method;
24
        $this->properties['pattern'] = $pattern;
25
        $this->properties['handler'] = $handler;
26
        $this->properties['function'] = $function;
27
        $this->properties['class'] = $class;
28
    }
29
30
    /**
31
     * @param string $property
32
     * @return string
33
     */
34
    public function properties($property = null)
35
    {
36
        if (empty($property)) {
37
            return $this->properties;
38
        }
39
40
        return $this->properties[$property];
41
    }
42
43
    /**
44
     * RoutePattern Factory for "GET" method
45
     *
46
     * @param string $pattern
47
     * @param string $function
48
     * @param string $class
49
     * @param string $handler
50
     * @return \ByJG\RestServer\RoutePattern
51
     */
52
    public static function get($pattern, $function, $class = null, $handler = null)
53
    {
54
        return new RoutePattern('GET', $pattern, $handler, $function, $class);
55
    }
56
57
    /**
58
     * RoutePattern Factory for "POST" method
59
     *
60
     * @param string $pattern
61
     * @param string $function
62
     * @param string $class
63
     * @param string $handler
64
     * @return \ByJG\RestServer\RoutePattern
65
     */
66
    public static function post($pattern, $function, $class = null, $handler = null)
67
    {
68
        return new RoutePattern('POST', $pattern, $handler, $function, $class);
69
    }
70
71
    /**
72
     * RoutePattern Factory for "PUT" method
73
     *
74
     * @param string $pattern
75
     * @param string $function
76
     * @param string $class
77
     * @param string $handler
78
     * @return \ByJG\RestServer\RoutePattern
79
     */
80
    public static function put($pattern, $function, $class = null, $handler = null)
81
    {
82
        return new RoutePattern('PUT', $pattern, $handler, $function, $class);
83
    }
84
85
    /**
86
     * RoutePattern Factory for "DELETE" method
87
     *
88
     * @param string $pattern
89
     * @param string $function
90
     * @param string $class
91
     * @param string $handler
92
     * @return \ByJG\RestServer\RoutePattern
93
     */
94
    public static function delete($pattern, $function, $class = null, $handler = null)
95
    {
96
        return new RoutePattern('DELETE', $pattern, $handler, $function, $class);
97
    }
98
}
99