Example #1
0
 public function testContentHashId()
 {
     $hash = HashBuilder::createHashIdForContent('Foo');
     $this->assertInternalType('string', $hash);
     $this->assertSame($hash, HashBuilder::createHashIdForContent(array('Foo')));
     $this->assertContains('Bar', HashBuilder::createHashIdForContent(array('Foo'), 'Bar'));
 }
 private function createSubobjectId(ArrayFormatter $parameters)
 {
     $isAnonymous = in_array($parameters->getFirst(), array(null, '', '-'));
     $this->useFirstElementForPropertyLabel = $this->useFirstElementForPropertyLabel && !$isAnonymous;
     if ($this->useFirstElementForPropertyLabel || $isAnonymous) {
         return HashBuilder::createHashIdForContent($parameters->toArray(), '_');
     }
     return $parameters->getFirst();
 }
 /**
  * @see EntityLookup::getPropertySubjects
  *
  * @since 2.5
  *
  * {@inheritDoc}
  */
 public function getPropertySubjects(DIProperty $property, DataItem $dataItem = null, RequestOptions $requestOptions = null)
 {
     // The cache is not used for $dataItem === null (means all values for
     // the given property are returned)
     if ($dataItem === null || !$dataItem instanceof DIWikiPage || !$this->blobStore->canUse() || !$this->canUseValueLookupFeature(SMW_VL_PS)) {
         return $this->entityLookup->getPropertySubjects($property, $dataItem, $requestOptions);
     }
     // Added as linked list as we keep the container ttl different from
     // that of the main container
     $sid = $this->getHashFrom($dataItem, 'ps');
     $container = $this->blobStore->read($sid);
     $psid = HashBuilder::createHashIdForContent(array($property->getKey(), $property->isInverse(), (array) $requestOptions, self::VERSION), 'ps:');
     if ($container->has($psid)) {
         return $container->get($psid);
     }
     $result = $this->entityLookup->getPropertySubjects($property, $dataItem, $requestOptions);
     $container->set($psid, $result);
     // We set a short lifetime (5 min) in order to cache repeated requests but
     // avoiding a complex invalidation during a subject update otherwise all
     // properties of a container would require scanning and removal
     $container->setExpiryInSeconds(60 * 5);
     $this->blobStore->save($container);
     $this->appendToList($sid, $dataItem);
     return $result;
 }
Example #4
0
 /**
  * Returns result hash value
  *
  * @since 1.9
  *
  * @return string
  */
 public function getHash()
 {
     return HashBuilder::createHashIdForContent($this->serializeToArray());
 }
 private function getParameters(ParserParameterProcessor $parserParameterProcessor)
 {
     $id = $parserParameterProcessor->getFirst();
     $isAnonymous = in_array($id, array(null, '', '-'));
     $this->isEnabledFirstElementAsPropertyLabel = $this->isEnabledFirstElementAsPropertyLabel && !$isAnonymous;
     $parameters = $this->doPrepareParameters($parserParameterProcessor);
     // Reclaim the ID to be hash based on the content
     if ($this->isEnabledFirstElementAsPropertyLabel || $isAnonymous) {
         $id = HashBuilder::createHashIdForContent($parameters, '_');
     }
     return array($parameters, $id);
 }