Hoa central
Public Member Functions | Protected Attributes | Private Member Functions | List of all members
Hoa\Devtools\Bin\Diagnostic Class Reference
Inheritance diagram for Hoa\Devtools\Bin\Diagnostic:

Public Member Functions

 main ()
 
 usage ()
 
- Public Member Functions inherited from Hoa\Console\Dispatcher\Kit
 __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 ()
 

Protected Attributes

 $options
 
- Protected Attributes inherited from Hoa\Console\Dispatcher\Kit
 $options = null
 
 $_options = null
 

Private Member Functions

 arrayToIni (Array $array)
 

Additional Inherited Members

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

Detailed Description

Class .

This command generates a diagnostic.

Definition at line 50 of file Diagnostic.php.

Member Function Documentation

Hoa\Devtools\Bin\Diagnostic::arrayToIni ( Array  $array)
private

Transform an array into INI format.

Parameters
array$arrayArray to transform.
Returns
string

Definition at line 241 of file Diagnostic.php.

242  {
243  $out = null;
244 
245  foreach ($array as $section => $entries) {
246  if (null !== $out) {
247  $out .= "\n\n";
248  }
249 
250  $out .= '[' . $section . ']';
251 
252  foreach ($entries as $key => $value) {
253  if (is_array($value)) {
254  $value = implode(' ', $value);
255  }
256 
257  $out .= "\n" . $key . ' = "' . $value . '"';
258  }
259  }
260 
261  return $out;
262  }

Here is the caller graph for this function:

Hoa\Devtools\Bin\Diagnostic::main ( )

The entry method.

Returns
int

Definition at line 71 of file Diagnostic.php.

72  {
73  $sections = [];
74  $mail = null;
75  $diagnostic = [];
76 
77  while (false !== $c = $this->getOption($v)) {
78  switch ($c) {
79  case 's':
80  $sections = $this->parser->parseSpecialValue($v);
81 
82  break;
83 
84  case 'm':
85  $mail = $v;
86 
87  break;
88 
89  case 'h':
90  case '?':
91  return $this->usage();
92 
93  case '__ambiguous':
94  $this->resolveOptionAmbiguity($v);
95 
96  break;
97  }
98  }
99 
100  $store = function ($sections, $key, $value = null) use (&$diagnostic) {
101  if (is_array($key) && null === $value) {
102  foreach ($key as $i => $name) {
103  $diagnostic[$sections][$i] = $name;
104  }
105  } else {
106  $diagnostic[$sections][$key] = $value;
107  }
108 
109  return;
110  };
111 
112  $store(
113  'version',
114  'php',
115  phpversion()
116  );
117  $store(
118  'version',
119  'zend_engine',
120  zend_version()
121  );
122  $store(
123  'system',
124  'platform',
125  php_uname()
126  );
127  $store(
128  'system',
129  'architecture',
130  (true === S_32_BITS) ? '32bits' : '64bits'
131  );
132  $store(
133  'system',
134  'lang',
135  isset($_SERVER['LANG']) ? $_SERVER['LANG'] : 'unknown'
136  );
137  $store(
138  'bin',
139  'self',
140  $_SERVER['PHP_SELF']
141  );
142  $store(
143  'bin',
144  'hoa',
145  Core::getInstance()->getParameters()->getFormattedParameter('root.hoa')
146  );
147  $store(
148  'bin',
149  'php_dir',
150  PHP_BINDIR
151  );
152  $store(
153  'bin',
154  'php',
155  defined('PHP_BINARY') ? PHP_BINARY : 'unknown'
156  );
157 
158  foreach (get_loaded_extensions() as $extension) {
159  $reflection = new \ReflectionExtension($extension);
160  $entry = 'extension-' . strtolower($extension);
161 
162  if ('extension-standard' !== $entry &&
163  'extension-core' !== $entry) {
164  $entries = [];
165 
166  foreach ($reflection->getINIEntries() as $key => $value) {
167  $entries[substr($key, strpos($key, '.') + 1)] = $value;
168  }
169  } else {
170  $entries = $reflection->getINIEntries();
171  }
172 
173  $store(
174  $entry,
175  'version',
176  $reflection->getVersion() ?: 'unknown'
177  );
178  $store(
179  $entry,
180  $entries
181  );
182  }
183 
184  if (empty($sections) || in_array('all', $sections)) {
185  $ini = $this->arrayToIni($diagnostic);
186  } else {
187  $handle = [];
188 
189  foreach ($sections as $section) {
190  if (false === array_key_exists($section, $diagnostic)) {
191  return 1;
192  }
193 
194  $handle[$section] = $diagnostic[$section];
195  }
196 
197  $ini = $this->arrayToIni($handle);
198  }
199 
200  echo $ini, "\n";
201 
202  if (null !== $mail) {
203  $subject = 'Diagnostic from ' . get_current_user();
204 
205  return mail($mail, $subject, $ini) ? 0 : 1;
206  }
207 
208  return;
209  }
static getInstance()
Definition: Core.php:193
getOption(&$optionValue, $short=null)
Definition: Kit.php:104
resolveOptionAmbiguity(Array $solutions)
Definition: Kit.php:190
getParameters()
Definition: Core.php:266

Here is the call graph for this function:

Hoa\Devtools\Bin\Diagnostic::usage ( )

The command usage.

Returns
int

Definition at line 216 of file Diagnostic.php.

217  {
218  echo
219  'Usage : devtools:diagnostic <options>', "\n",
220  'Options :', "\n",
221  $this->makeUsageOptionsList([
222  's' => 'Sections (comma separated) to display, among:' . "\n" .
223  ' • all;' . "\n" .
224  ' • version;' . "\n" .
225  ' • system;' . "\n" .
226  ' • bin;' . "\n" .
227  ' • extension-<name in lowercase> (see `php -m`).',
228  'm' => 'Email address where to send the diagnostic.',
229  'help' => 'This help.'
230  ]), "\n";
231 
232  return;
233  }
makeUsageOptionsList(Array $definitions=[])
Definition: Kit.php:149

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

Hoa\Devtools\Bin\Diagnostic::$options
protected
Initial value:

Definition at line 57 of file Diagnostic.php.


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