Completed
Push — master ( f42a52...0a9499 )
by Thierry
02:50 queued 01:16
created

ParameterFactory::numeric()   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
 * RequestFactory.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\Request\Factory;
17
18
use Jaxon\Request\Support\CallableObject;
19
use Jaxon\Request\Support\CallableRepository;
20
use Jaxon\Utils\Pagination\Paginator;
21
22
// Extends Parameter for compatibility with older versions (see function rq())
23
class ParameterFactory
24
{
25
    /**
26
     * Make a parameter of type Parameter::FORM_VALUES
27
     *
28
     * @param string        $sFormId                The id of the HTML form
29
     *
30
     * @return Parameter
31
     */
32
    public function form($sFormId)
33
    {
34
        return new Parameter(Parameter::FORM_VALUES, $sFormId);
35
    }
36
37
    /**
38
     * Make a parameter of type Parameter::INPUT_VALUE
39
     *
40
     * @param string $sInputId the id of the HTML input element
41
     *
42
     * @return Parameter
43
     */
44
    public function input($sInputId)
45
    {
46
        return new Parameter(Parameter::INPUT_VALUE, $sInputId);
47
    }
48
49
    /**
50
     * Make a parameter of type Parameter::CHECKED_VALUE
51
     *
52
     * @param string $sInputId the name of the HTML form element
53
     *
54
     * @return Parameter
55
     */
56
    public function checked($sInputId)
57
    {
58
        return new Parameter(Parameter::CHECKED_VALUE, $sInputId);
59
    }
60
61
    /**
62
     * Make a parameter of type Parameter::CHECKED_VALUE
63
     *
64
     * @param string $sInputId the name of the HTML form element
65
     *
66
     * @return Parameter
67
     */
68
    public function select($sInputId)
69
    {
70
        return self::input($sInputId);
71
    }
72
73
    /**
74
     * Make a parameter of type Parameter::ELEMENT_INNERHTML
75
     *
76
     * @param string $sElementId the id of the HTML element
77
     *
78
     * @return Parameter
79
     */
80
    public function html($sElementId)
81
    {
82
        return new Parameter(Parameter::ELEMENT_INNERHTML, $sElementId);
83
    }
84
85
    /**
86
     * Make a parameter of type Parameter::QUOTED_VALUE
87
     *
88
     * @param string $sValue the value of the parameter
89
     *
90
     * @return Parameter
91
     */
92
    public function string($sValue)
93
    {
94
        return new Parameter(Parameter::QUOTED_VALUE, $sValue);
95
    }
96
97
    /**
98
     * Make a parameter of type Parameter::NUMERIC_VALUE
99
     *
100
     * @param numeric $nValue the value of the parameter
101
     *
102
     * @return Parameter
103
     */
104
    public function numeric($nValue)
105
    {
106
        return new Parameter(Parameter::NUMERIC_VALUE, intval($nValue));
107
    }
108
109
    /**
110
     * Make a parameter of type Parameter::NUMERIC_VALUE
111
     *
112
     * @param numeric $nValue the value of the parameter
113
     *
114
     * @return Parameter
115
     */
116
    public function int($nValue)
117
    {
118
        return self::numeric($nValue);
119
    }
120
121
    /**
122
     * Make a parameter of type Parameter::JS_VALUE
123
     *
124
     * @param string $sValue the javascript code of the parameter
125
     *
126
     * @return Parameter
127
     */
128
    public function javascript($sValue)
129
    {
130
        return new Parameter(Parameter::JS_VALUE, $sValue);
131
    }
132
133
    /**
134
     * Make a parameter of type Parameter::JS_VALUE
135
     *
136
     * @param string $sValue the javascript code of the parameter
137
     *
138
     * @return Parameter
139
     */
140
    public function js($sValue)
141
    {
142
        return self::javascript($sValue);
143
    }
144
145
    /**
146
     * Make a parameter of type Parameter::PAGE_NUMBER
147
     *
148
     * @return Parameter
149
     */
150
    public function page()
151
    {
152
        // By default, the value of a parameter of type Parameter::PAGE_NUMBER is 0.
153
        return new Parameter(Parameter::PAGE_NUMBER, 0);
154
    }
155
}
156