Exemplo n.º 1
0
 /**
  * Get property value, proxied from Bitmap.
  * 
  * @param string $name Name of class property.
  *
  * @return bool
  * @access public  
  * @magic
  * @throws Exception
  */
 public function __get($name)
 {
     if (!array_key_exists($name, $this->mapped)) {
         throw new Exception("Property '{$name}' does not exist in bitfield map.");
     }
     return $this->bitfield->isEnabled(constant($this->mapped[$name]));
 }
Exemplo n.º 2
0
            printf("Chat Enabled: %s\n", $item->pref_chat_enabled ? 'Y' : 'N');
            printf("\n");
        }
        fclose($fp);
        return;
    }
    throw new Exception("Failed to open example.data");
}
echo "Writing random data...\n";
generate_data(1000);
echo "Reading entries...\n";
read_data_entries();
echo "Done.\n";
exit;
// Example of how to use Bitfield directly:
$field = new Bitfield();
$field->addOption('USER_IS_ADMIN');
$field->addOption('USER_IS_BANNED');
$field->addOption('USER_IS_ADVERTISER');
$field->addOption('PREF_AUTOLOGIN');
$field->addOption('PREF_SHOW_ADS');
$field->setBitfield(USER_IS_ADMIN | PREF_AUTOLOGIN | PREF_SHOW_ADS);
if ($field->isEnabled(USER_IS_ADMIN)) {
    echo "Hello sir!\n";
    if ($field->isEnabled(PREF_AUTOLOGIN)) {
        echo "Autologin enabled.\n";
    }
    if ($field->isEnabled(USER_IS_ADVERTISER)) {
        echo "Gimme some offers.\n";
    }
} else {