1 | <?php |
||
7 | class UpdateOperation implements \einfach\operation\IOperation |
||
|
|||
8 | { |
||
9 | /** |
||
10 | * @param $params |
||
11 | * @return \einfach\operation\Result |
||
12 | */ |
||
13 | public public function __invoke($params) |
||
14 | { |
||
15 | $result = (new Railway) |
||
16 | ->step(function ($params) { |
||
17 | echo "Hey {$params['name']}. Say hello to anonymous function!"; |
||
18 | //return error('Early fail'); |
||
19 | return ok(['newParam' => 'newValue']); |
||
20 | }) |
||
21 | ->step([$this, 'nestedRailway']) |
||
22 | ->step([$this, 'castRequest']) |
||
23 | ->step([$this, 'validateRequest']) |
||
24 | ->step([$this, 'findUser']) |
||
25 | ->step([$this, 'updateDB']) |
||
26 | ->tryCatch([$this, 'sendNotification']) |
||
27 | ->always([$this, 'writeLog']) |
||
28 | ->failure([$this, 'notifyAdmin']) |
||
29 | ->runWithParams($params); |
||
30 | |||
31 | return $result; |
||
32 | } |
||
33 | |||
34 | public function nestedRailway($params){ |
||
35 | return (new Railway) |
||
36 | ->step(function ($params){ |
||
37 | return error('Nested Railway failed!'); |
||
38 | return ok(['nestedRwParam' => 'nestedRwValue']); |
||
39 | }) |
||
40 | ->runWithParams($params); |
||
41 | } |
||
42 | |||
43 | public function castRequest($params) |
||
44 | { |
||
45 | return ok(); |
||
46 | } |
||
47 | |||
48 | public function validateRequest($params) |
||
49 | { |
||
50 | return ok(); |
||
51 | } |
||
52 | |||
53 | public function findUser($params) |
||
54 | { |
||
55 | // pretend I am doing a query |
||
56 | // $user = DB::findById($params['id']); |
||
57 | $user = (object) ['id' => 123, 'name' => 'Eugene', 'phone' => '111111']; |
||
58 | return ok(['model' => $user]); |
||
59 | //return error('User not found!'); |
||
60 | } |
||
61 | |||
62 | public function updateDB($params) |
||
63 | { |
||
64 | return ok(); |
||
65 | } |
||
66 | |||
67 | public function sendNotification($params) |
||
68 | { |
||
69 | //throw new \Exception("Hey there, Exception!"); |
||
70 | return ok(); |
||
71 | } |
||
72 | |||
73 | public function writeLog($params) |
||
74 | { |
||
75 | |||
76 | } |
||
77 | |||
78 | public function notifyAdmin($params) |
||
79 | { |
||
80 | |||
81 | } |
||
82 | } |
||
83 | |||
119 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.