minor changes

This commit is contained in:
tomas 2005-02-25 04:05:44 +00:00
parent c1fe56c53e
commit 80833376d5

View file

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.1 $ Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/Validator.php,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/Validator.php,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -37,7 +37,9 @@ define('VAL_NOTDEF', 115);
#require_once ""; #require_once "";
/** /**
* Simple XML validator against structure stored in PHP hash-array hierarchy.
* *
* It should be replaced by XML schema validation in the future.
*/ */
class Validator{ class Validator{
/** /**
@ -83,19 +85,11 @@ class Validator{
$attrs = array(); $attrs = array();
foreach($node->attrs as $i=>$attr){ foreach($node->attrs as $i=>$attr){
$attrs[$attr->name] =& $node->attrs[$i]; $attrs[$attr->name] =& $node->attrs[$i];
$permr = ( $listr = $this->isListedAs($fname, $attr->name, 'attrs', 'required');
isset($format[$fname]['attrs']['required']) ? $listi = $this->isListedAs($fname, $attr->name, 'attrs', 'implied');
array_search($attr->name, $format[$fname]['attrs']['required']) : $listn = $this->isListedAs($fname, $attr->name, 'attrs', 'normal');
FALSE if($listr===FALSE && $listi===FALSE && $listn===FALSE)
);
$permi = (
isset($format[$fname]['attrs']['implied']) ?
array_search($attr->name, $format[$fname]['attrs']['implied']) :
FALSE
);
if($permr===FALSE && $permi===FALSE)
return $this->_err(VAL_UNKNOWNA, $attr->name); return $this->_err(VAL_UNKNOWNA, $attr->name);
//else{ var_dump($permr); var_dump($permi); }
} }
if(isset($format[$fname]['attrs'])){ if(isset($format[$fname]['attrs'])){
$fattrs =& $format[$fname]['attrs']; $fattrs =& $format[$fname]['attrs'];
@ -109,22 +103,10 @@ class Validator{
foreach($node->children as $i=>$ch){ foreach($node->children as $i=>$ch){
$chname = strtolower(($ch->ns? $ch->ns.":" : '').$ch->name); $chname = strtolower(($ch->ns? $ch->ns.":" : '').$ch->name);
$childs[$chname] =& $node->children[$i]; $childs[$chname] =& $node->children[$i];
$permo = ( $listo = $this->isListedAs($fname, $chname, 'childs', 'optional');
isset($format[$fname]['childs']['optional']) ? $listr = $this->isListedAs($fname, $chname, 'childs', 'required');
array_search($chname, $format[$fname]['childs']['optional']) : $list1 = $this->isListedAs($fname, $chname, 'childs', 'oneof');
FALSE if($listo===FALSE && $listr===FALSE && $list1===FALSE)
);
$permr = (
isset($format[$fname]['childs']['required']) ?
array_search($chname, $format[$fname]['childs']['required']) :
FALSE
);
$perm1 = (
isset($format[$fname]['childs']['oneof']) ?
array_search($chname, $format[$fname]['childs']['oneof']) :
FALSE
);
if($permo===FALSE && $permr===FALSE && $perm1===FALSE)
return $this->_err(VAL_UNKNOWNE, $chname); return $this->_err(VAL_UNKNOWNE, $chname);
} }
//var_dump($childs); //var_dump($childs);
@ -150,6 +132,20 @@ class Validator{
return TRUE; return TRUE;
} }
/**
*
*/
function isListedAs($fname, $chname, $nType='childs', $reqType='required')
{
$format =& $this->format;
$listed = (
isset($format[$fname][$nType][$reqType]) ?
array_search($chname, $format[$fname][$nType][$reqType]) :
FALSE
);
return $listed;
}
/** /**
* *
*/ */