getSortKey(); if ( is_numeric( $sortKey ) ) { return new SMWDINumber( $sortKey ); } return new SMWDIBlob( $sortKey ); } /** * Get a UTF-8 encoded string serialization of this data item. * The serialisation should be concise and need not be pretty, but it * must allow unserialization. Each subclass of SMWDataItem implements * a static method doUnserialize() for this purpose. * @return string */ abstract public function getSerialization(); /** * Get a hash string for this data item. Might be overwritten in * subclasses to obtain shorter or more efficient hashes. * * @return string */ public function getHash() { return $this->getSerialization(); } /** * @since 2.1 * * @return string */ public function __toString() { return $this->getSerialization(); } /** * Create a data item of the given dataitem ID based on the the * provided serialization string and (optional) typeid. * * @param integer $diType dataitem ID * @param string $serialization * * @return SMWDataItem */ public static function newFromSerialization( $diType, $serialization ) { $diClass = self::getDataItemClassNameForId( $diType ); return call_user_func( [ $diClass, 'doUnserialize' ], $serialization ); } /** * Gets the class name of the data item that has the provided type id. * * @param integer $diType Element of the SMWDataItem::TYPE_ enum * * @throws InvalidArgumentException * * @return string */ public static function getDataItemClassNameForId( $diType ) { switch ( $diType ) { case self::TYPE_NUMBER: return SMWDINumber::class; case self::TYPE_BLOB: return SMWDIBlob::class; case self::TYPE_BOOLEAN: return SMWDIBoolean::class; case self::TYPE_URI: return SMWDIUri::class; case self::TYPE_TIME: return SMWDITime::class; case self::TYPE_GEO: return SMWDIGeoCoord::class; case self::TYPE_CONTAINER: return SMWDIContainer::class; case self::TYPE_WIKIPAGE: return SMWDIWikiPage::class; case self::TYPE_CONCEPT: return SMWDIConcept::class; case self::TYPE_PROPERTY: return SMWDIProperty::class; case self::TYPE_ERROR: return SMWDIError::class; case self::TYPE_NOTYPE: default: throw new InvalidArgumentException( "The value \"$diType\" is not a valid dataitem ID." ); } } /** * @since 2.5 * * @param string $key * @param string $value */ public function setOption( $key, $value ) { if ( !$this->options instanceof Options ) { $this->options = new Options(); } $this->options->set( $key, $value ); } /** * @since 2.5 * * @param string $key * @param string|null $default * * @return mixed */ public function getOption( $key, $default = null ) { if ( !$this->options instanceof Options ) { $this->options = new Options(); } if ( $this->options->has( $key ) ) { return $this->options->get( $key ); } return $default; } }