File indexing completed on 2024-12-22 05:36:21

0001 <?php
0002 
0003 /**
0004  * Records errors for particular segments of an HTML document such as tokens,
0005  * attributes or CSS properties. They can contain error structs (which apply
0006  * to components of what they represent), but their main purpose is to hold
0007  * errors applying to whatever struct is being used.
0008  */
0009 class HTMLPurifier_ErrorStruct
0010 {
0011 
0012     /**
0013      * Possible values for $children first-key. Note that top-level structures
0014      * are automatically token-level.
0015      */
0016     const TOKEN     = 0;
0017     const ATTR      = 1;
0018     const CSSPROP   = 2;
0019 
0020     /**
0021      * Type of this struct.
0022      * @type string
0023      */
0024     public $type;
0025 
0026     /**
0027      * Value of the struct we are recording errors for. There are various
0028      * values for this:
0029      *  - TOKEN: Instance of HTMLPurifier_Token
0030      *  - ATTR: array('attr-name', 'value')
0031      *  - CSSPROP: array('prop-name', 'value')
0032      * @type mixed
0033      */
0034     public $value;
0035 
0036     /**
0037      * Errors registered for this structure.
0038      * @type array
0039      */
0040     public $errors = array();
0041 
0042     /**
0043      * Child ErrorStructs that are from this structure. For example, a TOKEN
0044      * ErrorStruct would contain ATTR ErrorStructs. This is a multi-dimensional
0045      * array in structure: [TYPE]['identifier']
0046      * @type array
0047      */
0048     public $children = array();
0049 
0050     /**
0051      * @param string $type
0052      * @param string $id
0053      * @return mixed
0054      */
0055     public function getChild($type, $id)
0056     {
0057         if (!isset($this->children[$type][$id])) {
0058             $this->children[$type][$id] = new HTMLPurifier_ErrorStruct();
0059             $this->children[$type][$id]->type = $type;
0060         }
0061         return $this->children[$type][$id];
0062     }
0063 
0064     /**
0065      * @param int $severity
0066      * @param string $message
0067      */
0068     public function addError($severity, $message)
0069     {
0070         $this->errors[] = array($severity, $message);
0071     }
0072 }
0073 
0074 // vim: et sw=4 sts=4