You are here

class EasyRdf_Literal_HexBinary in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/HexBinary.php \EasyRdf_Literal_HexBinary

Class that represents an RDF Literal of datatype xsd:hexBinary

@package EasyRdf @link http://www.w3.org/TR/xmlschema-2/#hexBinary @copyright Copyright (c) 2009-2013 Nicholas J Humfrey @license http://www.opensource.org/licenses/bsd-license.php

Hierarchy

Expanded class hierarchy of EasyRdf_Literal_HexBinary

1 string reference to 'EasyRdf_Literal_HexBinary'
Literal.php in vendor/easyrdf/easyrdf/lib/EasyRdf/Literal.php

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/HexBinary.php, line 46

View source
class EasyRdf_Literal_HexBinary extends EasyRdf_Literal {

  /** Constructor for creating a new xsd:hexBinary literal
   *
   * @param  mixed  $value     The value of the literal (already encoded as hexadecimal)
   * @param  string $lang      Should be null (literals with a datatype can't have a language)
   * @param  string $datatype  Optional datatype (default 'xsd:hexBinary')
   * @return object EasyRdf_Literal_HexBinary
   */
  public function __construct($value, $lang = null, $datatype = null) {

    // Normalise the canonical representation, as specified here:
    // http://www.w3.org/TR/xmlschema-2/#hexBinary-canonical-repr
    $value = strtoupper($value);

    // Validate the data
    if (preg_match('/[^A-F0-9]/', $value)) {
      throw new InvalidArgumentException("Literal of type xsd:hexBinary contains non-hexadecimal characters");
    }
    parent::__construct(strtoupper($value), null, 'xsd:hexBinary');
  }

  /** Constructor for creating a new literal object from a binary blob
   *
   * @param  string $binary  The binary data
   * @return object EasyRdf_Literal_HexBinary
   */
  public static function fromBinary($binary) {
    return new self(bin2hex($binary));
  }

  /** Decode the hexadecimal string into a binary blob
   *
   * @return string The binary blob
   */
  public function toBinary() {
    return pack("H*", $this->value);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EasyRdf_Literal::$classMap private static property @ignore A mapping from class name to datatype URI
EasyRdf_Literal::$datatype protected property @ignore The datatype URI of the literal
EasyRdf_Literal::$datatypeMap private static property @ignore a mapping from datatype uri to class name
EasyRdf_Literal::$lang protected property @ignore The language of the literal (e.g. 'en')
EasyRdf_Literal::$value protected property @ignore The string value for this literal
EasyRdf_Literal::create public static function Create a new literal object
EasyRdf_Literal::deleteDatatypeMapping public static function Remove the mapping between an RDF datatype and a PHP class name
EasyRdf_Literal::dumpValue public function Return pretty-print view of the literal
EasyRdf_Literal::getDatatype public function Returns the shortened datatype URI of the literal.
EasyRdf_Literal::getDatatypeForValue public static function Get datatype URI for a PHP value.
EasyRdf_Literal::getDatatypeUri public function Returns the full datatype URI of the literal.
EasyRdf_Literal::getLang public function Returns the language of the literal.
EasyRdf_Literal::getValue public function Returns the value of the literal. 4
EasyRdf_Literal::setDatatypeMapping public static function Register an RDF datatype with a PHP class name
EasyRdf_Literal::toRdfPhp public function Returns the properties of the literal as an associative array
EasyRdf_Literal::__toString public function Magic method to return the value of a literal as a string
EasyRdf_Literal_HexBinary::fromBinary public static function Constructor for creating a new literal object from a binary blob
EasyRdf_Literal_HexBinary::toBinary public function Decode the hexadecimal string into a binary blob
EasyRdf_Literal_HexBinary::__construct public function Constructor for creating a new xsd:hexBinary literal Overrides EasyRdf_Literal::__construct