ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ValidatorAtom.php
Go to the documentation of this file.
1 <?php
2 
10 {
14  protected $context;
15 
19  protected $obj;
20 
24  protected $member;
25 
29  protected $contents;
30 
31  public function __construct($context, $obj, $member)
32  {
33  $this->context = $context;
34  $this->obj = $obj;
35  $this->member = $member;
36  $this->contents =& $obj->$member;
37  }
38 
42  public function assertIsString()
43  {
44  if (!is_string($this->contents)) {
45  $this->error('must be a string');
46  }
47  return $this;
48  }
49 
53  public function assertIsBool()
54  {
55  if (!is_bool($this->contents)) {
56  $this->error('must be a boolean');
57  }
58  return $this;
59  }
60 
64  public function assertIsArray()
65  {
66  if (!is_array($this->contents)) {
67  $this->error('must be an array');
68  }
69  return $this;
70  }
71 
75  public function assertNotNull()
76  {
77  if ($this->contents === null) {
78  $this->error('must not be null');
79  }
80  return $this;
81  }
82 
86  public function assertAlnum()
87  {
88  $this->assertIsString();
89  if (!ctype_alnum($this->contents)) {
90  $this->error('must be alphanumeric');
91  }
92  return $this;
93  }
94 
98  public function assertNotEmpty()
99  {
100  if (empty($this->contents)) {
101  $this->error('must not be empty');
102  }
103  return $this;
104  }
105 
109  public function assertIsLookup()
110  {
111  $this->assertIsArray();
112  foreach ($this->contents as $v) {
113  if ($v !== true) {
114  $this->error('must be a lookup array');
115  }
116  }
117  return $this;
118  }
119 
124  protected function error($msg)
125  {
126  throw new HTMLPurifier_ConfigSchema_Exception(ucfirst($this->member) . ' in ' . $this->context . ' ' . $msg);
127  }
128 }
129 
130 // vim: et sw=4 sts=4