Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
CheckProp.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Checking family properties parameters
8  * @class CheckProp
9  * @brief Check PROP import lines
10  * @see ErrorCodePRFL
11  */
12 class CheckProp extends CheckData
13 {
14  /**
15  * Property's name
16  * @var string
17  */
18  public $propName = '';
19  /**
20  * Parameters' (pName, pValue) tuples
21  * @var array
22  */
23  public $parameters = array();
24 
25  /**
26  *
27  */
28  private static $parameterClassMap = array(
29  'sort' => 'sortProperties'
30  );
31  /**
32  * Check validity of a PROP import line
33  *
34  * @param array $data
35  * @param \DocFam $docfam
36  * @return CheckProp
37  */
38  public function check(array $data, &$docfam = null)
39  {
40  array_shift($data);
41 
42  if (count($data) < 1) {
43  $this->addError(ErrorCode::getError('PROP0100'));
44  return $this;
45  }
46  $propName = array_shift($data);
48  $this->addError(ErrorCode::getError('PROP0101', $propName));
49  return $this;
50  }
51 
52  if (count($data) < 1) {
53  $this->addError(ErrorCode::getError('PROP0200'));
54  return $this;
55  }
56  $parameters = array();
57  while ($value = array_shift($data)) {
58  $tuple = self::checkValueSyntax($value);
59  if ($tuple === false) {
60  $this->addError(ErrorCode::getError('PROP0201', $value));
61  return $this;
62  }
63  if (!self::checkParameterClassKey($tuple['name'])) {
64  $this->addError(ErrorCode::getError('PROP0202', $tuple['name']));
65  return $this;
66  }
67  $parameters []= $tuple;
68  }
69 
70  $this->propName = $propName;
71  $this->parameters = $parameters;
72  return $this;
73  }
74 
75  /**
76  * Check validity of a parameter's tuple string value ("<pName>=<pValue>")
77  *
78  * @static
79  * @param string $value The parameter's tuple value
80  * @return array|bool boolean false on error, or the parsed parameter tuple on success
81  */
82  public static function checkValueSyntax($value) {
83  if(!preg_match('/^(?P<name>[a-z]{1,63})=(?P<value>.*)$/i', $value, $m)) {
84  return false;
85  }
86  return array(
87  'name' => $m['name'],
88  'value' => $m['value']
89  );
90  }
91 
92  /**
93  * Check that the parameter's name has a valid and known class name
94  *
95  * @static
96  * @param string $pName The parameter's name
97  * @return bool boolean false if not valid, or boolean true if valid
98  */
99  public static function checkParameterClassKey($pName) {
100  return in_array($pName, array_keys(self::$parameterClassMap));
101  }
102 
103  /**
104  * Helper method to get the class name for a given parameter's name
105  * @static
106  * @param null $key
107  * @return array
108  */
109  public static function getParameterClassMap($key = null) {
110  if ($key === null) {
111  return self::$parameterClassMap;
112  }
113  return self::$parameterClassMap[$key];
114  }
115 }
Check PROP import lines.
Definition: CheckProp.php:12
static checkValueSyntax($value)
Definition: CheckProp.php:82
static getError($code, $args=null)
Definition: ErrorCode.php:27
static checkParameterClassKey($pName)
Definition: CheckProp.php:99
static getParameterClassMap($key=null)
Definition: CheckProp.php:109
static checkAttrSyntax($attrid)
Definition: checkAttr.php:609
addError($msg)
Definition: CheckData.php:29
check(array $data, &$docfam=null)
Definition: CheckProp.php:38
$value
$data
← centre documentaire © anakeen