| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Wikibase\DataModel\Statement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Comparable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Hashable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use InvalidArgumentException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Wikibase\DataModel\Entity\PropertyId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Wikibase\DataModel\PropertyIdProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Wikibase\DataModel\Reference; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Wikibase\DataModel\ReferenceList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Wikibase\DataModel\Snak\Snak; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Wikibase\DataModel\Snak\SnakList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * Class representing a Wikibase statement. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * See https://www.mediawiki.org/wiki/Wikibase/DataModel#Statements | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @since 0.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * @license GPL-2.0+ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * @author Jeroen De Dauw < [email protected] > | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @author Bene* < [email protected] > | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | class Statement implements Hashable, Comparable, PropertyIdProvider { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	 * Rank enum. Higher values are more preferred. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	 * @since 2.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	const RANK_PREFERRED = 2; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	const RANK_NORMAL = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	const RANK_DEPRECATED = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	 * @var string|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	private $guid = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	 * @var Snak | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	private $mainSnak; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	 * The property value snaks making up the qualifiers for this statement. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	 * @var SnakList | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 	private $qualifiers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	 * @var ReferenceList | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 	private $references; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 	 * @var integer, element of the Statement::RANK_ enum | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	private $rank = self::RANK_NORMAL; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	 * @since 2.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	 * @param Snak $mainSnak | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	 * @param SnakList|null $qualifiers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	 * @param ReferenceList|null $references | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	 * @param string|null $guid | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 		Snak $mainSnak, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		SnakList $qualifiers = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		ReferenceList $references = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 		$guid = null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 	) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 		$this->mainSnak = $mainSnak; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 		$this->qualifiers = $qualifiers ?: new SnakList(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		$this->references = $references ?: new ReferenceList(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 23 |  | 		$this->setGuid( $guid ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	 * Returns the GUID of this statement. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 23 |  | 	 * @since 0.2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 | 23 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 | 23 |  | 	 * @return string|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 23 |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 19 |  | 	public function getGuid() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		return $this->guid; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 	 * Sets the GUID of this statement. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 	 * @since 0.2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 11 |  | 	 * @param string|null $guid | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 | 11 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 	 * @throws InvalidArgumentException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 	public function setGuid( $guid ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 		if ( !is_string( $guid ) && $guid !== null ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 			throw new InvalidArgumentException( '$guid must be a string or null' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 		$this->guid = $guid; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 31 |  | 	 * Returns the main value snak of this statement. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 | 31 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 | 8 |  | 	 * @since 0.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 	 * @return Snak | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 | 27 |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 | 27 |  | 	public function getMainSnak() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 		return $this->mainSnak; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 	 * Sets the main value snak of this statement. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 	 * @since 0.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 | 9 |  | 	 * @param Snak $mainSnak | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 | 9 |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 	public function setMainSnak( Snak $mainSnak ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 		$this->mainSnak = $mainSnak; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 	 * Returns the property value snaks making up the qualifiers for this statement. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 	 * @since 0.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 	 * @return SnakList | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 	public function getQualifiers() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 		return $this->qualifiers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 	 * Sets the property value snaks making up the qualifiers for this statement. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 	 * @since 0.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 | 8 |  | 	 * @param SnakList $propertySnaks | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 | 8 |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 	public function setQualifiers( SnakList $propertySnaks ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 		$this->qualifiers = $propertySnaks; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 	 * Returns the references attached to this statement. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 	 * @since 0.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 	 * @return ReferenceList | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 	public function getReferences() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 		return $this->references; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | 	 * Sets the references attached to this statement. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  | 	 * @since 0.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 | 23 |  | 	 * @param ReferenceList $references | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 | 23 |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  | 	public function setReferences( ReferenceList $references ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  | 		$this->references = $references; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  | 	 * @since 2.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  | 	 * @param Snak[]|Snak $snaks | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  | 	 * @param Snak [$snak2,...] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 | 4 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 | 4 |  | 	 * @throws InvalidArgumentException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 | 4 |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  | 	public function addNewReference( $snaks = array() /*...*/ ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  | 		if ( $snaks instanceof Snak ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  | 			$snaks = func_get_args(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  | 		$this->references->addNewReference( $snaks ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 | 8 |  | 	 * Sets the rank of the statement. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 | 8 |  | 	 * The rank is an element of the Statement::RANK_ enum. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 | 4 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 | 4 |  | 	 * @since 0.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 | 8 |  | 	 * @param integer $rank | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 | 8 |  | 	 * @throws InvalidArgumentException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  | 	public function setRank( $rank ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  | 		$ranks = array( self::RANK_DEPRECATED, self::RANK_NORMAL, self::RANK_PREFERRED ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  | 		if ( !in_array( $rank, $ranks, true ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  | 			throw new InvalidArgumentException( 'Invalid rank specified for statement: ' . var_export( $rank, true ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  | 		$this->rank = $rank; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 | 9 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 | 9 |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  | 	 * @since 0.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 | 9 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 | 4 |  | 	 * @return integer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  | 	public function getRank() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 | 5 |  | 		return $this->rank; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 | 5 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  | 	 * @see Hashable::getHash | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  | 	 * @since 0.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 | 8 |  | 	 * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 227 | 8 |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 228 |  |  | 	public function getHash() { | 
            
                                                                        
                            
            
                                    
            
            
                | 229 |  |  | 		return sha1( implode( | 
            
                                                                        
                            
            
                                    
            
            
                | 230 |  |  | 			'|', | 
            
                                                                        
                            
            
                                    
            
            
                | 231 |  |  | 			array( | 
            
                                                                        
                            
            
                                    
            
            
                | 232 |  |  | 				sha1( $this->mainSnak->getHash() . $this->qualifiers->getHash() ), | 
            
                                                                        
                            
            
                                    
            
            
                | 233 |  |  | 				$this->rank, | 
            
                                                                        
                            
            
                                    
            
            
                | 234 |  |  | 				$this->references->getValueHash(), | 
            
                                                                        
                            
            
                                    
            
            
                | 235 |  |  | 			) | 
            
                                                                        
                            
            
                                    
            
            
                | 236 |  |  | 		) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 237 | 5 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 | 5 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 | 5 |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  | 	 * Returns the id of the property of the main snak. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 | 5 |  | 	 * Short for ->getMainSnak()->getPropertyId() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 | 5 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 | 5 |  | 	 * @see PropertyIdProvider::getPropertyId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 | 5 |  | 	 * @since 0.2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  | 	 * @return PropertyId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  | 	public function getPropertyId() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  | 		return $this->getMainSnak()->getPropertyId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  | 	 * Returns a list of all Snaks on this statement. This includes the main snak and all snaks | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  | 	 * from qualifiers and references. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  | 	 * This is a convenience method for use in code that needs to operate on all snaks, e.g. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 | 4 |  | 	 * to find all referenced Entities. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 | 4 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  | 	 * @return Snak[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  | 	public function getAllSnaks() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  | 		$snaks = array( $this->mainSnak ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  | 		foreach ( $this->qualifiers as $qualifier ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  | 			$snaks[] = $qualifier; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  | 		/* @var Reference $reference */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  | 		foreach ( $this->getReferences() as $reference ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 | 4 |  | 			foreach ( $reference->getSnaks() as $referenceSnak ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 | 4 |  | 				$snaks[] = $referenceSnak; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 | 4 |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 | 4 |  | 		return $snaks; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 | 4 |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 | 1 |  | 	 * @see Comparable::equals | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 | 1 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 | 1 |  | 	 * @since 0.7.4 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 | 4 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  | 	 * @param mixed $target | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 | 4 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  | 	 * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  | 	public function equals( $target ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  | 		if ( $this === $target ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  | 			return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  | 		return $target instanceof self | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  | 			&& $this->guid === $target->guid | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  | 			&& $this->rank === $target->rank | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  | 			&& $this->mainSnak->equals( $target->mainSnak ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 | 12 |  | 			&& $this->qualifiers->equals( $target->qualifiers ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 | 12 |  | 			&& $this->references->equals( $target->references ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 | 1 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  | 	 * @see http://php.net/manual/en/language.oop5.cloning.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 | 12 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 | 12 |  | 	 * @since 5.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 | 12 |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 | 12 |  | 	public function __clone() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 | 12 |  | 		$this->qualifiers = clone $this->qualifiers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  | 		$this->references = clone $this->references; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 311 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 312 |  |  |  |