Page MenuHomePhabricator

D567.id2059.diff
No OneTemporary

D567.id2059.diff

diff --git a/mvc/Director.php b/mvc/Director.php
--- a/mvc/Director.php
+++ b/mvc/Director.php
@@ -1,15 +1,60 @@
<?php namespace spitfire\mvc;
-use spitfire\core\ContextCLI;
-use spitfire\mvc\MVC;
+use spitfire\cli\arguments\CLIArguments;
-abstract class Director extends MVC
+
+/**
+ * The director allows an application to register a command that should be able
+ * to be invoked via CLI.
+ *
+ * @author César de la Cal Bretschneider <cesar@magic3w.com>
+ */
+abstract class Director
{
+ /**
+ * Return an array that describes what parameters the application expects.
+ * This looks something like this:
+ *
+ * <code>
+ * return [
+ * '-v' => '--verbose',
+ * '-t' => '--tag',
+ * '--verbose' => [
+ * 'type' => 'bool',
+ * 'description' => 'Provide verbose output'
+ * ],
+ * '--tag' => [
+ * 'required' => false,
+ * 'type' => 'string',
+ * 'description' => 'Selects which tag to use. If omitted, the script will ask for a tag'
+ * ]
+ * ];
+ * </code>
+ *
+ * The array may contain any of the following: a string or an array.
+ *
+ * If the key contains a string, it redirects the settings to the appropriate
+ * key. In our example the '-v' can be redirected to '--verbose', but also
+ * deprecated keys can be addressed like '--debug' to '--verbose'
+ *
+ * If the key contains an array, three keys are expected:
+ *
+ * - Required: Indicating whether the key is required to execute the director
+ * - Type: Allowing the system to pre-process input (arrays can be read from multiple params and ints can be type checked)
+ * - Description: If the user requests help or a list for the parameters, they will get this.
+ *
+ * @return array
+ */
+ public abstract function parameters() : array;
- public function __construct(ContextCLI$intent) {
- parent::__construct($intent);
- $this->call = new Invoke();
- }
+ /**
+ * Executes the director, handling control to the application implementing it.
+ *
+ * @param array $parameters The array of parameters parsed from the input, using the data provided by parameters()
+ * @param CLIArguments $arguments The raw arguments read from the process
+ * @return int The return code
+ */
+ public abstract function exec(array $parameters, CLIArguments $arguments): int;
-}
\ No newline at end of file
+}

File Metadata

Mime Type
text/plain
Expires
Apr 11 2021, 4:05 AM (9 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6081
Default Alt Text
D567.id2059.diff (2 KB)

Event Timeline