コード例 #1
0
ファイル: Boolean.php プロジェクト: johnulist/easyrdf
 /** 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')
  */
 public function __construct($value, $lang = null, $datatype = null)
 {
     if (!is_string($value)) {
         $value = $value ? 'true' : 'false';
     }
     parent::__construct($value, null, $datatype);
 }
コード例 #2
0
ファイル: HexBinary.php プロジェクト: johnulist/easyrdf
 /** 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')
  *
  * @throws \InvalidArgumentException
  */
 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');
 }
コード例 #3
0
ファイル: Date.php プロジェクト: johnulist/easyrdf
 /** 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')
  */
 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);
 }
コード例 #4
0
ファイル: Decimal.php プロジェクト: johnulist/easyrdf
 /** 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
  */
 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);
 }
コード例 #5
0
ファイル: DateTime.php プロジェクト: johnulist/easyrdf
 /** 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')
  */
 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);
     }
     Literal::__construct($value, null, $datatype);
 }
コード例 #6
0
ファイル: HTML.php プロジェクト: johnulist/easyrdf
 /** Constructor for creating a new rdf:HTML literal
  *
  * @param  mixed  $value     The HTML fragment
  * @param  string $lang      Should be null (literals with a datatype can't have a language)
  * @param  string $datatype  Optional datatype (default 'rdf:HTML')
  */
 public function __construct($value, $lang = null, $datatype = null)
 {
     parent::__construct($value, null, $datatype);
 }