File: Zend_Validate-NotEmpty.xml

package info (click to toggle)
zendframework 1.12.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 133,584 kB
  • sloc: xml: 1,311,829; php: 570,173; sh: 170; makefile: 125; sql: 121
file content (211 lines) | stat: -rw-r--r-- 7,862 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect2 id="zend.validate.set.notempty">
    <title>NotEmpty</title>

    <para>
        This validator allows you to validate if a given value is not empty. This is often useful
        when working with form elements or other user input, where you can use it to ensure required
        elements have values associated with them.
    </para>

    <sect3 id="zend.validate.set.notempty.options">
        <title>Supported options for Zend_Validate_NotEmpty</title>

        <para>
            The following options are supported for <classname>Zend_Validate_NotEmpty</classname>:
        </para>

        <itemizedlist>
            <listitem>
                <para>
                    <emphasis><property>type</property></emphasis>: Sets the type of validation
                    which will be processed. For details take a look into <link
                        linkend="zend.validate.set.notempty.types">this section</link>.
                </para>
            </listitem>
        </itemizedlist>
    </sect3>

    <sect3 id="zend.validate.set.notempty.default">
        <title>Default behaviour for Zend_Validate_NotEmpty</title>

        <para>
            By default, this validator works differently than you would expect when you've worked
            with <acronym>PHP</acronym>'s <methodname>empty()</methodname> function. In
            particular, this validator will evaluate both the integer <emphasis>0</emphasis> and
            string '<emphasis>0</emphasis>' as empty.
        </para>

        <programlisting language="php"><![CDATA[
$valid = new Zend_Validate_NotEmpty();
$value  = '';
$result = $valid->isValid($value);
// returns false
]]></programlisting>

        <note>
            <title>Default behaviour differs from PHP</title>

            <para>
                Without providing configuration, <classname>Zend_Validate_NotEmpty</classname>'s
                behaviour differs from <acronym>PHP</acronym>.
            </para>
        </note>
    </sect3>

    <sect3 id="zend.validate.set.notempty.types">
        <title>Changing behaviour for Zend_Validate_NotEmpty</title>

        <para>
            Some projects have differing opinions of what is considered an "empty" value: a string
            with only whitespace might be considered empty, or <emphasis>0</emphasis> may be
            considered non-empty (particularly for boolean sequences). To accomodate differing
            needs, <classname>Zend_Validate_NotEmpty</classname> allows you to configure which types
            should be validated as empty and which not.
        </para>

        <para>
            The following types can be handled:
        </para>

        <itemizedlist>
            <listitem>
                <para>
                    <emphasis>boolean</emphasis>: Returns <constant>FALSE</constant> when the
                    boolean value is <constant>FALSE</constant>.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis>integer</emphasis>: Returns <constant>FALSE</constant> when an integer
                    <emphasis>0</emphasis> value is given. Per default this validation is not
                    activated and returns <constant>TRUE</constant> on any integer values.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis>float</emphasis>: Returns <constant>FALSE</constant> when an float
                    <emphasis>0.0</emphasis> value is given. Per default this validation is not
                    activated and returns <constant>TRUE</constant> on any float values.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis>string</emphasis>: Returns <constant>FALSE</constant> when an empty
                    string <emphasis>''</emphasis> is given.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis>zero</emphasis>: Returns <constant>FALSE</constant> when the single
                    character zero (<emphasis>'0'</emphasis>) is given.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis>empty_array</emphasis>: Returns <constant>FALSE</constant> when an
                    empty <emphasis>array</emphasis> is given.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis>null</emphasis>: Returns <constant>FALSE</constant> when an
                    <constant>NULL</constant> value is given.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis>php</emphasis>: Returns <constant>FALSE</constant> on the same reasons
                    where <acronym>PHP</acronym> method <methodname>empty()</methodname> would
                    return <constant>TRUE</constant>.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis>space</emphasis>: Returns <constant>FALSE</constant> when an string
                    is given which contains only whitespaces.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis>object</emphasis>: Returns <constant>TRUE</constant>.
                    <constant>FALSE</constant> will be returned when <property>object</property> is
                    not allowed but an object is given.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis>object_string</emphasis>: Returns <constant>FALSE</constant> when an
                    object is given and it's <methodname>__toString()</methodname> method returns an
                   empty string.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis>object_count</emphasis>: Returns <constant>FALSE</constant> when an
                    object is given, it has an <classname>Countable</classname> interface and it's
                    count is 0.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis>all</emphasis>: Returns <constant>FALSE</constant> on all above types.
                </para>
            </listitem>
        </itemizedlist>

        <para>
            All other given values will return <constant>TRUE</constant> per default.
        </para>

        <para>
            There are several ways to select which of the above types are validated. You can give
            one or multiple types and add them, you can give an array, you can use constants, or you
            can give a textual string. See the following examples:
        </para>

        <programlisting language="php"><![CDATA[
// Returns false on 0
$validator = new Zend_Validate_NotEmpty(Zend_Validate_NotEmpty::INTEGER);

// Returns false on 0 or '0'
$validator = new Zend_Validate_NotEmpty(
    Zend_Validate_NotEmpty::INTEGER + Zend_NotEmpty::ZERO
);

// Returns false on 0 or '0'
$validator = new Zend_Validate_NotEmpty(array(
    Zend_Validate_NotEmpty::INTEGER,
    Zend_Validate_NotEmpty::ZERO
));

// Returns false on 0 or '0'
$validator = new Zend_Validate_NotEmpty(array(
    'integer',
    'zero',
));
]]></programlisting>

        <para>
            You can also provide an instance of <classname>Zend_Config</classname> to set the
            desired types. To set types after instantiation, use the
            <methodname>setType()</methodname> method.
        </para>
    </sect3>
</sect2>
<!--
vim:se ts=4 sw=4 et:
-->