/** * 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(); } }
/** * 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); } }
/** * 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; }
/** * @test */ public function offsetUnsetArrayTest() { $key = 'firstName'; unset($this->fixture[$key]); $this->assertNull($this->fixture->valueForKey($key)); }