* Class that represents an RDF Literal of datatype xsd:decimal
 *
 * @package    EasyRdf
 * @link       http://www.w3.org/TR/xmlschema-2/#decimal
 * @copyright  Copyright (c) 2009-2012 Nicholas J Humfrey
 * @license    http://www.opensource.org/licenses/bsd-license.php
 */
class EasyRdf_Literal_Decimal extends EasyRdf_Literal
{
    /** 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);
    }
    /** Return the value of the literal cast to a PHP double
     *
     * @return double
     */
    public function getValue()
    {
        return (double) $this->_value;
    }
}
EasyRdf_Literal::setDatatypeMapping('xsd:decimal', 'EasyRdf_Literal_Decimal');
예제 #2
0
파일: Date.php 프로젝트: Tjorriemorrie/app
    public function year()
    {
        return (int) $this->_value->format('Y');
    }
    /** Integer representation of the month
     *
     * @return integer
     */
    public function month()
    {
        return (int) $this->_value->format('m');
    }
    /** Integer representation of the day of the month
     *
     * @return integer
     */
    public function day()
    {
        return (int) $this->_value->format('d');
    }
    /** Magic method to return the value as an ISO8601 date string
     *
     * @return string The date as an ISO8601 string
     */
    public function __toString()
    {
        return $this->_value->format('Y-m-d');
    }
}
EasyRdf_Literal::setDatatypeMapping('xsd:date', 'EasyRdf_Literal_Date');
예제 #3
0
    {
        $binary = pack("H*", $value);
        return new self($binary);
    }
    /** Return the literal value as a hexadecimal string
     *
     * @return string The value as a hexadecimal string
     */
    public function toHex()
    {
        return $this->checkbinary($this->_value) !== true ? $this->_value : strtoupper(bin2hex($this->_value));
    }
    /** Magic method to return the value as a hexadecimal string
     *
     * @return string The value as a hexadecimal string
     */
    public function __toString()
    {
        return $this->toHex();
    }
    /** Check if a variable contains binary data or not 
     *
     * @retun true/false
     */
    function checkbinary($bin)
    {
        return preg_match('#^[01]+$#', $bin);
    }
}
EasyRdf_Literal::setDatatypeMapping('xsd:hexBinary', 'EasyRdf_Literal_HexBinary');
        parent::__construct($value, null, $datatype);
    }
    /** Return the value of the literal cast to a PHP bool
     *
     * If the value is 'true' or '1' return true, otherwise returns false.
     *
     * @return bool
     */
    public function getValue()
    {
        return strtolower($this->_value) === 'true' or $this->_value === '1';
    }
    /** Return true if the value of the literal is 'true' or '1'
     *
     * @return bool
     */
    public function isTrue()
    {
        return strtolower($this->_value) === 'true' or $this->_value === '1';
    }
    /** Return true if the value of the literal is 'false' or '0'
     *
     * @return bool
     */
    public function isFalse()
    {
        return strtolower($this->_value) === 'false' or $this->_value === '0';
    }
}
EasyRdf_Literal::setDatatypeMapping('xsd:boolean', 'EasyRdf_Literal_Boolean');
예제 #5
0
 * @package    EasyRdf
 * @copyright  Copyright (c) 2009-2011 Nicholas J Humfrey
 * @license    http://www.opensource.org/licenses/bsd-license.php
 * @version    $Id: Integer.php 98993 2011-10-05 12:20:17Z bkaempgen $
 */
/**
 * Class that represents an RDF Literal of datatype xsd:integer
 *
 * @package    EasyRdf
 * @link       http://www.w3.org/TR/xmlschema-2/#integer
 * @copyright  Copyright (c) 2009-2011 Nicholas J Humfrey
 * @license    http://www.opensource.org/licenses/bsd-license.php
 */
class EasyRdf_Literal_Integer extends EasyRdf_Literal
{
    /** Constructor for creating a new integer literal
     *
     * Non-integer values will be cast to integer.
     *
     * @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:integer')
     * @return object EasyRdf_Literal_Integer
     */
    public function __construct($value, $lang = null, $datatype = null)
    {
        parent::__construct((int) $value, null, $datatype);
    }
}
EasyRdf_Literal::setDatatypeMapping('xsd:integer', 'EasyRdf_Literal_Integer');
예제 #6
0
 public function testSetDatatypeMappingClassNonString()
 {
     $this->setExpectedException('InvalidArgumentException', '$class should be a string and cannot be null or empty');
     EasyRdf_Literal::setDatatypeMapping('ex:mytype', array());
 }
예제 #7
0
    /** Magic method to return the value of a literal as a string
     *
     * @return string The value of the literal
     */
    public function __toString()
    {
        return isset($this->value) ? $this->value : '';
    }
    /** Return pretty-print view of the literal
     *
     * @param  string $format Either 'html' or 'text'
     * @param  string $color  The colour of the text
     * @return string
     */
    public function dumpValue($format = 'html', $color = 'black')
    {
        return EasyRdf_Utils::dumpLiteralValue($this, $format, $color);
    }
}
/*
   Register default set of datatype classes
*/
EasyRdf_Literal::setDatatypeMapping('xsd:boolean', 'EasyRdf_Literal_Boolean');
EasyRdf_Literal::setDatatypeMapping('xsd:date', 'EasyRdf_Literal_Date');
EasyRdf_Literal::setDatatypeMapping('xsd:dateTime', 'EasyRdf_Literal_DateTime');
EasyRdf_Literal::setDatatypeMapping('xsd:decimal', 'EasyRdf_Literal_Decimal');
EasyRdf_Literal::setDatatypeMapping('xsd:hexBinary', 'EasyRdf_Literal_HexBinary');
EasyRdf_Literal::setDatatypeMapping('rdf:HTML', 'EasyRdf_Literal_HTML');
EasyRdf_Literal::setDatatypeMapping('xsd:integer', 'EasyRdf_Literal_Integer');
EasyRdf_Literal::setDatatypeMapping('rdf:XMLLiteral', 'EasyRdf_Literal_XML');