Example #1
0
 public function interact()
 {
     // Fetch the entity and apply the payload...
     $entity = $this->getEntity()->setState($this->payload);
     // ... verify that the entity can be updated by the current user
     $this->verifyUpdateAuth($entity);
     // ... verify that the entity is in a valid state
     $this->verifyValid($entity);
     // ... persist the changes
     $this->repo->update($entity);
     // ... verify that the entity can be read by the current user
     $this->verifyReadAuth($entity);
     // ... load the updated entity from the storage layer
     $updated_entity = $this->getEntity();
     // ... and return the updated, formatted entity
     return $this->formatter->__invoke($updated_entity);
 }
Example #2
0
 public function interact()
 {
     // Fetch the entity and apply the payload...
     $entity = $this->getEntity()->setState($this->payload);
     // ... verify that the entity can be updated by the current user
     $this->verifyUpdateAuth($entity);
     // ... verify that the entity is in a valid state
     $this->verifyValid($entity);
     // ... persist the changes
     $this->repo->update($entity);
     // ... check that the entity can be read by the current user
     if ($this->auth->isAllowed($entity, 'read')) {
         // ... and either load the updated entity from the storage layer
         $updated_entity = $this->getEntity();
         // ... and return the updated, formatted entity
         return $this->formatter->__invoke($updated_entity);
     } else {
         // ... or just return nothing
         return;
     }
 }