Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
CheckBegin.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 
7 class CheckBegin extends CheckData
8 {
9  protected $parentName;
10  protected $famId;
11  protected $famClass;
12  protected $famTitle;
13  protected $famName;
14  /**
15  * @var Doc
16  */
17  protected $doc;
18  /**
19  * @param array $data
20  * @param Doc $doc
21  * @return CheckBegin
22  */
23  function check(array $data, &$doc = null)
24  {
25 
26  $this->parentName = ($data[1] == "--" || $data[1] == "-") ? "" : $data[1];
27  $this->famId = isset($data[3]) ? $data[3] : 0;
28  $this->famTitle = isset($data[2]) ? $data[2] : null;
29  $this->famClass = isset($data[4]) ? ($data[4] == "--" ? "" : $data[4]) : null;
30  $this->famName = isset($data[5]) ? $data[5] : '';
31  $this->checkName();
32  $this->checkInheritance();
33  $this->checkTitle();
34 
35  return $this;
36  }
37  /**
38  * check class file when it is a workflow
39  * @param array $data
40  * @param Doc $doc
41  * @return CheckBegin
42  */
43  function checkClass(array $data, &$doc = null)
44  {
45  $this->doc = $doc;
46  if (strstr($doc->usefor, 'W')) {
47  if ($doc->classname) {
48  $checkW = new CheckWorkflow($doc->classname, $doc->name);
49  $checkCr = $checkW->verifyWorkflowClass();
50  if (count($checkCr) > 0) {
51  $this->addError(implode("\n", $checkCr));
52  }
53  }
54  } elseif ($this->famClass) {
55  $this->checkClassFile($this->famClass);
56  }
57 
58  return $this;
59  }
60 
61  private function getClassFile($className)
62  {
63  return sprintf('FDL/Class.%s.php', $className);
64  }
65  private function checkClassFile($phpfile)
66  {
67  if ($phpfile) {
68  $fileName = realpath($this->getClassFile($phpfile));
69  if ($fileName) {
70  if (CheckClass::phpLintFile($fileName, $output) === false) {
71  $this->addError(ErrorCode::getError('FAM0400', $this->getClassFile($phpfile) , $this->famName, implode("\n", $output)));
72  }
73  } else {
74  $this->addError(ErrorCode::getError('FAM0401', $this->getClassFile($phpfile) , $this->famName));
75  }
76  }
77  }
78 
79  protected function checkName()
80  {
81  if (!$this->famName) {
82  $this->addError(ErrorCode::getError('FAM0500', $this->famTitle));
83  } elseif (!preg_match('/^[a-z][a-z0-9_]{1,63}$/i', $this->famName)) {
84  $this->addError(ErrorCode::getError('FAM0501', $this->famName));
85  } else {
86  $f = getTDoc('', $this->famName);
87  if ($f && $f["doctype"] != 'C') {
88  $this->addError(ErrorCode::getError('FAM0502', $this->famName, $f["title"]));
89  }
90  }
91  }
92 
93  protected function checkTitle()
94  {
95  if ($this->famTitle) {
96  if (mb_strlen($this->famTitle) > 255) {
97  $this->addError(ErrorCode::getError('FAM0200', $this->famTitle, $this->famName));
98  } elseif (preg_match("/\n|\t|\r/", $this->famTitle)) {
99  $this->addError(ErrorCode::getError('FAM0201', $this->famTitle, $this->famName));
100  }
101  }
102  }
103 
104  protected function checkInheritance()
105  {
106  if ($this->parentName) {
107  if ($this->famName == $this->parentName) {
108  $this->addError(ErrorCode::getError('FAM0101', $this->famName));
109  } else {
110  $p = getTdoc('', $this->parentName);
111  if (!$p) {
112  $this->addError(ErrorCode::getError('FAM0100', $this->parentName, $this->famName));
113  } elseif ($p["doctype"] != 'C') {
114  $this->addError(ErrorCode::getError('FAM0104', $this->parentName, $this->famName));
115  } else {
116 
117  $me = getTdoc('', $this->famName);
118  if ($me) {
119  $fromId = $me['fromid'];
120  $fromName = getNameFromId(getDbAccess() , $fromId);
121  if ($fromName == '') {
122  throw new \Dcp\Exception("FAM0603", $fromId, $this->famName);
123  }
124  if (($fromName != $this->parentName) && ($fromId != $this->parentName)) {
125  //print_r($p);
126  $this->addError(ErrorCode::getError('FAM0102', $fromName, $this->parentName, $this->famName));
127  }
128  }
129  }
130  }
131  }
132  }
133 }
checkClass(array $data, &$doc=null)
Definition: CheckBegin.php:43
getTDoc($dbaccess, $id, $sqlfilters=array(), $result=array())
static getError($code, $args=null)
Definition: ErrorCode.php:27
static phpLintFile($fileName, &$output)
Definition: CheckClass.php:86
checkInheritance()
Definition: CheckBegin.php:104
addError($msg)
Definition: CheckData.php:29
$className
getDbAccess()
Definition: Lib.Common.php:368
getNameFromId($dbaccess, $id)
Check worflow definition when importing definition.
$data
check(array $data, &$doc=null)
Definition: CheckBegin.php:23
← centre documentaire © anakeen