Exemplo n.º 1
0
 /**
  * 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();
     }
 }
Exemplo n.º 2
0
 /**
  * Scrap an instance (move it to trash, if object supports, or delete it).
  *
  * @param  EntityInterface $instance
  * @param  bool            $force_delete
  * @return EntityInterface
  */
 public function &scrap(EntityInterface &$instance, $force_delete = false)
 {
     if ($instance->isNew()) {
         throw new RuntimeException('Only objects that are saved to database can be modified');
     }
     $registered_type = $this->requireRegisteredType(get_class($instance));
     $instance_id = $instance->getId();
     $instance = $this->getProducerForRegisteredType($registered_type)->scrap($instance, $force_delete);
     if ($instance->isNew() && !empty($this->objects_pool[$registered_type][$instance_id])) {
         unset($this->objects_pool[$registered_type][$instance_id]);
     }
     return $instance;
 }