1: <?php
2:
3: namespace Charcoal\App\Script;
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: * Script are actions called from the CLI.
14: *
15: * Typically, with the `charcoal` bin.
16: */
17: interface ScriptInterface
18: {
19:
20: /**
21: * Give an opportunity to children classes to inject dependencies from a Pimple Container.
22: *
23: * Does nothing by default, reimplement in children classes.
24: *
25: * The `$container` DI-container (from `Pimple`) should not be saved or passed around, only to be used to
26: * inject dependencies (typically via setters).
27: *
28: * @param Container $container A dependencies container instance.
29: * @return void
30: */
31: public function setDependencies(Container $container);
32:
33: /**
34: * @param string $ident The script identifier string.
35: * @return ScriptInterface Chainable
36: */
37: public function setIdent($ident);
38:
39: /**
40: * @return string
41: */
42: public function ident();
43:
44: /**
45: * @param string $description The script description.
46: * @return ScriptInterface Chainable
47: */
48: public function setDescription($description);
49:
50: /**
51: * @return string
52: */
53: public function description();
54:
55: /**
56: * @param array $arguments The script arguments array, as [key=>value].
57: * @return ScriptInterface Chainable
58: */
59: public function setArguments(array $arguments);
60:
61: /**
62: * @param string $argumentIdent The argument identifier.
63: * @param array $argument The argument options.
64: * @return ScriptInterface Chainable
65: */
66: public function addArgument($argumentIdent, array $argument);
67:
68: /**
69: * @return array $arguments
70: */
71: public function arguments();
72:
73: /**
74: * @param string $argumentIdent The argument identifier to retrieve options from.
75: * @return array
76: */
77: public function argument($argumentIdent);
78:
79: /**
80: * Run the script.
81: *
82: * @param RequestInterface $request A PSR-7 compatible Request instance.
83: * @param ResponseInterface $response A PSR-7 compatible Response instance.
84: * @return ResponseInterface
85: */
86: public function run(RequestInterface $request, ResponseInterface $response);
87: }
88: