コード例 #1
0
 public function putStatement(StatementId $id, Statement $statement)
 {
     if (null !== $statement->getId() && !$id->equals($statement->getId())) {
         throw new ConflictException(sprintf('Id parameter ("%s") and statement id ("%s") do not match.', $id->getValue(), $statement->getId()->getValue()));
     }
     try {
         $existingStatement = $this->repository->findStatementById($id->getValue());
     } catch (NotFoundException $e) {
         $this->repository->storeStatement($statement, true);
     }
     return new Response('', 204);
 }
コード例 #2
0
 public static function fromModel(StatementModel $model)
 {
     $statement = new self();
     $statement->id = $model->getId()->getValue();
     $statement->actor = Object::fromModel($model->getActor());
     $statement->verb = Verb::fromModel($model->getVerb());
     $statement->object = Object::fromModel($model->getObject());
     if (null !== $model->getTimestamp()) {
         $statement->created = $model->getTimestamp()->getTimestamp();
     }
     if (null !== ($result = $model->getResult())) {
         $statement->result = Result::fromModel($result);
     }
     if (null !== ($authority = $model->getAuthority())) {
         $statement->authority = Object::fromModel($authority);
     }
     if (null !== ($context = $model->getContext())) {
         $statement->context = Context::fromModel($context);
     }
     if (null !== ($attachments = $model->getAttachments())) {
         $statement->hasAttachments = true;
         $statement->attachments = array();
         foreach ($attachments as $attachment) {
             $mappedAttachment = Attachment::fromModel($attachment);
             $mappedAttachment->statement = $statement;
             $statement->attachments[] = $mappedAttachment;
         }
     } else {
         $statement->hasAttachments = false;
     }
     return $statement;
 }
コード例 #3
0
 /**
  * {@inheritDoc}
  */
 public function storeStatement(Statement $statement)
 {
     if (null !== $statement->getId()) {
         return $this->doStoreStatements($statement, 'put', array('statementId' => $statement->getId()), 204);
     } else {
         return $this->doStoreStatements($statement);
     }
 }
コード例 #4
0
 public static function createFromModel(Statement $statement)
 {
     $mappedStatement = new MappedStatement();
     $mappedStatement->id = $statement->getId();
     $mappedStatement->actor = $statement->getActor();
     $mappedStatement->verb = MappedVerb::createFromModel($statement->getVerb());
     $mappedStatement->object = $statement->getObject();
     $mappedStatement->result = $statement->getResult();
     $mappedStatement->authority = $statement->getAuthority();
     $mappedStatement->created = $statement->getCreated();
     $mappedStatement->stored = $statement->getStored();
     return $mappedStatement;
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 public final function storeStatement(Statement $statement, $flush = true)
 {
     if (null === $statement->getId()) {
         $statement = $statement->withId(StatementId::fromUuid(Uuid::uuid4()));
     }
     $mappedStatement = MappedStatement::fromModel($statement);
     $mappedStatement->stored = time();
     $this->repository->storeStatement($mappedStatement, $flush);
     return $statement->getId();
 }
コード例 #6
0
 /**
  * Writes a {@link Statement} to the underlying data storage.
  *
  * @param Statement $statement The statement to store
  * @param bool      $flush     Whether or not to flush the managed objects
  *                             immediately (i.e. write them to the data
  *                             storage)
  *
  * @return string The UUID of the created Statement
  */
 public final function storeStatement(Statement $statement, $flush = true)
 {
     $uuid = $statement->getId();
     $mappedStatement = MappedStatement::createFromModel($statement);
     $mappedStatement->stored = new \DateTime();
     if (null === $uuid) {
         $uuid = Uuid::uuid4()->toString();
         $mappedStatement->id = $uuid;
     }
     $this->storeMappedStatement($mappedStatement, $flush);
     return $uuid;
 }
コード例 #7
0
 private function assertStatementEquals(Statement $expected, Statement $actual, $validateId = true)
 {
     if ($validateId) {
         $this->assertSame($expected->getId(), $actual->getId());
     }
     $this->assertTrue($actual->getActor()->equals($expected->getActor()));
     $this->assertTrue($actual->getVerb()->equals($expected->getVerb()));
     $this->assertTrue($actual->getObject()->equals($expected->getObject()));
     if (null === $expected->getResult()) {
         $this->assertNull($actual->getResult());
     } else {
         $this->assertTrue($actual->getResult()->equals($expected->getResult()));
     }
     if (null === $expected->getAuthority()) {
         $this->assertNull($actual->getAuthority());
     } else {
         $this->assertTrue($actual->getAuthority()->equals($expected->getAuthority()));
     }
 }