diff --git "a/include/class-wb\\Snak.php" "b/include/class-wb\\Snak.php" index 299a1af..d59d497 100644 --- "a/include/class-wb\\Snak.php" +++ "b/include/class-wb\\Snak.php" @@ -1,125 +1,188 @@ . # Wikibase namespace wb; /** * A generic Snak is a combination of a property and a datatype + datavalue. * * A Snak is part of a Claim or a Reference. It's based on a DataValue. */ class Snak { //var $hash; var $snaktype; var $property; var $datatype; var $datavalue; /** * @param $snaktype string * @param $property string * @param $datatype string * @param $datavalue mixed */ public function __construct( $snaktype, $property, $datatype, $datavalue = null ) { $this->setSnakType( $snaktype ) ->setProperty( $property ) ->setDataType( $datatype ); if( null !== $datavalue ) { $this->setDataValue( $datavalue ); } } + /** + * Get the property + * + * @return string + */ public function getProperty() { return $this->property; } + /** + * Get the snak type + */ public function getSnakType() { return $this->snaktype; } + /** + * Get the data type + */ public function getDataType() { return $this->datatype; } + /** + * Get the data value + * + * @return DataValue + */ public function getDataValue() { return $this->datavalue; } + /** + * Set the snak type + * + * @param $snaktype + * @param self + */ public function setSnakType( $snaktype ) { $this->snaktype = $snaktype; return $this; } + /** + * Set the property + * + * @param $property string + * @param self + */ public function setProperty( $property ) { $this->property = $property; return $this; } + /** + * Set the data type + * + * @param $datatype + * @param self + */ public function setDataType( $datatype ) { $this->datatype = $datatype; return $this; } + /** + * Set the data value + * + * @param $datavalue DataValue + * @param self + */ public function setDataValue( DataValue $datavalue ) { $this->datavalue = $datavalue; return $this; } + /** + * Check if the snak has an hash + * + * @return bool + */ public function hasHash() { return isset( $this->hash ); } + /** + * Get the hash + * + * @return string|null + */ public function getHash() { return $this->hash; } + /** + * Set the hash + * + * @param $hash string + * @return self + */ public function setHash( $hash ) { $this->hash = $hash; + return $this; } + /** + * Create a snak from raw data + * + * @param $data array + * @return self + */ public static function createFromData( $data ) { if( ! isset( $data['snaktype'], $data['property'], $data['datatype'] ) ) { throw new WrongDataException( __CLASS__ ); } $snak = new self( $data['snaktype'], $data['property'], $data['datatype'] ); if( isset( $data['datavalue'] ) ) { $snak->setDataValue( DataValue::createFromData( $data['datavalue'] ) ); } if( isset( $data['hash'] ) ) { $snak->setHash( $data['hash'] ); } return $snak; } /** * @return string */ public function __toString() { return sprintf( '[[P:%s]]: %s', $this->getProperty(), $this->getDataValue() ); } }