/**
  * Drop an existing type instance.
  *
  * @param  ServerRequestInterface         $request
  * @return EntityInterface|StatusResponse
  */
 public function delete(ServerRequestInterface $request)
 {
     if ($this->isReadOnly()) {
         return new NotFoundStatusResponse();
     }
     if ($this->active_object && $this->active_object->isLoaded()) {
         $authenticated_user = $this->getAuthenticatedUser($request);
         if ($this->shouldCheckPermissions() && !$this->canDelete($this->active_object, $authenticated_user)) {
             return new ForbiddenStatusResponse();
         }
         $this->active_object = $this->pool->scrap($this->active_object);
         if ($this->active_object->isNew()) {
             return ['single' => ['id' => $this->active_object->getId()]];
         } else {
             return $this->active_object;
         }
     } else {
         return new NotFoundStatusResponse();
     }
 }
Exemple #2
0
 /**
  * Add object to the pool.
  *
  * @param EntityInterface $object
  */
 public function remember(EntityInterface &$object)
 {
     if ($object->isLoaded()) {
         $this->addToObjectPool($this->requireRegisteredType(get_class($object)), $object->getId(), $object);
     } else {
         throw new InvalidArgumentException('Object needs to be saved in the database to be remembered');
     }
 }