HTMLPurifier_Config::get PHP Method

get() public method

Retrieves a value from the configuration.
public get ( string $key, mixed $a = null ) : mixed
$key string String key
$a mixed
return mixed
    public function get($key, $a = null)
    {
        if ($a !== null) {
            $this->triggerError("Using deprecated API: use \$config->get('{$key}.{$a}') instead", E_USER_WARNING);
            $key = "{$key}.{$a}";
        }
        if (!$this->finalized) {
            $this->autoFinalize();
        }
        if (!isset($this->def->info[$key])) {
            // can't add % due to SimpleTest bug
            $this->triggerError('Cannot retrieve value of undefined directive ' . htmlspecialchars($key), E_USER_WARNING);
            return;
        }
        if (isset($this->def->info[$key]->isAlias)) {
            $d = $this->def->info[$key];
            $this->triggerError('Cannot get value from aliased directive, use real name ' . $d->key, E_USER_ERROR);
            return;
        }
        if ($this->lock) {
            list($ns) = explode('.', $key);
            if ($ns !== $this->lock) {
                $this->triggerError('Cannot get value of namespace ' . $ns . ' when lock for ' . $this->lock . ' is active, this probably indicates a Definition setup method ' . 'is accessing directives that are not within its namespace', E_USER_ERROR);
                return;
            }
        }
        return $this->plist->get($key);
    }

Usage Example

Example #1
0
 /**
  * @param array $attr
  * @param HTMLPurifier_Config $config
  * @param HTMLPurifier_Context $context
  * @return array
  */
 public function transform($attr, $config, $context)
 {
     $src = true;
     if (!isset($attr['src'])) {
         if ($config->get('Core.RemoveInvalidImg')) {
             return $attr;
         }
         $attr['src'] = $config->get('Attr.DefaultInvalidImage');
         $src = false;
     }
     if (!isset($attr['alt'])) {
         if ($src) {
             $alt = $config->get('Attr.DefaultImageAlt');
             if ($alt === null) {
                 // truncate if the alt is too long
                 $attr['alt'] = substr(basename($attr['src']), 0, 40);
             } else {
                 $attr['alt'] = $alt;
             }
         } else {
             $attr['alt'] = $config->get('Attr.DefaultInvalidImageAlt');
         }
     }
     return $attr;
 }
All Usage Examples Of HTMLPurifier_Config::get