1 <?php
 2 
 3 
 4 class EditAction
 5 {
 6     public function __construct(Auth $auth, Service $service, Payload $payload)
 7     {
 8         $this->auth = $auth;
 9         $this->service = $service;
10         // need payload in "Action" to deal with authorization
11         $this->payload = $payload;
12     }
13 
14     public function __invoke($input)
15     {
16         if (! $this->isAllowed()) {
17             // Need payload here to create an unauthorized response
18             return $this->payload
19                 ->setStatus(Payload::NOT_AUTHENTICATED);
20         }
21 
22         // maybe need to add some kind of check here instead, I guess?
23         // seems wrong... instead, below
24         // return $this->payload
25         //     ->setStatus(Payload::UPDATED)
26         //     ->setOuput(call_user_func($this->service, $input));
27 
28         return call_user_func($this->service, $input));
29     }
30 }
31 
32 class EditService
33 {
34     public function __construct(Mapper $mapper, Filter $filter, Payload $payload)
35     {
36         $this->mapper = $mapper;
37         $this->filter = $filter;
38         // need payload in "Service" to deal with invalid input, etc.
39         $this->payload = $payload;
40     }
41 
42     public function __invoke($input)
43     {
44         // Should return a Payload, thou, right?
45         // if ($this->filter->validate($input)) {
46         //     return $this->mapper->edit($input);
47         // }
48         // return $this->filter->errors();
49 
50 
51         if ($this->filter->validate($input)) {
52             return $this->payload
53                 ->setStatus(Payload::UPDATED)
54                 ->setOuput($this->mapper->edit($input));
55         }
56 
57         return $this->payload->setStatus(Payload::ERROR);
58     }
59 }