cvs: pear /MDB parser.php

From: Date: Fri, 23 Aug 2002 13:45:45 +0000
Subject: cvs: pear /MDB parser.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-5905@lists.php.net to get a copy of this message
dickmann Fri Aug 23 09:45:45 2002 EDT Modified files: /pear/MDB parser.php Log: improve boolean handling Index: pear/MDB/parser.php diff -u pear/MDB/parser.php:1.15 pear/MDB/parser.php:1.16 --- pear/MDB/parser.php:1.15 Fri Aug 23 09:00:04 2002 +++ pear/MDB/parser.php Fri Aug 23 09:45:43 2002 @@ -42,7 +42,7 @@ // | Author: Christian Dickmann <dickmann@php.net> | // +----------------------------------------------------------------------+ // -// $Id: parser.php,v 1.15 2002/08/23 13:00:04 dickmann Exp $ +// $Id: parser.php,v 1.16 2002/08/23 13:45:43 dickmann Exp $ // require_once "XML/Parser.php"; @@ -364,10 +364,9 @@ }; break; case 'boolean': - if ($field_value !== '0' && $field_value !== '1') { + if (!$this->is_boolean($field_value)) { return $this->raiseError($xp, '"'.$field_value.'" is not of type "'.$field_def['type'].'"'); } - $field_value = (int) $field_value; break; case 'date': if (!ereg("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})$", $field_value)) { @@ -410,9 +409,30 @@ return FALSE; } - function is_boolean($value) + function is_boolean(&$value) { - if ($value !== '1' && $value !== '0') { + if (is_int($value) && ($value == 0 || $value == 1)) { + return TRUE; + }; + if ($value === '1' || $value === '0') { + $value = (int) $value; + return TRUE; + }; + switch($value) + { + case 'N': + case 'n': + case 'no': + case 'false': + $value = 0; + break; + case 'Y': + case 'y': + case 'yes': + case 'true': + $value = 1; + break; + default: return FALSE; }; return TRUE;

« previous php.pear.cvs (#5905) next »