offsetGet() public method

Retrieves a value, and logs the access.
public offsetGet ( mixed $index ) : mixed
$index mixed
return mixed
 function testUsed()
 {
     $hash = new HTMLPurifier_StringHash(array('key' => 'value', 'key2' => 'value2'));
     $this->assertIdentical($hash->getAccessed(), array());
     $t = $hash->offsetGet('key');
     $this->assertIdentical($hash->getAccessed(), array('key' => true));
     $hash->resetAccessed();
     $this->assertIdentical($hash->getAccessed(), array());
 }
Esempio n. 2
0
 /**
  * @param HTMLPurifier_ConfigSchema_Interchange $interchange
  * @param HTMLPurifier_StringHash $hash
  * @throws HTMLPurifier_ConfigSchema_Exception
  */
 public function buildDirective($interchange, $hash)
 {
     $directive = new HTMLPurifier_ConfigSchema_Interchange_Directive();
     // These are required elements:
     $directive->id = $this->id($hash->offsetGet('ID'));
     $id = $directive->id->toString();
     // convenience
     if (isset($hash['TYPE'])) {
         $type = explode('/', $hash->offsetGet('TYPE'));
         if (isset($type[1])) {
             $directive->typeAllowsNull = true;
         }
         $directive->type = $type[0];
     } else {
         throw new HTMLPurifier_ConfigSchema_Exception("TYPE in directive hash '{$id}' not defined");
     }
     if (isset($hash['DEFAULT'])) {
         try {
             $directive->default = $this->varParser->parse($hash->offsetGet('DEFAULT'), $directive->type, $directive->typeAllowsNull);
         } catch (HTMLPurifier_VarParserException $e) {
             throw new HTMLPurifier_ConfigSchema_Exception($e->getMessage() . " in DEFAULT in directive hash '{$id}'");
         }
     }
     if (isset($hash['DESCRIPTION'])) {
         $directive->description = $hash->offsetGet('DESCRIPTION');
     }
     if (isset($hash['ALLOWED'])) {
         $directive->allowed = $this->lookup($this->evalArray($hash->offsetGet('ALLOWED')));
     }
     if (isset($hash['VALUE-ALIASES'])) {
         $directive->valueAliases = $this->evalArray($hash->offsetGet('VALUE-ALIASES'));
     }
     if (isset($hash['ALIASES'])) {
         $raw_aliases = trim($hash->offsetGet('ALIASES'));
         $aliases = preg_split('/\\s*,\\s*/', $raw_aliases);
         foreach ($aliases as $alias) {
             $directive->aliases[] = $this->id($alias);
         }
     }
     if (isset($hash['VERSION'])) {
         $directive->version = $hash->offsetGet('VERSION');
     }
     if (isset($hash['DEPRECATED-USE'])) {
         $directive->deprecatedUse = $this->id($hash->offsetGet('DEPRECATED-USE'));
     }
     if (isset($hash['DEPRECATED-VERSION'])) {
         $directive->deprecatedVersion = $hash->offsetGet('DEPRECATED-VERSION');
     }
     if (isset($hash['EXTERNAL'])) {
         $directive->external = preg_split('/\\s*,\\s*/', trim($hash->offsetGet('EXTERNAL')));
     }
     $interchange->addDirective($directive);
 }