/** Constructor for creating a new boolean literal * * If the value is not a string, then it will be converted to 'true' or 'false'. * * @param mixed $value The value of the literal * @param string $lang Should be null (literals with a datatype can't have a language) * @param string $datatype Optional datatype (default 'xsd:boolean') * @return object EasyRdf_Literal_Boolean */ public function __construct($value, $lang = null, $datatype = null) { if (!is_string($value)) { $value = $value ? 'true' : 'false'; } parent::__construct($value, null, $datatype); }
/** Constructor for creating a new date literal * * The date is parsed and stored internally using a DateTime object. * @see DateTime * * @param mixed $value The value of the literal * @param string $lang Should be null (literals with a datatype can't have a language) * @param string $datatype Optional datatype (default 'xsd:date') * @return object EasyRdf_Literal_Date */ public function __construct($value, $lang = null, $datatype = null) { // Convert the value into a DateTime object, if it isn't already if (!$value instanceof DateTime) { $value = new DateTime(strval($value)); } parent::__construct($value, null, $datatype); }
/** Constructor for creating a new date literal * * If the value is a DateTime object, then it will be converted to the xsd:date format. * * @see DateTime * * @param mixed $value The value of the literal * @param string $lang Should be null (literals with a datatype can't have a language) * @param string $datatype Optional datatype (default 'xsd:date') * @return object EasyRdf_Literal_Date */ public function __construct($value, $lang = null, $datatype = null) { // Convert DateTime object into string if ($value instanceof DateTime) { $value = $value->format('Y-m-d'); } parent::__construct($value, null, $datatype); }
/** Constructor for creating a new date and time literal * * If the value is a DateTime object, then it will be converted to the xsd:dateTime format. * * @see DateTime * * @param mixed $value The value of the literal * @param string $lang Should be null (literals with a datatype can't have a language) * @param string $datatype Optional datatype (default 'xsd:dateTime') * @return object EasyRdf_Literal_DateTime */ public function __construct($value, $lang = null, $datatype = null) { // Convert DateTime objects into string if ($value instanceof DateTime) { $iso = $value->format(DateTime::ISO8601); $value = preg_replace('/[\\+\\-]00(\\:?)00$/', 'Z', $iso); } EasyRdf_Literal::__construct($value, null, $datatype); }
/** 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 date literal * * If the value is a DateTime object, then it will be converted to the xsd:date format. * If no value is given or is is null, then the current date is used. * * @see DateTime * * @param mixed $value The value of the literal * @param string $lang Should be null (literals with a datatype can't have a language) * @param string $datatype Optional datatype (default 'xsd:date') * @return object EasyRdf_Literal_Date */ public function __construct($value = null, $lang = null, $datatype = null) { // If $value is null, use today's date if (is_null($value)) { $value = new DateTime('today'); } // Convert DateTime object into string if ($value instanceof DateTime) { $value = $value->format('Y-m-d'); } parent::__construct($value, null, $datatype); }
/** Constructor for creating a new decimal literal * * @param double|int|string $value The value of the literal * @param string $lang Should be null (literals with a datatype can't have a language) * @param string $datatype Optional datatype (default 'xsd:decimal') * * @throws UnexpectedValueException * @return EasyRdf_Literal_Decimal */ public function __construct($value, $lang = null, $datatype = null) { if (is_string($value)) { self::validate($value); } elseif (is_double($value) or is_int($value)) { $locale_data = localeconv(); $value = str_replace($locale_data['decimal_point'], '.', strval($value)); } else { throw new UnexpectedValueException('EasyRdf_Literal_Decimal expects int/float/string as value'); } $value = self::canonicalise($value); parent::__construct($value, null, $datatype); }
/** Constructor for creating a new date and time literal * * If the value is a DateTime object, then it will be converted to the xsd:dateTime format. * If no value is given or is is null, then the current time is used. * * @see DateTime * * @param mixed $value The value of the literal * @param string $lang Should be null (literals with a datatype can't have a language) * @param string $datatype Optional datatype (default 'xsd:dateTime') * @return object EasyRdf_Literal_DateTime */ public function __construct($value = null, $lang = null, $datatype = null) { // If $value is null, use 'now' if (is_null($value)) { $value = new DateTime('now'); } // Convert DateTime objects into string if ($value instanceof DateTime) { $atom = $value->format(DateTime::ATOM); $value = preg_replace('/[\\+\\-]00(\\:?)00$/', 'Z', $atom); } EasyRdf_Literal::__construct($value, null, $datatype); }
/** Constructor for creating a new decimal literal * * @param mixed $value The value of the literal * @param string $lang Should be null (literals with a datatype can't have a language) * @param string $datatype Optional datatype (default 'xsd:decimal') * @return object EasyRdf_Literal_Decimal */ public function __construct($value, $lang = null, $datatype = null) { parent::__construct($value, null, $datatype); }
/** Constructor for creating a new hexadecimal encoded binary blob * * @param mixed $value The value of the literal * @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) { parent::__construct($value, null, 'xsd:hexBinary'); }