Debian Codegraph @

vendor/ipl/html/src/Contract/Form.php

raw
1 <?php
2
3 namespace ipl\Html\Contract;
4
5 use Evenement\EventEmitterInterface;
6 use Psr\Http\Message\ServerRequestInterface;
7
8 interface Form extends EventEmitterInterface
9 {
10 /** @var string Event emitted when the form is associated with a request but is not sent */
11 public const ON_REQUEST = 'request';
12
13 /** @var string Event emitted when the form has been sent */
14 public const ON_SENT = 'sent';
15
16 /** @var string Event emitted when the form is validated */
17 public const ON_VALIDATE = 'validate';
18
19 /** @var string Event emitted when the form has been submitted */
20 public const ON_SUBMIT = 'success';
21
22 /** @var string Event emitted in case of an error */
23 public const ON_ERROR = 'error';
24
25 /**
26 * Get the Form submission URL
27 *
28 * @return ?string
29 */
30 public function getAction();
31
32 /**
33 * Get the HTTP method the form accepts
34 *
35 * @return string
36 */
37 public function getMethod();
38
39 /**
40 * Get the request associated with the form
41 *
42 * @return ?ServerRequestInterface
43 */
44 public function getRequest();
45
46 /**
47 * Handle the given request
48 *
49 * The following events will be emitted:
50 * - {@see self::ON_REQUEST} when the form is associated with a request but is not sent
51 * - {@see self::ON_SENT} when the form has been sent
52 * - {@see self::ON_SUBMIT} when the form has been submitted
53 * - {@see self::ON_ERROR} in case of an error
54 *
55 * @param ServerRequestInterface $request
56 *
57 * @return $this
58 */
59 public function handleRequest(ServerRequestInterface $request);
60
61 /**
62 * Get whether the form has been sent
63 *
64 * A form is considered sent if the request's method equals the form's method.
65 *
66 * @return bool
67 */
68 public function hasBeenSent();
69
70 /**
71 * Get whether the form has been submitted
72 *
73 * A form is submitted when it has been sent and a submit button, if set, has been pressed.
74 *
75 * @return bool
76 */
77 public function hasBeenSubmitted();
78
79 /**
80 * Check if the form is valid
81 *
82 * Emits the {@see self::ON_VALIDATE} event if the form has not been validated before.
83 *
84 * @return bool
85 */
86 public function isValid();
87 }