Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
70ff3b26
Commit
70ff3b26
authored
Sep 02, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored Validator API
parent
d8ac77d5
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
201 additions
and
214 deletions
+201
-214
Validator.php
lib/Doctrine/Validator.php
+12
-7
Country.php
lib/Doctrine/Validator/Country.php
+6
-4
Creditcard.php
lib/Doctrine/Validator/Creditcard.php
+4
-6
Date.php
lib/Doctrine/Validator/Date.php
+5
-5
Driver.php
lib/Doctrine/Validator/Driver.php
+0
-8
Email.php
lib/Doctrine/Validator/Email.php
+17
-18
ErrorStack.php
lib/Doctrine/Validator/ErrorStack.php
+0
-5
Htmlcolor.php
lib/Doctrine/Validator/Htmlcolor.php
+3
-4
Ip.php
lib/Doctrine/Validator/Ip.php
+3
-4
Minlength.php
lib/Doctrine/Validator/Minlength.php
+50
-48
Nospace.php
lib/Doctrine/Validator/Nospace.php
+5
-6
Notblank.php
lib/Doctrine/Validator/Notblank.php
+6
-6
Notnull.php
lib/Doctrine/Validator/Notnull.php
+5
-5
Range.php
lib/Doctrine/Validator/Range.php
+5
-6
Regexp.php
lib/Doctrine/Validator/Regexp.php
+11
-8
Unique.php
lib/Doctrine/Validator/Unique.php
+9
-9
Unsigned.php
lib/Doctrine/Validator/Unsigned.php
+4
-8
Usstate.php
lib/Doctrine/Validator/Usstate.php
+56
-57
No files found.
lib/Doctrine/Validator.php
View file @
70ff3b26
...
...
@@ -136,7 +136,11 @@ class Doctrine_Validator extends Doctrine_Object
}
$validator
=
self
::
getValidator
(
$name
);
if
(
!
$validator
->
validate
(
$record
,
$key
,
$value
,
$args
))
{
$validator
->
invoker
=
$record
;
$validator
->
field
=
$key
;
$validator
->
args
=
$args
;
if
(
!
$validator
->
validate
(
$value
))
{
$errorStack
->
add
(
$key
,
$name
);
//$err[$key] = 'not valid';
...
...
@@ -182,14 +186,15 @@ class Doctrine_Validator extends Doctrine_Object
return
(
count
(
$this
->
stack
)
>
0
);
}
/**
* phpType
* converts a doctrine type to native php type
*
* @param $
doctrineT
ype
* @param $
portableType portable doctrine t
ype
* @return string
*/
public
static
function
phpType
(
$
doctrin
eType
)
public
static
function
phpType
(
$
portabl
eType
)
{
switch
(
$
doctrin
eType
)
{
switch
(
$
portabl
eType
)
{
case
'enum'
:
return
'integer'
;
case
'blob'
:
...
...
@@ -201,7 +206,7 @@ class Doctrine_Validator extends Doctrine_Object
return
'string'
;
break
;
default
:
return
$
doctrin
eType
;
return
$
portabl
eType
;
}
}
/**
...
...
@@ -236,7 +241,7 @@ class Doctrine_Validator extends Doctrine_Object
case
'NULL'
:
return
true
;
break
;
}
;
}
}
/**
* returns the type of loosely typed variable
...
...
@@ -259,6 +264,6 @@ class Doctrine_Validator extends Doctrine_Object
break
;
default
:
return
$type
;
}
;
}
}
}
lib/Doctrine/Validator/Country.php
View file @
70ff3b26
...
...
@@ -277,6 +277,8 @@ class Doctrine_Validator_Country
'zr'
=>
'Zaire'
,
'zw'
=>
'Zimbabwe'
);
/**
* returns all available country codes
*
* @return array
*/
public
static
function
getCountries
()
...
...
@@ -284,15 +286,15 @@ class Doctrine_Validator_Country
return
self
::
$countries
;
}
/**
*
@param Doctrine_Record $record
*
@param string $key
*
checks if given value is a valid country code
*
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
public
function
validate
(
$value
)
{
$value
=
strtolower
(
$value
);
return
isset
(
self
::
$countries
[
$value
]);
}
...
...
lib/Doctrine/Validator/Creditcard.php
View file @
70ff3b26
...
...
@@ -31,17 +31,15 @@
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class
Doctrine_Validator_Creditcard
{
{
/**
* checks if given value is a valid credit card number
*
* @link http://www.owasp.org/index.php/OWASP_Validation_Regex_Repository
* @param Doctrine_Record $record
* @param string $key
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
public
function
validate
(
$value
)
{
return
preg_match
(
'#^((4\d{3})|(5[1-5]\d{2})|(6011)|(7\d{3}))-?\d{4}-?\d{4}-?\d{4}|3[4,7]\d{13}$#'
,
$value
);
}
...
...
lib/Doctrine/Validator/Date.php
View file @
70ff3b26
...
...
@@ -33,18 +33,18 @@
class
Doctrine_Validator_Date
{
/**
*
@param Doctrine_Record $record
*
@param string $key
*
checks if given value is a valid date
*
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
public
function
validate
(
$value
)
{
if
(
empty
(
$value
))
{
return
true
;
}
$e
=
explode
(
"-"
,
$value
);
$e
=
explode
(
'-'
,
$value
);
if
(
count
(
$e
)
!==
3
)
{
return
false
;
}
...
...
lib/Doctrine/Validator/Driver.php
View file @
70ff3b26
...
...
@@ -67,10 +67,6 @@ class Doctrine_Validator_Driver
*/
public
function
__set
(
$arg
,
$value
)
{
if
(
!
isset
(
$this
->
_args
[
$arg
]))
{
throw
new
Doctrine_Plugin_Exception
(
'Unknown argument '
.
$arg
);
}
$this
->
_args
[
$arg
]
=
$value
;
return
$this
;
...
...
@@ -98,10 +94,6 @@ class Doctrine_Validator_Driver
*/
public
function
setArg
(
$arg
,
$value
)
{
if
(
!
isset
(
$this
->
_args
[
$arg
]))
{
throw
new
Doctrine_Plugin_Exception
(
'Unknown argument '
.
$arg
);
}
$this
->
_args
[
$arg
]
=
$value
;
return
$this
;
...
...
lib/Doctrine/Validator/Email.php
View file @
70ff3b26
...
...
@@ -33,22 +33,21 @@
class
Doctrine_Validator_Email
{
/**
* checks if given value is a valid email address
*
* @link http://iamcal.com/publish/articles/php/parsing_email/pdf/
* @param Doctrine_Record $record
* @param string $key
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
public
function
validate
(
$value
)
{
if
(
empty
(
$value
))
{
return
true
;
}
if
(
isset
(
$
args
[
0
]
))
{
$parts
=
explode
(
"@"
,
$value
);
if
(
isset
(
$parts
[
1
])
&&
function_exists
(
"checkdnsrr"
))
{
if
(
!
checkdnsrr
(
$parts
[
1
],
"MX"
))
{
if
(
isset
(
$
this
->
args
))
{
$parts
=
explode
(
'@'
,
$value
);
if
(
isset
(
$parts
[
1
])
&&
function_exists
(
'checkdnsrr'
))
{
if
(
!
checkdnsrr
(
$parts
[
1
],
'MX'
))
{
return
false
;
}
}
...
...
@@ -57,24 +56,24 @@ class Doctrine_Validator_Email
$qtext
=
'[^\\x0d\\x22\\x5c\\x80-\\xff]'
;
$dtext
=
'[^\\x0d\\x5b-\\x5d\\x80-\\xff]'
;
$atom
=
'[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'
;
$quoted
_p
air
=
'\\x5c[\\x00-\\x7f]'
;
$domain
_literal
=
"
\\
x5b(
$dtext
|
$quoted_p
air
)*
\\
x5d"
;
$quoted
_string
=
"
\\
x22(
$qtext
|
$quoted_p
air
)*
\\
x22"
;
$quoted
P
air
=
'\\x5c[\\x00-\\x7f]'
;
$domain
Literal
=
"
\\
x5b(
$dtext
|
$quotedP
air
)*
\\
x5d"
;
$quoted
String
=
"
\\
x22(
$qtext
|
$quotedP
air
)*
\\
x22"
;
$domain_ref
=
$atom
;
$sub
_domain
=
"(
$domain_ref
|
$domain_l
iteral
)"
;
$word
=
"(
$atom
|
$quoted
_s
tring
)"
;
$domain
=
"
$sub
_domain
(
\\
x2e
$sub_d
omain
)+"
;
$sub
Domain
=
"(
$domain_ref
|
$domainL
iteral
)"
;
$word
=
"(
$atom
|
$quoted
S
tring
)"
;
$domain
=
"
$sub
Domain
(
\\
x2e
$subD
omain
)+"
;
/*
following psudocode to allow strict checking - ask pookey about this if you're puzzled
following ps
e
udocode to allow strict checking - ask pookey about this if you're puzzled
if ($this->getValidationOption('strict_checking') == true) {
$domain = "$sub_domain(\\x2e$sub_domain)*";
}
*/
$local
_p
art
=
"
$word
(
\\
x2e
$word
)*"
;
$addr
_spec
=
"
$local_p
art
\\
x40
$domain
"
;
$local
P
art
=
"
$word
(
\\
x2e
$word
)*"
;
$addr
Spec
=
"
$localP
art
\\
x40
$domain
"
;
return
(
bool
)
preg_match
(
"!^
$addr_s
pec
$!D"
,
$value
);
return
(
bool
)
preg_match
(
"!^
$addrS
pec
$!D"
,
$value
);
}
}
lib/Doctrine/Validator/ErrorStack.php
View file @
70ff3b26
...
...
@@ -109,8 +109,6 @@ class Doctrine_Validator_ErrorStack extends Doctrine_Access implements Countable
$this
->
errors
=
array
();
}
/** IteratorAggregate implementation */
/**
* Enter description here...
*
...
...
@@ -120,9 +118,6 @@ class Doctrine_Validator_ErrorStack extends Doctrine_Access implements Countable
{
return
new
ArrayIterator
(
$this
->
errors
);
}
/** Countable implementation */
/**
* Enter description here...
*
...
...
lib/Doctrine/Validator/Htmlcolor.php
View file @
70ff3b26
...
...
@@ -33,13 +33,12 @@
class
Doctrine_Validator_HtmlColor
{
/**
*
@param Doctrine_Record $record
*
@param string $key
*
checks if given value is a valid html color code
*
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
public
function
validate
(
$value
)
{
if
(
!
preg_match
(
"/^#
{
0,1}[0-9]{6
}
$/"
,
$value
))
{
return
false
;
...
...
lib/Doctrine/Validator/Ip.php
View file @
70ff3b26
...
...
@@ -33,13 +33,12 @@
class
Doctrine_Validator_Ip
{
/**
*
@param Doctrine_Record $record
*
@param string $key
*
checks if given value is valid ip address
*
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
public
function
validate
(
$value
)
{
return
(
bool
)
ip2long
(
str_replace
(
"
\0
"
,
''
,
$value
));
}
...
...
lib/Doctrine/Validator/Minlength.php
View file @
70ff3b26
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Validator_Regexp
*
* @package Doctrine
* @category Object Relational Mapping
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Gijs van Dulmen <gijs@vandulmen.net>
*/
class
Doctrine_Validator_Minlength
{
/**
* @param Doctrine_Record $record
* @param string $key
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
{
if
(
isset
(
$args
)
&&
strlen
(
$value
)
<
$args
)
return
false
;
return
true
;
}
}
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Validator_Regexp
*
* @package Doctrine
* @category Object Relational Mapping
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Gijs van Dulmen <gijs@vandulmen.net>
*/
class
Doctrine_Validator_Minlength
{
/**
* checks if given value is more length than the minimum length required
*
* @param mixed $value
* @return boolean
*/
public
function
validate
(
$value
)
{
if
(
isset
(
$this
->
args
)
&&
strlen
(
$value
)
<
$this
->
args
)
{
return
false
;
}
return
true
;
}
}
lib/Doctrine/Validator/Nospace.php
View file @
70ff3b26
...
...
@@ -30,17 +30,16 @@
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class
Doctrine_Validator_Nospace
class
Doctrine_Validator_Nospace
extends
Doctrine_Validator_Driver
{
/**
*
@param Doctrine_Record $record
*
@param string $key
*
checks that value doesn't contain any space chars
*
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
public
function
validate
(
$value
)
{
return
(
$value
===
null
||
!
preg_match
(
'/\s\t\r\n/'
,
$value
));
return
(
$value
===
null
||
!
preg_match
(
'/\s\t\r\n/'
,
$value
));
}
}
lib/Doctrine/Validator/Notblank.php
View file @
70ff3b26
...
...
@@ -30,17 +30,17 @@
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class
Doctrine_Validator_Notblank
class
Doctrine_Validator_Notblank
extends
Doctrine_Validator_Driver
{
/**
* @param Doctrine_Record $record
* @param string $key
* checks that value isn't blank
* a value is blank when its either null or contains only space characters
*
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
public
function
validate
(
$value
)
{
return
(
trim
(
$value
)
!=
''
);
return
(
trim
(
$value
)
!=
=
''
&&
$value
!==
null
);
}
}
lib/Doctrine/Validator/Notnull.php
View file @
70ff3b26
...
...
@@ -30,16 +30,16 @@
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class
Doctrine_Validator_Notnull
class
Doctrine_Validator_Notnull
extends
Doctrine_Validator_Driver
{
/**
*
@param Doctrine_Record $record
*
@param string $key
*
checks that given value isn't null
*
* @param mixed $value
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
)
public
function
validate
(
$value
)
{
return
!
is_null
(
$value
);
return
(
$value
!==
null
);
}
}
lib/Doctrine/Validator/Range.php
View file @
70ff3b26
...
...
@@ -33,18 +33,17 @@
class
Doctrine_Validator_Range
{
/**
*
@param Doctrine_Record $record
*
@param string $key
*
checks if value is within given range
*
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
public
function
validate
(
$value
)
{
if
(
isset
(
$
args
[
0
])
&&
$value
<
$
args
[
0
])
{
if
(
isset
(
$
this
->
args
[
0
])
&&
$value
<
$this
->
args
[
0
])
{
return
false
;
}
if
(
isset
(
$
args
[
1
])
&&
$value
>
$
args
[
1
])
{
if
(
isset
(
$
this
->
args
[
1
])
&&
$value
>
$this
->
args
[
1
])
{
return
false
;
}
return
true
;
...
...
lib/Doctrine/Validator/Regexp.php
View file @
70ff3b26
...
...
@@ -33,23 +33,26 @@
class
Doctrine_Validator_Regexp
{
/**
*
@param Doctrine_Record $record
*
@param string $key
*
checks if given value satisfies a regular expression
*
* @param mixed $value
* @param
string
$args
* @param
mixed
$args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
public
function
validate
(
$value
)
{
if
(
is_array
(
$args
))
{
foreach
(
$args
as
$regexp
)
{
if
(
!
preg_match
(
$args
,
$value
))
{
if
(
!
isset
(
$this
->
args
))
{
return
true
;
}
if
(
is_array
(
$this
->
args
))
{
foreach
(
$this
->
args
as
$regexp
)
{
if
(
!
preg_match
(
$regexp
,
$value
))
{
return
false
;
}
}
return
true
;
}
else
{
if
(
preg_match
(
$args
,
$value
))
{
if
(
preg_match
(
$
this
->
args
,
$value
))
{
return
true
;
}
}
...
...
lib/Doctrine/Validator/Unique.php
View file @
70ff3b26
...
...
@@ -33,21 +33,21 @@
class
Doctrine_Validator_Unique
{
/**
*
@param Doctrine_Record $record
*
@param string $key
*
checks if given value is unique
*
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
public
function
validate
(
$value
)
{
$table
=
$
record
->
getTable
();
$table
=
$
this
->
invoker
->
getTable
();
$pks
=
$table
->
getIdentifier
();
if
(
is_array
(
$pks
)
)
{
$pks
=
join
(
','
,
$pks
);
$pks
=
join
(
','
,
$pks
);
}
$sql
=
'SELECT '
.
$pks
.
' FROM '
.
$table
->
getTableName
()
.
' WHERE '
.
$
key
.
' = ?'
;
$sql
=
'SELECT '
.
$pks
.
' FROM '
.
$table
->
getTableName
()
.
' WHERE '
.
$
this
->
field
.
' = ?'
;
$values
=
array
();
$values
[]
=
$value
;
...
...
@@ -55,11 +55,11 @@ class Doctrine_Validator_Unique
// If the record is not new we need to add primary key checks because its ok if the
// unique value already exists in the database IF the record in the database is the same
// as the one that is validated here.
$state
=
$
record
->
state
();
$state
=
$
this
->
invoker
->
state
();
if
(
!
(
$state
==
Doctrine_Record
::
STATE_TDIRTY
||
$state
==
Doctrine_Record
::
STATE_TCLEAN
))
{
foreach
(
$table
->
getPrimaryKeys
()
as
$pk
)
{
$sql
.=
" AND
{
$pk
}
!= ?"
;
$values
[]
=
$
record
->
$pk
;
$values
[]
=
$
this
->
invoker
->
$pk
;
}
}
...
...
lib/Doctrine/Validator/Unsigned.php
View file @
70ff3b26
...
...
@@ -20,7 +20,7 @@
*/
/**
* Doctrine_Validator_
Enum
* Doctrine_Validator_
Unsigned
*
* @package Doctrine
* @category Object Relational Mapping
...
...
@@ -33,22 +33,18 @@
class
Doctrine_Validator_Unsigned
{
/**
*
@param Doctrine_Record $record
*
@param string $key
*
checks if given value is a valid unsigned integer
*
* @param mixed $value
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
public
function
validate
(
$value
)
{
$int
=
(
int
)
$value
;
if
(
$int
!=
$value
||
$int
<
0
)
{
return
false
;
}
if
(
$int
<
0
)
{
return
false
;
}
return
true
;
}
}
lib/Doctrine/Validator/Usstate.php
View file @
70ff3b26
...
...
@@ -33,72 +33,71 @@
class
Doctrine_Validator_Usstate
{
private
static
$states
=
array
(
"AK"
=>
true
,
"AL"
=>
true
,
"AR"
=>
true
,
"AZ"
=>
true
,
"CA"
=>
true
,
"CO"
=>
true
,
"CT"
=>
true
,
"DC"
=>
true
,
"DE"
=>
true
,
"FL"
=>
true
,
"GA"
=>
true
,
"HI"
=>
true
,
"IA"
=>
true
,
"ID"
=>
true
,
"IL"
=>
true
,
"IN"
=>
true
,
"KS"
=>
true
,
"KY"
=>
true
,
"LA"
=>
true
,
"MA"
=>
true
,
"MD"
=>
true
,
"ME"
=>
true
,
"MI"
=>
true
,
"MN"
=>
true
,
"MO"
=>
true
,
"MS"
=>
true
,
"MT"
=>
true
,
"NC"
=>
true
,
"ND"
=>
true
,
"NE"
=>
true
,
"NH"
=>
true
,
"NJ"
=>
true
,
"NM"
=>
true
,
"NV"
=>
true
,
"NY"
=>
true
,
"OH"
=>
true
,
"OK"
=>
true
,
"OR"
=>
true
,
"PA"
=>
true
,
"PR"
=>
true
,
"RI"
=>
true
,
"SC"
=>
true
,
"SD"
=>
true
,
"TN"
=>
true
,
"TX"
=>
true
,
"UT"
=>
true
,
"VA"
=>
true
,
"VI"
=>
true
,
"VT"
=>
true
,
"WA"
=>
true
,
"WI"
=>
true
,
"WV"
=>
true
,
"WY"
=>
true
'AK'
=>
true
,
'AL'
=>
true
,
'AR'
=>
true
,
'AZ'
=>
true
,
'CA'
=>
true
,
'CO'
=>
true
,
'CT'
=>
true
,
'DC'
=>
true
,
'DE'
=>
true
,
'FL'
=>
true
,
'GA'
=>
true
,
'HI'
=>
true
,
'IA'
=>
true
,
'ID'
=>
true
,
'IL'
=>
true
,
'IN'
=>
true
,
'KS'
=>
true
,
'KY'
=>
true
,
'LA'
=>
true
,
'MA'
=>
true
,
'MD'
=>
true
,
'ME'
=>
true
,
'MI'
=>
true
,
'MN'
=>
true
,
'MO'
=>
true
,
'MS'
=>
true
,
'MT'
=>
true
,
'NC'
=>
true
,
'ND'
=>
true
,
'NE'
=>
true
,
'NH'
=>
true
,
'NJ'
=>
true
,
'NM'
=>
true
,
'NV'
=>
true
,
'NY'
=>
true
,
'OH'
=>
true
,
'OK'
=>
true
,
'OR'
=>
true
,
'PA'
=>
true
,
'PR'
=>
true
,
'RI'
=>
true
,
'SC'
=>
true
,
'SD'
=>
true
,
'TN'
=>
true
,
'TX'
=>
true
,
'UT'
=>
true
,
'VA'
=>
true
,
'VI'
=>
true
,
'VT'
=>
true
,
'WA'
=>
true
,
'WI'
=>
true
,
'WV'
=>
true
,
'WY'
=>
true
);
public
function
getStates
()
{
return
self
::
$states
;
}
/**
* @param Doctrine_Record $record
* @param string $key
* @param mixed $value
* checks if given value is a valid US state code
*
* @param string $args
* @return boolean
*/
public
function
validate
(
Doctrine_Record
$record
,
$key
,
$value
,
$args
)
public
function
validate
(
$value
)
{
return
isset
(
self
::
$states
[
$value
]);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment