4 * Fluent interface for validating the contents of member variables.
5 * This should be immutable. See HTMLPurifier_ConfigSchema_Validator for
6 * use-cases. We name this an 'atom' because it's ONLY for validations that
7 * are independent and usually scalar.
9 class HTMLPurifier_ConfigSchema_ValidatorAtom
31 public function __construct($context, $obj, $member)
33 $this->context
= $context;
35 $this->member
= $member;
36 $this->contents
=& $obj->$member;
40 * @return HTMLPurifier_ConfigSchema_ValidatorAtom
42 public function assertIsString()
44 if (!is_string($this->contents
)) {
45 $this->error('must be a string');
51 * @return HTMLPurifier_ConfigSchema_ValidatorAtom
53 public function assertIsBool()
55 if (!is_bool($this->contents
)) {
56 $this->error('must be a boolean');
62 * @return HTMLPurifier_ConfigSchema_ValidatorAtom
64 public function assertIsArray()
66 if (!is_array($this->contents
)) {
67 $this->error('must be an array');
73 * @return HTMLPurifier_ConfigSchema_ValidatorAtom
75 public function assertNotNull()
77 if ($this->contents
=== null) {
78 $this->error('must not be null');
84 * @return HTMLPurifier_ConfigSchema_ValidatorAtom
86 public function assertAlnum()
88 $this->assertIsString();
89 if (!ctype_alnum($this->contents
)) {
90 $this->error('must be alphanumeric');
96 * @return HTMLPurifier_ConfigSchema_ValidatorAtom
98 public function assertNotEmpty()
100 if (empty($this->contents
)) {
101 $this->error('must not be empty');
107 * @return HTMLPurifier_ConfigSchema_ValidatorAtom
109 public function assertIsLookup()
111 $this->assertIsArray();
112 foreach ($this->contents
as $v) {
114 $this->error('must be a lookup array');
122 * @throws HTMLPurifier_ConfigSchema_Exception
124 protected function error($msg)
126 throw new HTMLPurifier_ConfigSchema_Exception(ucfirst($this->member
) . ' in ' . $this->context
. ' ' . $msg);
130 // vim: et sw=4 sts=4