18 private $lineType =
'';
22 private $structAttr = null;
23 private $types = array(
51 private $noValueTypes = array(
58 private $visibilities = array(
68 private $yesno = array(
72 private $postgreSqlWords = array(
168 private $isModAttr =
false;
172 $this->lineType = $data[0];
175 $this->attrid = strtolower($this->structAttr->id);
176 $this->isModAttr = (strtolower($data[0]) ==
"modattr");
181 $this->checkVisibility();
182 $this->checkIsAbstract();
183 $this->checkIsTitle();
184 $this->checkIsNeeded();
185 if ($this->checkPhpFile()) {
186 $this->checkPhpFunctionOrMethod();
189 $this->checkPhpConstraint();
190 $this->checkOptions();
197 private function checkId()
199 if (empty($this->attrid)) {
204 if (in_array($this->attrid, $this->postgreSqlWords)) {
208 if (in_array($this->attrid, $doc->fields)) {
218 private function checkSet()
220 $setId = strtolower($this->structAttr->setid);
221 if ($setId && ($this->attrid == $setId)) {
224 if ($this->isNodeNeedSet()) {
234 if ($this->getType() ==
'tab') {
244 private function checkType()
246 $type = $this->structAttr->type;
248 if (!$this->isModAttr) {
251 $this->checkModAttrType();
253 } elseif (!in_array(
$type, $this->types)) {
254 $basicType = $this->getType();
257 } elseif (!in_array($basicType, $this->types)) {
260 $format = $this->getFormat();
262 if (in_array($basicType, array(
269 $a = @sprintf($format, 123);
275 if ($this->isModAttr) {
276 $this->checkModAttrType();
280 if ($this->isModAttr) {
281 $this->checkModAttrType();
288 private function checkModAttrType()
290 $type = $this->structAttr->type;
292 $basicType = $this->getType();
293 $originAttr = $this->getOriginAttr($this->attrid, $this->doc->fromid, $this->doc->id);
295 $originType = $originAttr[
"type"];
296 $basicOriginType = $this->getType($originType);
297 if ($basicOriginType ==
"enum") {
298 if (trim($this->structAttr->phpfunc) !=
'') {
303 if (!$this->isCompatibleModType($basicOriginType, $basicType)) {
312 private function getOriginAttr($attrid, $fromid,
$docid)
314 $sqlPattern = <<<
'SQL'
315 select * from docattr where
docid in (
316 with recursive adocfam(
id, fromid, famname) as (
317 select docfam.id, docfam.fromid, docfam.name as famname from docfam where docfam.id=%d or docfam.id=%d
319 select docfam.id, docfam.fromid, docfam.name as famname from docfam, adocfam where docfam.id = adocfam.fromid
320 ) select
id from adocfam
321 ) and
id=
'%s' order by
docid desc;
324 $attrid = pg_escape_string($attrid);
325 $sql = sprintf($sqlPattern,
$docid, $fromid, $attrid);
333 private function isCompatibleModType($typeA, $typeB)
335 if ($typeA == $typeB)
return true;
336 $compatibleText = array(
341 if (in_array($typeA, $compatibleText) && in_array($typeB, $compatibleText))
return true;
342 $compatibleNumbers = array(
346 if (in_array($typeA, $compatibleNumbers) && in_array($typeB, $compatibleNumbers))
return true;
347 $compatibleRelation = array(
352 if (in_array($typeA, $compatibleRelation) && in_array($typeB, $compatibleRelation))
return true;
360 private function checkOrder()
362 $order = $this->structAttr->order;
364 if ($this->isNodeNeedOrder() && empty($order)) {
367 if (!is_numeric($order)) {
368 if ($order === \dcp\FamilyAbsoluteOrder::firstOrder || $order === \dcp\FamilyAbsoluteOrder::autoOrder) {
382 private function checkVisibility()
384 $vis = $this->structAttr->visibility;
386 if (!$this->isModAttr) {
389 } elseif (!in_array($vis, $this->visibilities)) {
392 $type = $this->getType();
393 if ($vis ==
"U" &&
$type && (
$type !=
"array")) {
399 private function checkIsAbstract()
401 $isAbstract = strtolower($this->structAttr->isabstract);
403 if (!in_array($isAbstract, $this->yesno)) {
405 } elseif ($isAbstract ==
'y' && (!$this->isNodeHasValue())) {
411 private function checkIsTitle()
413 $isTitle = strtolower($this->structAttr->istitle);
415 if (!in_array($isTitle, $this->yesno)) {
417 } elseif ($isTitle ==
'y' && (!$this->isNodeHasValue())) {
423 private function checkIsNeeded()
425 $isNeeded = strtolower($this->structAttr->isneeded);
427 if (!in_array($isNeeded, $this->yesno)) {
429 } elseif ($isNeeded ==
'y' && (!$this->isNodeHasValue())) {
437 private function checkPhpFile()
440 $phpFile = trim($this->structAttr->phpfile);
441 if ($phpFile && $phpFile !=
'-' && ($this->getType() !=
"action")) {
442 $phpFile = sprintf(
"EXTERNALS/%s", $phpFile);
443 if (!file_exists($phpFile)) {
447 $realPhpFile = realpath($phpFile);
452 require_once $phpFile;
459 private function checkPhpFunctionOrMethod()
461 $phpFunc = trim($this->structAttr->phpfunc);
462 $phpFile = trim($this->structAttr->phpfile);
463 $type = $this->getType();
464 if ($phpFunc && $phpFunc !=
'-' && (
$type !=
"action") && (
$type !=
"enum")) {
465 if ($phpFile && $phpFile !=
'-') {
467 $this->checkPhpFunction();
470 $this->checkPhpMethod();
475 private function checkEnum()
477 $phpFunc = $this->structAttr->phpfunc;
478 $phpFile = trim($this->structAttr->phpfile);
479 $type = $this->getType();
480 if ((!$phpFile || $phpFile ==
'-') && $phpFunc && (
$type ==
"enum")) {
482 $enums = str_replace(array(
486 $topt = explode(
",", $enums);
487 foreach ($topt as $opt) {
488 if (strpos($opt,
'|') ===
false) {
491 }
else list($enumKey, $enumLabel) = explode(
"|", $opt, 2);
492 if ($enumKey ===
'') {
494 } elseif (!preg_match(
'/^[\x20-\x7E]+$/', $enumKey)) {
496 }
else if ($enumLabel === null) {
503 private function checkPhpFunction()
505 $phpFunc = trim($this->structAttr->phpfunc);
506 $phpFile = trim($this->structAttr->phpfile);
507 $type = $this->getType();
508 if ($phpFunc && $phpFunc !=
'-' && (
$type !=
"action")) {
509 if ($phpFile && $phpFile !=
'-') {
512 $strucFunc = $oParse->parse($phpFunc, (
$type ==
'enum'));
513 if ($strucFunc->getError()) {
516 $phpFuncName = $strucFunc->functionName;
518 $refFunc =
new ReflectionFunction($phpFuncName);
519 if ($refFunc->isInternal()) {
523 $targetFile = $refFunc->getFileName();
524 $realPhpFile = realpath(sprintf(
"EXTERNALS/%s", $phpFile));
525 if ($targetFile != $realPhpFile) {
526 if (!$oParse->appName) {
530 $numArgs = $refFunc->getNumberOfRequiredParameters();
531 if ($numArgs > count($strucFunc->inputs)) {
537 catch(Exception $e) {
548 private function checkPhpMethod()
550 $phpFunc = trim($this->structAttr->phpfunc);
551 $type = $this->getType();
553 if ($this->isModAttr && (!
$type))
return;
555 $strucFunc = $oParse->parse($phpFunc, (
$type ==
'enum'));
556 if ($strucFunc->getError()) {
561 if ($this->lineType ==
'PARAM' && isset($strucFunc->outputs) && count($strucFunc->outputs) > 0) {
567 private function checkPhpConstraint()
569 $constraint = trim($this->structAttr->constraint);
571 if ($this->isModAttr && $constraint ==
'-') {
575 $strucFunc = $oParse->parse($constraint,
true);
576 if ($strucFunc->getError()) {
586 private function checkOptions()
589 $options = trim($this->structAttr->options);
591 $topt = explode(
"|", $options);
592 foreach ($topt as $opt) {
593 if (strpos($opt,
'=') ===
false) {
596 }
else list($optName, $optValue) = explode(
"=", $opt, 2);
597 if (!preg_match(
'/^[a-z_-]{1,63}$/', $optName)) {
599 }
else if ($optValue === null) {
611 if (preg_match(
"/^[A-Z_0-9]{1,63}$/i", $attrid)) {
617 private function getType(
$type = null)
619 if (
$type === null) {
620 $type = trim($this->structAttr->type);
623 if (preg_match(
'/^([a-z]+)\(["\'].+["\']\)$/i',
$type, $reg)) {
625 } elseif (preg_match(
'/^([a-z]+)$/i',
$type, $reg)) {
631 private function getFormat()
633 $type = trim($this->structAttr->type);
636 if (preg_match(
'/^([a-z]+)\(["\'](.+)["\']\)$/i',
$type, $reg)) {
642 private function isNodeNeedSet()
644 if ($this->isModAttr)
return false;
645 $type = $this->getType();
649 private function isNodeNeedOrder()
651 if ($this->isModAttr)
return false;
652 $type = $this->getType();
653 return ((
$type !=
"tab") && (
$type !=
"frame"));
656 private function isNodeHasValue()
659 return (!in_array(
$type, $this->noValueTypes));
680 private $dataOrder = array(
706 foreach ($this->dataOrder as $key) {
707 if ($key ==
'phpfunc') $this->$key = isset($data[$cid]) ? $data[$cid] :
'';
708 else $this->$key = isset($data[$cid]) ? trim($data[$cid]) :
'';
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
check(array $data, &$extra=null)
static getError($code, $args=null)
Check application accesses when importing definition.
static phpLintFile($fileName, &$output)
static checkAttrSyntax($attrid)
__construct(array $data=array())
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)