Skip to content

Commit

Permalink
Added extra method for loading the initial draft of an object
Browse files Browse the repository at this point in the history
  • Loading branch information
jkphl committed Aug 1, 2016
1 parent fe8a6e3 commit f077fb6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
30 changes: 30 additions & 0 deletions src/Object/Application/Model/Object/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,36 @@ public function createObject(
* @return ObjectInterface Object
*/
public function loadObject(RepositoryLocatorInterface $locator, $visibility = SelectorInterface::ALL)
{
$revision = $locator->getRevision();
return (($revision->getRevision() == 1) && $revision->isDraft()) ?
$this->loadInitialObjectDraft($locator, $visibility) : $this->loadObjectRevision($locator, $visibility);
}

/**
* Load a particular object revision from a repository
*
* @param RepositoryLocatorInterface $locator Repository object locator
* @param int $visibility Object visibility
* @return ObjectInterface Object
*/
protected function loadInitialObjectDraft(RepositoryLocatorInterface $locator, $visibility = SelectorInterface::ALL)
{
// Load the object resource respecting visibility constraints
$objectResource = $this->loadObjectResource($locator, $visibility);

// Instantiate and return the object
return ObjectFactory::createFromResource($locator, $objectResource);
}

/**
* Load a particular object revision from a repository
*
* @param RepositoryLocatorInterface $locator Repository object locator
* @param int $visibility Object visibility
* @return ObjectInterface Object
*/
protected function loadObjectRevision(RepositoryLocatorInterface $locator, $visibility = SelectorInterface::ALL)
{
// Create the current revision locator
/** @var RepositoryLocatorInterface $currentLocator */
Expand Down
4 changes: 2 additions & 2 deletions src/Object/Domain/Model/Object/Revision.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Revision implements SerializablePropertyInterface
/**
* Object revision number
*
* @var int
* @var int|null
*/
protected $revision = null;
/**
Expand Down Expand Up @@ -141,7 +141,7 @@ public function serialize()
/**
* Return the object revision number
*
* @return int Object revision number
* @return int|null Object revision number
*/
public function getRevision()
{
Expand Down
9 changes: 7 additions & 2 deletions src/Object/Tests/NoteObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
namespace Apparat\Object\Tests;

use Apparat\Object\Application\Model\Object\Note;
use Apparat\Object\Ports\Facades\ObjectFacade;
use Apparat\Object\Ports\Types\Object as ObjectTypes;
use Apparat\Object\Ports\Object\Note as ApparatNote;

/**
* Note object tests
Expand Down Expand Up @@ -71,8 +73,11 @@ public function testCreateAndPublishNoteObject()
$this->assertEquals($creationDate, $note->getCreated());
$this->assertEquals('This is a sample note object. It features:', $note->getTitle());

// $noteApparatObject = ObjectFacade::load('repo'.$note->getRepositoryLocator());
// $this->assertInstanceOf(\Apparat\Object\Ports\Object\Note::class, $noteApparatObject);
/** @var ApparatNote $noteApparatObject */
$noteApparatObject = ObjectFacade::load('/repo'.$note->getRepositoryLocator());
$this->assertInstanceOf(ApparatNote::class, $noteApparatObject);
$this->assertEquals(ApparatNote::TYPE, $noteApparatObject->getType());
$this->assertEquals('This is a sample note object. It features:', $noteApparatObject['name']);

// Delete temporary repository
$this->deleteRecursive($tempRepoDirectory);
Expand Down

0 comments on commit f077fb6

Please sign in to comment.