1: <?php
2:
3: namespace Charcoal\App\Action;
4:
5: // PSR-7 (http messaging) dependencies
6: use \Psr\Http\Message\RequestInterface;
7: use \Psr\Http\Message\ResponseInterface;
8:
9: // Dependencies from `Pimple`
10: use \Pimple\Container;
11:
12: /**
13: *
14: */
15: interface ActionInterface
16: {
17: /**
18: * Actions are callable, with http request and response as parameters.
19: *
20: * @param RequestInterface $request A PSR-7 compatible Request instance.
21: * @param ResponseInterface $response A PSR-7 compatible Response instance.
22: * @return ResponseInterface
23: */
24: public function __invoke(RequestInterface $request, ResponseInterface $response);
25:
26: /**
27: * Give an opportunity to children classes to inject dependencies from a Pimple Container.
28: *
29: * Does nothing by default, reimplement in children classes.
30: *
31: * The `$container` DI-container (from `Pimple`) should not be saved or passed around, only to be used to
32: * inject dependencies (typically via setters).
33: *
34: * @param Container $container A dependencies container instance.
35: * @return void
36: */
37: public function setDependencies(Container $container);
38:
39: /**
40: * @param array $data The data to set.
41: * @return ActionInterface Chainable
42: */
43: public function setData(array $data);
44:
45: /**
46: * @param string $mode The action mode.
47: * @return ActionInterface Chainable
48: */
49: public function setMode($mode);
50:
51: /**
52: * @return string
53: */
54: public function mode();
55:
56: /**
57: * @param boolean $success Success flag (true / false).
58: * @return ActionInterface Chainable
59: */
60: public function setSuccess($success);
61:
62: /**
63: * @return boolean
64: */
65: public function success();
66:
67: /**
68: * @param string $url The success URL.
69: * @return ActionInterface Chainable
70: */
71: public function setSuccessUrl($url);
72:
73: /**
74: * @return string
75: */
76: public function successUrl();
77:
78: /**
79: * @param string $url The success URL.
80: * @return ActionInterface Chainable
81: */
82: public function setFailureUrl($url);
83:
84: /**
85: * @return string
86: */
87: public function failureUrl();
88:
89: /**
90: * @return string
91: */
92: public function redirectUrl();
93:
94: /**
95: * @return array
96: */
97: public function results();
98:
99: /**
100: * @param RequestInterface $request A PSR-7 compatible Request instance.
101: * @param ResponseInterface $response A PSR-7 compatible Response instance.
102: * @return ResponseInterface
103: */
104: public function run(RequestInterface $request, ResponseInterface $response);
105:
106: /**
107: * Initialize the action with a request.
108: *
109: * @param RequestInterface $request The request to initialize.
110: * @return boolean Success / Failure.
111: */
112: public function init(RequestInterface $request);
113: }
114: