Hoa central
Resolve.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Core\Bin;
38 
39 use Hoa\Console;
40 use Hoa\Core;
41 
51 {
57  protected $options = [
58  ['exists', Console\GetOption::NO_ARGUMENT, 'E'],
59  ['unfold', Console\GetOption::NO_ARGUMENT, 'u'],
60  ['tree', Console\GetOption::NO_ARGUMENT, 't'],
61  ['no-verbose', Console\GetOption::NO_ARGUMENT, 'V'],
62  ['help', Console\GetOption::NO_ARGUMENT, 'h'],
63  ['help', Console\GetOption::NO_ARGUMENT, '?']
64  ];
65 
66 
67 
73  public function main()
74  {
75  $exists = true;
76  $unfold = false;
77  $tree = false;
78  $verbose = Console::isDirect(STDOUT);
79 
80  while (false !== $c = $this->getOption($v)) {
81  switch ($c) {
82  case 'E':
83  $exists = false;
84 
85  break;
86 
87  case 'u':
88  $unfold = true;
89 
90  break;
91 
92  case 't':
93  $tree = true;
94 
95  break;
96 
97  case 'V':
98  $verbose = false;
99 
100  break;
101 
102  case 'h':
103  case '?':
104  return $this->usage();
105 
106  case '__ambiguous':
107  $this->resolveOptionAmbiguity($v);
108 
109  break;
110  }
111  }
112 
113  $this->parser->listInputs($path);
114 
115  if (null === $path) {
116  return $this->usage();
117  }
118 
119  if (true === $tree) {
121  $foo = substr($path, 0, 6);
122 
123  if ('hoa://' !== $foo) {
124  return;
125  }
126 
127  $path = substr($path, 6);
128  $current = $protocol;
129 
130  foreach (explode('/', $path) as $component) {
131  if (!isset($current[$component])) {
132  break;
133  }
134 
135  $current = $current[$component];
136  }
137 
138  echo $current;
139 
140  return;
141  }
142 
143  if (true === $verbose) {
144  echo
145  Console\Chrome\Text::colorize($path, 'foreground(yellow)'),
146  ' is equivalent to:', "\n";
147  }
148 
149  $resolved = resolve($path, $exists, $unfold);
150 
151  foreach ((array) $resolved as $r) {
152  echo $r, "\n";
153  }
154 
155  return;
156  }
157 
163  public function usage()
164  {
165  echo
166  'Usage : core:resolve <options> path', "\n",
167  'Options :', "\n",
168  $this->makeUsageOptionsList([
169  'E' => 'Do not check if the resolution result exists.',
170  'u' => 'Unfold all possible results.',
171  't' => 'Print the tree from the path.',
172  'V' => 'No-verbose, i.e. be as quiet as possible, just print ' .
173  'essential informations.',
174  'help' => 'This help.'
175  ]), "\n";
176 
177  return;
178  }
179 }
180 
181 __halt_compiler();
182 Resolve hoa:// paths.
makeUsageOptionsList(Array $definitions=[])
Definition: Kit.php:149
you have Consistency php Event php Exception php Parameter php Protocol php Data php SUCCEED FAILED … __hoa_core_fill DS PS CRLF OS_WIN PHP_WINDOWS_VERSION_PLATFORM S_64_BITS S_32_BITS PHP_INT_MIN PHP_FLOAT_MIN PHP_FLOAT_MAX π void _public _protected _private _static _abstract _pure _final _dynamic _concrete _overridable WITH_COMPOSER Composer Autoload ClassLoader cli autoload php suhosin The URL scheme hoa
Definition: Core.php:160
static getProtocol()
Definition: Core.php:352
getOption(&$optionValue, $short=null)
Definition: Kit.php:104
resolveOptionAmbiguity(Array $solutions)
Definition: Kit.php:190
static colorize($text, $attributesBefore, $attributesAfter= 'normal')
Definition: Text.php:83
static isDirect($pipe)
Definition: Console.php:261