コード例 #1
0
 /**
  * Adds or updates the given model in the repository for the
  * given API path
  * @param Document $model
  * @param string $path The API path
  * @return void
  */
 public function saveModelForPath($model, $path)
 {
     $documentDatabase = $this->getDatabaseNameFromPath($path);
     /** @var DocumentRepository $repository */
     $repository = $this->getRepositoryForPath($path);
     $repository->setDatabase($documentDatabase);
     $model->_setDb($documentDatabase);
     if ($repository) {
         if ($model->_isNew()) {
             $repository->add($model);
         } else {
             $repository->update($model);
         }
         $this->persistAllChanges();
     }
 }
コード例 #2
0
 /**
  * Displays information about the given Document
  *
  * @param Document $document
  * @param bool $showBody
  */
 public function showDocument(Document $document, $showBody = FALSE)
 {
     $this->outputLine(static::ESCAPE . static::GREEN . 'Database: ' . $document->_getDb() . ' ' . 'ID: ' . ($document->getId() ? $document->getId() : '(Missing ID)') . ' ' . static::ESCAPE . static::NORMAL);
     if ($showBody) {
         $this->outputLine($this->formatJsonData($document->_getDataProtected(), TRUE) . PHP_EOL);
     }
 }
コード例 #3
0
ファイル: DocumentRepository.php プロジェクト: pkerling/rest
 /**
  * Merges two Documents
  *
  * @param Document                 $oldDocument
  * @param Document|array|\stdClass $newDocument
  * @throws \Cundd\Rest\Domain\Exception\NoDatabaseSelectedException if the converted Document has no database
  * @return Document
  */
 protected function mergeDocuments($oldDocument, $newDocument)
 {
     $mergeKeys = array('uid', 'pid', 'id', 'db', Document::DATA_PROPERTY_NAME);
     foreach ($mergeKeys as $key) {
         if (isset($newDocument[$key]) && $newDocument[$key]) {
             $oldDocument[$key] = $newDocument[$key];
         }
     }
     if (!$oldDocument->_getDb()) {
         $currentDatabase = $this->getDatabase();
         if (!$currentDatabase) {
             throw new NoDatabaseSelectedException('The given object and the repository have no database set', 1389257938);
         }
         $oldDocument->_setDb($currentDatabase);
     }
     return $oldDocument;
 }
コード例 #4
0
ファイル: DocumentTest.php プロジェクト: tritumRz/rest
 /**
  * @test
  */
 public function offsetUnsetArrayTest()
 {
     $key = 'firstName';
     unset($this->fixture[$key]);
     $this->assertNull($this->fixture->valueForKey($key));
 }