HTMLPurifier 4.4.0
/home/ezyang/Dev/htmlpurifier/library/HTMLPurifier/ConfigSchema/ValidatorAtom.php
Go to the documentation of this file.
00001 <?php
00002 
00009 class HTMLPurifier_ConfigSchema_ValidatorAtom
00010 {
00011 
00012     protected $context, $obj, $member, $contents;
00013 
00014     public function __construct($context, $obj, $member) {
00015         $this->context     = $context;
00016         $this->obj         = $obj;
00017         $this->member      = $member;
00018         $this->contents    =& $obj->$member;
00019     }
00020 
00021     public function assertIsString() {
00022         if (!is_string($this->contents)) $this->error('must be a string');
00023         return $this;
00024     }
00025 
00026     public function assertIsBool() {
00027         if (!is_bool($this->contents)) $this->error('must be a boolean');
00028         return $this;
00029     }
00030 
00031     public function assertIsArray() {
00032         if (!is_array($this->contents)) $this->error('must be an array');
00033         return $this;
00034     }
00035 
00036     public function assertNotNull() {
00037         if ($this->contents === null) $this->error('must not be null');
00038         return $this;
00039     }
00040 
00041     public function assertAlnum() {
00042         $this->assertIsString();
00043         if (!ctype_alnum($this->contents)) $this->error('must be alphanumeric');
00044         return $this;
00045     }
00046 
00047     public function assertNotEmpty() {
00048         if (empty($this->contents)) $this->error('must not be empty');
00049         return $this;
00050     }
00051 
00052     public function assertIsLookup() {
00053         $this->assertIsArray();
00054         foreach ($this->contents as $v) {
00055             if ($v !== true) $this->error('must be a lookup array');
00056         }
00057         return $this;
00058     }
00059 
00060     protected function error($msg) {
00061         throw new HTMLPurifier_ConfigSchema_Exception(ucfirst($this->member) . ' in ' . $this->context . ' ' . $msg);
00062     }
00063 
00064 }
00065 
00066 // vim: et sw=4 sts=4