Hoa central
Public Member Functions | Public Attributes | Protected Attributes | List of all members
Hoa\Console\Dispatcher\Kit Class Reference
Inheritance diagram for Hoa\Console\Dispatcher\Kit:

Public Member Functions

 __construct (Router $router, Dispatcher $dispatcher, View\Viewable $view=null)
 
 getOption (&$optionValue, $short=null)
 
 setOptions (Array $options)
 
 makeUsageOptionsList (Array $definitions=[])
 
 resolveOptionAmbiguity (Array $solutions)
 
 status ($text, $status)
 
 readLine ($prefix=null)
 
 readPassword ($prefix=null)
 
- Public Member Functions inherited from Hoa\Dispatcher\Kit
 __construct (Router $router, Dispatcher $dispatcher, View\Viewable $view=null)
 
 construct ()
 

Public Attributes

 $parser = null
 
- Public Attributes inherited from Hoa\Dispatcher\Kit
 $router = null
 
 $dispatcher = null
 
 $view = null
 
 $data = null
 

Protected Attributes

 $options = null
 
 $_options = null
 

Detailed Description

Class .

A structure, given to action, that holds some important data.

Definition at line 52 of file Kit.php.

Constructor & Destructor Documentation

Hoa\Console\Dispatcher\Kit::__construct ( Router  $router,
Dispatcher  $dispatcher,
View\Viewable  $view = null 
)

Build a dispatcher kit.

Parameters
\Hoa\Router$routerThe router.
\Hoa\Dispatcher$dispatcherThe dispatcher.
\Hoa\View\Viewable$viewThe view.
Returns
void

Definition at line 85 of file Kit.php.

89  {
90  parent::__construct($router, $dispatcher, $view);
91 
92  $this->parser = new Console\Parser();
93 
94  return;
95  }

Member Function Documentation

Hoa\Console\Dispatcher\Kit::getOption ( $optionValue,
  $short = null 
)

Alias of ::getOptions().

Parameters
string&$optionValuePlease, see original API.
string$shortPlease, see original API.
Returns
mixed

Definition at line 104 of file Kit.php.

105  {
106  if (null === $this->_options && !empty($this->options)) {
107  $this->setOptions($this->options);
108  }
109 
110  if (null === $this->_options) {
111  return false;
112  }
113 
114  return $this->_options->getOption($optionValue, $short);
115  }
setOptions(Array $options)
Definition: Kit.php:124

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Console\Dispatcher\Kit::makeUsageOptionsList ( Array  $definitions = [])

It is a helper to make the usage options list.

Parameters
array$definitionsAn associative arry: short or long option associated to the definition.
Returns
string

Definition at line 149 of file Kit.php.

150  {
151  $out = [];
152 
153  foreach ($this->options as $i => $options) {
154  $out[] = [
155  ' -' . $options[Console\GetOption::OPTION_VAL] . ', --' .
159  ? '='
162  ? '[=]'
163  : '')),
164  (isset($definitions[$options[Console\GetOption::OPTION_VAL]])
165  ? $definitions[$options[Console\GetOption::OPTION_VAL]]
166  : (isset($definitions[$options[0]])
168  : null
169  )
170  )
171  ];
172  }
173 
175  $out,
176  Console\Chrome\Text::ALIGN_LEFT,
177  .5,
178  0,
179  '|: '
180  );
181  }
static columnize(Array $line, $alignement=self::ALIGN_LEFT, $horizontalPadding=2, $verticalPadding=0, $separator=null)
Definition: Text.php:126

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Console\Dispatcher\Kit::readLine (   $prefix = null)

Read, edit, bind… a line from STDIN.

Parameters
string$prefixPrefix.
Returns
string

Definition at line 243 of file Kit.php.

244  {
245  static $_rl = null;
246 
247  if (null === $_rl) {
248  $_rl = new Console\Readline();
249  }
250 
251  return $_rl->readLine($prefix);
252  }

Here is the caller graph for this function:

Hoa\Console\Dispatcher\Kit::readPassword (   $prefix = null)

Read, edit, bind… a password from STDIN.

Parameters
string$prefixPrefix.
Returns
string

Definition at line 260 of file Kit.php.

261  {
262  static $_rl = null;
263 
264  if (null === $_rl) {
265  $_rl = new Console\Readline\Password();
266  }
267 
268  return $_rl->readLine($prefix);
269  }

Here is the caller graph for this function:

Hoa\Console\Dispatcher\Kit::resolveOptionAmbiguity ( Array  $solutions)

Resolve option ambiguity by asking the user to choose amongst some appropriated solutions.

Parameters
array$solutionsSolutions.
Returns
void

Definition at line 190 of file Kit.php.

191  {
192  echo
193  'You have made a typo in the option ',
194  $solutions['option'], '; it can match the following options: ', "\n",
195  ' • ', implode(";\n • ", $solutions['solutions']), '.', "\n",
196  'Please, type the right option (empty to choose the first one):', "\n";
197  $new = $this->readLine('> ');
198 
199  if (empty($new)) {
200  $new = $solutions['solutions'][0];
201  }
202 
203  $solutions['solutions'] = [$new];
204 
205  $this->_options->resolveOptionAmbiguity($solutions);
206 
207  return;
208  }
readLine($prefix=null)
Definition: Kit.php:243

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Console\Dispatcher\Kit::setOptions ( Array  $options)

Initialize options.

Parameters
array$optionsOptions, as described in .
Returns
array

Definition at line 124 of file Kit.php.

125  {
126  $old = $this->options;
127  $this->options = $options;
128  $rule = $this->router->getTheRule();
129  $variables = $rule[Router::RULE_VARIABLES];
130 
131  if (isset($variables['_tail'])) {
132  $this->parser->parse($variables['_tail']);
133  $this->_options = new Console\GetOption(
134  $this->options,
135  $this->parser
136  );
137  }
138 
139  return $old;
140  }
const RULE_VARIABLES
Definition: Router.php:112

Here is the caller graph for this function:

Hoa\Console\Dispatcher\Kit::status (   $text,
  $status 
)

Make a render of an operation.

Parameters
string$textThe operation text.
bool$statusThe operation status.
Returns
void

Definition at line 217 of file Kit.php.

218  {
219  $window = Console\Window::getSize();
220  $out =
221  ' ' . Console\Chrome\Text::colorize('*', 'foreground(yellow)') . ' ' .
222  $text . str_pad(
223  ' ',
224  $window['x']
225  - strlen(preg_replace('#' . "\033" . '\[[0-9]+m#', '', $text))
226  - 8
227  ) .
228  ($status === true
229  ? '[' . Console\Chrome\Text::colorize('ok', 'foreground(green)') . ']'
230  : '[' . Console\Chrome\Text::colorize('!!', 'foreground(white) background(red)') . ']');
231 
232  echo $out, "\n";
233 
234  return;
235  }
static getSize()
Definition: Window.php:118
static colorize($text, $attributesBefore, $attributesAfter= 'normal')
Definition: Text.php:83

Here is the call graph for this function:

Member Data Documentation

Hoa\Console\Dispatcher\Kit::$_options = null
protected

Definition at line 73 of file Kit.php.

Hoa\Console\Dispatcher\Kit::$options = null
protected

Definition at line 66 of file Kit.php.

Hoa\Console\Dispatcher\Kit::$parser = null

Definition at line 59 of file Kit.php.


The documentation for this class was generated from the following file: