Exemple #1
0
 public function getReferencePod()
 {
     if (!$this->_referencePodId) {
         return null;
     } else {
         $info = $this->_toolbox->parseId($this->_referencePodId);
         return $this->_toolbox->getPodManager()->load($info['collection'], $info['key']);
     }
 }
Exemple #2
0
 /**
  * Processes the transaction result after committing.
  * @param  array                       $results The results array from the server.
  * @throws TransactionManagerException
  * @return array
  */
 private function processResult($results)
 {
     $processedResults = array();
     foreach ($results as $id => $result) {
         $command = $this->_commands[$id];
         switch ($command['action']) {
             case "PodManager:store":
                 $processed = $this->_toolbox->getPodManager()->processStoreResult($command['object']->getPod(), $result['_rev'], $result['_id']);
                 break;
             case "PodManager:delete":
                 $this->_toolbox->getPodManager()->processDeleteResult($command['object']->getPod());
                 $processed = true;
                 break;
             case "PodManager:load":
                 $parsedId = $this->_toolbox->parseId($result['_id']);
                 if (!$result) {
                     $processed = null;
                     break;
                 }
                 $processed = $this->_toolbox->getPodManager()->convertArrayToPod($command['data']['type'], $result);
                 break;
             case "Query:getOne":
             case "Query:getAll":
                 $processed = $result;
                 break;
             case "Finder:find":
             case "Finder:findAll":
             case "Finder:findNear":
             case "Finder:findAllNear":
             case "Finder:findWithin":
             case "Finder:findAllWithin":
             case "Finder:search":
             case "Finder:searchAll":
                 if (isset($command['data']['coordinates'])) {
                     $processed = $this->_toolbox->getFinder()->convertToPods($command['data']['type'], $result, $command['data']['coordinates']);
                 } else {
                     $processed = $this->_toolbox->getFinder()->convertToPods($command['data']['type'], $result);
                 }
                 break;
             case "Finder:findOne":
             case "Finder:any":
             case "Finder:findOneNear":
             case "Finder:findOneWithin":
             case "Finder:searchForOne":
                 if ($result == null) {
                     $processed = null;
                     break;
                 }
                 if (isset($command['data']['coordinates'])) {
                     $processed = $this->_toolbox->getFinder()->convertToPods($command['data']['type'], array($result), $command['data']['coordinates']);
                 } else {
                     $processed = $this->_toolbox->getFinder()->convertToPods($command['data']['type'], array($result));
                 }
                 $processed = reset($processed);
                 break;
             case "GraphManager:getInboundEdges":
             case "GraphManager:getOutboundEdges":
             case "GraphManager:getEdges":
                 $processed = $this->_toolbox->getGraphManager()->convertToPods("edge", $result);
                 break;
             case "GraphManager:getNeighbours":
                 $processed = $this->_toolbox->getGraphManager()->convertToPods("vertex", $result);
                 break;
             default:
                 throw new TransactionManagerException("Invalid or unimplemented action ({$command['action']}) while processing the transaction results.");
         }
         if (array_key_exists($id, $this->_registeredResults)) {
             $processedResults[$this->_registeredResults[$id]] = $processed;
         }
     }
     return $processedResults;
 }
Exemple #3
0
 /**
  * @covers Paradox\Toolbox::parseId
  */
 public function testParseId()
 {
     $parsed = $this->toolbox->parseId('mycollection/123456');
     $this->assertEquals('mycollection', $parsed['collection'], "The parsed collection does not match");
     $this->assertEquals('123456', $parsed['key'], "The parsed key does not match");
 }