本文整理汇总了PHP中Collection::createFromArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::createFromArray方法的具体用法?PHP Collection::createFromArray怎么用?PHP Collection::createFromArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection::createFromArray方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getProcessedResponse
/**
* Get the batch part identified by the array key (0...n) or its id (if it was set with nextBatchPartId($id) )
*
* @throws ClientException
* @return mixed $partId
*/
public function getProcessedResponse()
{
$response = $this->getResponse();
switch ($this->_type) {
case 'getdocument':
$json = $response->getJson();
$options = $this->getCursorOptions();
$options['isNew'] = false;
$response = Document::createFromArray($json, $options);
break;
case 'document':
$json = $response->getJson();
if ($json['error'] === false) {
$id = $json[Document::ENTRY_ID];
$response = $id;
}
break;
case 'getedge':
$json = $response->getJson();
$options = $this->getCursorOptions();
$options['isNew'] = false;
$response = Edge::createFromArray($json, $options);
break;
case 'edge':
$json = $response->getJson();
if ($json['error'] === false) {
$id = $json[Edge::ENTRY_ID];
$response = $id;
}
break;
case 'getcollection':
$json = $response->getJson();
$options = $this->getCursorOptions();
$options['isNew'] = false;
$response = Collection::createFromArray($json, $options);
break;
case 'collection':
$json = $response->getJson();
if ($json['error'] === false) {
$id = $json[Collection::ENTRY_ID];
$response = $id;
}
break;
case 'cursor':
$options = $this->getCursorOptions();
$options['isNew'] = false;
$response = new Cursor($this->_batch->getConnection(), $response->getJson(), $options);
break;
default:
throw new ClientException('Could not determine response data type.');
break;
}
return $response;
}
示例2: getProperties
/**
* Get properties of a collection
*
* This will throw if the collection cannot be fetched from the server
*
* @throws Exception
*
* @param mixed $collectionId - collection id as a string or number
*
* @return Collection - the collection fetched from the server
*/
public function getProperties($collectionId)
{
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, array($collectionId, self::OPTION_PROPERTIES));
$response = $this->getConnection()->get($url);
$data = $response->getJson();
return Collection::createFromArray($data);
}
示例3: testLookupByKeys
/**
* test bulk document lookups
*/
public function testLookupByKeys()
{
$documentHandler = $this->documentHandler;
$collectionHandler = $this->collectionHandler;
$collection = Collection::createFromArray(array('name' => 'ArangoDB_PHP_TestSuite_TestCollection_01', 'waitForSync' => false));
$collectionHandler->add($collection);
$document = Document::createFromArray(array('someAttribute' => 'someValue1', 'someOtherAttribute' => 'someOtherValue'));
$documentId = $documentHandler->add($collection->getId(), $document);
$document2 = Document::createFromArray(array('someAttribute' => 'someValue2', 'someOtherAttribute' => 'someOtherValue2'));
$documentId2 = $documentHandler->add($collection->getId(), $document2);
$document3 = Document::createFromArray(array('someAttribute' => 'someValue3', 'someOtherAttribute' => 'someOtherValue'));
$documentId3 = $documentHandler->add($collection->getId(), $document3);
$this->assertTrue(is_numeric($documentId), 'Did not return an id!');
$this->assertTrue(is_numeric($documentId2), 'Did not return an id!');
$this->assertTrue(is_numeric($documentId3), 'Did not return an id!');
$keys = array($documentId, $documentId2, $documentId3);
$result = $collectionHandler->lookupByKeys($collection->getId(), $keys);
$this->assertEquals(3, count($result));
$document = $result[0];
$this->assertInstanceOf('\\triagens\\ArangoDb\\Document', $document, "Object was not a Document!");
$this->assertEquals($documentId, $document->getId());
$this->assertEquals("someValue1", $document->someAttribute);
$this->assertEquals("someOtherValue", $document->someOtherAttribute);
$document = $result[1];
$this->assertInstanceOf('\\triagens\\ArangoDb\\Document', $document, "Object was not a Document!");
$this->assertEquals($documentId2, $document->getId());
$this->assertEquals("someValue2", $document->someAttribute);
$this->assertEquals("someOtherValue2", $document->someOtherAttribute);
$document = $result[2];
$this->assertInstanceOf('\\triagens\\ArangoDb\\Document', $document, "Object was not a Document!");
$this->assertEquals($documentId3, $document->getId());
$this->assertEquals("someValue3", $document->someAttribute);
$this->assertEquals("someOtherValue", $document->someOtherAttribute);
}
示例4: testFulltextQuery
/**
* test for fulltext queries
*/
public function testFulltextQuery()
{
$this->collectionHandler = new CollectionHandler($this->connection);
$documentHandler = $this->documentHandler;
$collectionHandler = $this->collectionHandler;
$collection = Collection::createFromArray(array('name' => 'ArangoDB_PHP_TestSuite_TestCollection_01', 'waitForSync' => true));
$collectionHandler->add($collection);
$document = Document::createFromArray(array('someAttribute' => 'someValue1', 'someOtherAttribute' => 'someOtherValue'));
$documentId = $documentHandler->add($collection->getId(), $document);
$document2 = Document::createFromArray(array('someAttribute' => 'someValue2', 'someOtherAttribute' => 'someOtherValue2'));
$documentId2 = $documentHandler->add($collection->getId(), $document2);
$document3 = Document::createFromArray(array('someAttribute' => 'someValue3', 'someOtherAttribute' => 'someOtherValue'));
$documentId3 = $documentHandler->add($collection->getId(), $document3);
// First we test without a fulltext index and expect a 400
try {
$result = $collectionHandler->fulltext($collection->getId(), "someOtherAttribute", "someOtherValue");
} catch (Exception $e) {
}
$this->assertTrue($e->getCode() === 400);
// Now we create an index
$fulltextIndexId = $collectionHandler->createFulltextIndex($collection->getId(), array("someOtherAttribute"));
$fulltextIndexId = $fulltextIndexId["id"];
$cursor = $collectionHandler->fulltext($collection->getId(), "someOtherAttribute", "someOtherValue", array("index" => $fulltextIndexId));
$m = $cursor->getMetadata();
$this->assertTrue($m["count"] == 2);
$this->assertTrue($m["hasMore"] == false);
// Now we pass some options
$cursor = $collectionHandler->fulltext($collection->getId(), "someOtherAttribute", "someOtherValue", array("index" => $fulltextIndexId, "skip" => 1));
$m = $cursor->getMetadata();
$this->assertTrue($m["count"] == 1);
$this->assertTrue($m["hasMore"] == false);
$cursor = $collectionHandler->fulltext($collection->getId(), "someOtherAttribute", "someOtherValue", array("batchSize" => 1));
$m = $cursor->getMetadata();
$this->assertTrue($m["count"] == 2);
$this->assertTrue(count($m["result"]) == 1);
$this->assertTrue($m["hasMore"] == true);
}