Completed
Push — master ( 331d03...c48bd4 )
by Thierry
01:44
created

Parameter::int()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Factory.php - Jaxon Request Factory
5
 *
6
 * Create Jaxon client side requests, which will generate the client script necessary
7
 * to invoke a jaxon request from the browser to registered objects.
8
 *
9
 * @package jaxon-core
10
 * @author Thierry Feuzeu <[email protected]>
11
 * @copyright 2016 Thierry Feuzeu <[email protected]>
12
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
13
 * @link https://github.com/jaxon-php/jaxon-core
14
 */
15
16
namespace Jaxon\Factory;
17
18
use Jaxon\Jaxon;
19
use Jaxon\Request\Parameter as RequestParameter;
20
21
class Parameter
22
{
23
    /**
24
     * Make a parameter of type Jaxon::FORM_VALUES
25
     *
26
     * @param string        $sFormId                The id of the HTML form
27
     *
28
     * @return RequestParameter
29
     */
30
    public function form($sFormId)
31
    {
32
        return new RequestParameter(Jaxon::FORM_VALUES, $sFormId);
33
    }
34
35
    /**
36
     * Make a parameter of type Jaxon::INPUT_VALUE
37
     *
38
     * @param string $sInputId the id of the HTML input element
39
     *
40
     * @return RequestParameter
41
     */
42
    public function input($sInputId)
43
    {
44
        return new RequestParameter(Jaxon::INPUT_VALUE, $sInputId);
45
    }
46
47
    /**
48
     * Make a parameter of type Jaxon::CHECKED_VALUE
49
     *
50
     * @param string $sInputId the name of the HTML form element
51
     *
52
     * @return RequestParameter
53
     */
54
    public function checked($sInputId)
55
    {
56
        return new RequestParameter(Jaxon::CHECKED_VALUE, $sInputId);
57
    }
58
59
    /**
60
     * Make a parameter of type Jaxon::CHECKED_VALUE
61
     *
62
     * @param string $sInputId the name of the HTML form element
63
     *
64
     * @return RequestParameter
65
     */
66
    public function select($sInputId)
67
    {
68
        return self::input($sInputId);
69
    }
70
71
    /**
72
     * Make a parameter of type Jaxon::ELEMENT_INNERHTML
73
     *
74
     * @param string $sElementId the id of the HTML element
75
     *
76
     * @return RequestParameter
77
     */
78
    public function html($sElementId)
79
    {
80
        return new RequestParameter(Jaxon::ELEMENT_INNERHTML, $sElementId);
81
    }
82
83
    /**
84
     * Make a parameter of type Jaxon::QUOTED_VALUE
85
     *
86
     * @param string $sValue the value of the parameter
87
     *
88
     * @return RequestParameter
89
     */
90
    public function string($sValue)
91
    {
92
        return new RequestParameter(Jaxon::QUOTED_VALUE, $sValue);
93
    }
94
95
    /**
96
     * Make a parameter of type Jaxon::NUMERIC_VALUE
97
     *
98
     * @param numeric $nValue the value of the parameter
99
     *
100
     * @return RequestParameter
101
     */
102
    public function numeric($nValue)
103
    {
104
        return new RequestParameter(Jaxon::NUMERIC_VALUE, intval($nValue));
105
    }
106
107
    /**
108
     * Make a parameter of type Jaxon::NUMERIC_VALUE
109
     *
110
     * @param numeric $nValue the value of the parameter
111
     *
112
     * @return RequestParameter
113
     */
114
    public function int($nValue)
115
    {
116
        return self::numeric($nValue);
117
    }
118
119
    /**
120
     * Make a parameter of type Jaxon::JS_VALUE
121
     *
122
     * @param string $sValue the javascript code of the parameter
123
     *
124
     * @return RequestParameter
125
     */
126
    public function javascript($sValue)
127
    {
128
        return new RequestParameter(Jaxon::JS_VALUE, $sValue);
129
    }
130
131
    /**
132
     * Make a parameter of type Jaxon::JS_VALUE
133
     *
134
     * @param string $sValue the javascript code of the parameter
135
     *
136
     * @return RequestParameter
137
     */
138
    public function js($sValue)
139
    {
140
        return self::javascript($sValue);
141
    }
142
143
    /**
144
     * Make a parameter of type Jaxon::PAGE_NUMBER
145
     *
146
     * @return RequestParameter
147
     */
148
    public function page()
149
    {
150
        // By default, the value of a parameter of type Jaxon::PAGE_NUMBER is 0.
151
        return new RequestParameter(Jaxon::PAGE_NUMBER, 0);
152
    }
153
}
154