Example #1
0
 /**
  * Builds the index for the given collection
  *
  * @param DatabaseInterface|\Iterator $database
  * @return $this
  */
 public function indexDatabase($database)
 {
     // Clear the map
     $this->map = array();
     /** @var SplFixedArray $collection */
     $collection = null;
     if ($database instanceof DatabaseRawDataInterface) {
         $collection = $database->getRawData();
     }
     if ($database instanceof SplFixedArray) {
         // Use the fixed array as is
     } elseif (is_array($database)) {
         $collection = SplFixedArray::fromArray($database);
     } elseif ($database instanceof \Iterator) {
         $collection = SplFixedArray::fromArray(iterator_to_array($database));
     } else {
         throw new InvalidIndexException(sprintf('Can not build index of argument of type %s', is_object($database) ? get_class($database) : gettype($database)));
     }
     $position = 0;
     $count = $collection->getSize();
     if ($count > 0) {
         do {
             $tempEntry = DocumentUtility::assertDocumentIdentifier($database[$position]);
             $this->addEntryWithPosition($tempEntry, $position);
         } while (++$position < $count);
     }
 }
Example #2
0
 /**
  * @test
  */
 public function deleteTest()
 {
     $requestInfo = RequestInfoFactory::buildRequestInfoFromRequest(new Request('DELETE', '/contacts/info@cundd.net'));
     $handlerResult = $this->fixture->delete($requestInfo);
     $this->assertInstanceOf('Cundd\\PersistentObjectStore\\Server\\Handler\\HandlerResultInterface', $handlerResult);
     $this->assertEquals(204, $handlerResult->getStatusCode());
     $this->assertEquals('Document "info@cundd.net" deleted', $handlerResult->getData());
     /** @var DocumentInterface $dataInstance */
     $dataInstance = new Document(['email' => 'info@cundd.net']);
     $this->assertFalse($this->database->contains($dataInstance));
 }
Example #3
0
 /**
  * Builds the index for the given collection
  *
  * @param DatabaseInterface|\Iterator $database
  * @return $this
  */
 public function indexDatabase($database)
 {
     // Clear the map
     $this->map = array();
     /** @var SplFixedArray $collection */
     $collection = null;
     if ($database instanceof DatabaseRawDataInterface) {
         $collection = $database->getRawData();
     } elseif ($database instanceof SplFixedArray) {
         $collection = $database;
     } elseif (is_array($database)) {
         $collection = SplFixedArray::fromArray($database);
     } elseif ($database instanceof \Iterator) {
         $collection = SplFixedArray::fromArray(iterator_to_array($database));
     } else {
         throw new InvalidIndexException(sprintf('Can not build index of argument of type %s', is_object($database) ? get_class($database) : gettype($database)));
     }
     $position = 0;
     $count = $collection->getSize();
     $tempMap = array();
     if ($count > 0) {
         $collectionContainsDocumentObjects = $collection[0] instanceof DocumentInterface;
         do {
             $entry = $collection[$position];
             if ($collectionContainsDocumentObjects) {
                 $key = DocumentUtility::assertDocumentIdentifier($entry)->getId();
             } else {
                 $key = DocumentUtility::getIdentifierForDocument($entry);
             }
             //				DebugUtility::var_dump('Index', $key);
             if (isset($tempMap[$key])) {
                 throw new DuplicateEntryException(sprintf('Duplicate entry \'%s\' for identifier', $key), 1415046937);
             }
             $tempMap[$key] = $position;
         } while (++$position < $count);
     }
     $this->map = $tempMap;
 }
Example #4
0
 /**
  * Returns the Document objects that will be written to the file system
  *
  * @param DatabaseInterface $database
  * @return array
  */
 protected function _getObjectsWrite($database)
 {
     $objectsToWrite = array();
     $database->rewind();
     while ($database->valid()) {
         /** @var DocumentInterface $item */
         $item = $database->current();
         if ($item) {
             $objectsToWrite[] = $item->getData();
             //			} else {
             //				DebugUtility::pl('Current item is NULL');
         }
         $database->next();
     }
     return $objectsToWrite;
 }