Hoa central
Hoa.php
Go to the documentation of this file.
1 <?php
2 
37 use Hoa\Console;
38 use Hoa\Core;
39 use Hoa\Dispatcher;
40 use Hoa\Router;
41 
45 if (!defined('HOA')) {
46  $composer = [
47  dirname(__DIR__) . DIRECTORY_SEPARATOR .
48  'vendor' . DIRECTORY_SEPARATOR .
49  'autoload.php',
50  dirname(__DIR__) . DIRECTORY_SEPARATOR .
51  '..' . DIRECTORY_SEPARATOR .
52  '..' . DIRECTORY_SEPARATOR .
53  'autoload.php',
54  dirname(__DIR__) . DIRECTORY_SEPARATOR .
55  '..' . DIRECTORY_SEPARATOR .
56  '..' . DIRECTORY_SEPARATOR .
57  '..' . DIRECTORY_SEPARATOR .
58  'autoload.php'
59  ];
60 
61  foreach ($composer as $path) {
62  if (file_exists($path)) {
63  require_once $path;
64 
65  break;
66  }
67  }
68 
69  if (!defined('HOA')) {
70  require_once
71  dirname(__DIR__) . DIRECTORY_SEPARATOR .
72  '..' . DIRECTORY_SEPARATOR .
73  'Core' . DIRECTORY_SEPARATOR .
74  'Core.php';
75  }
76 }
77 
80 
84 try {
85  $router = new Router\Cli();
86  $router->get(
87  'g',
88  '(?:(?<vendor>\w+)\s+)?(?<library>\w+)?(?::(?<command>\w+))?(?<_tail>.*?)',
89  'main',
90  'main',
91  [
92  'vendor' => 'hoa',
93  'library' => 'core',
94  'command' => 'welcome'
95  ]
96  );
97 
98  $dispatcher = new Dispatcher\ClassMethod([
99  'synchronous.call'
100  => '(:%variables.vendor:lU:)\(:%variables.library:lU:)\Bin\(:%variables.command:lU:)',
101  'synchronous.able'
102  => 'main'
103  ]);
104  $dispatcher->setKitName('Hoa\Console\Dispatcher\Kit');
105  exit((int) $dispatcher->dispatch($router));
106 } catch (Core\Exception $e) {
107  $message = $e->raise(true);
108  $code = 1;
109 } catch (\Exception $e) {
110  $message = $e->getMessage();
111  $code = 2;
112 }
113 
114 ob_start();
115 
116 Console\Cursor::colorize('foreground(white) background(red)');
117 echo $message, "\n";
118 Console\Cursor::colorize('normal');
119 $content = ob_get_contents();
120 
121 ob_end_clean();
122 
123 file_put_contents('php://stderr', $content);
124 exit($code);
static enableErrorHandler($enable=true)
Definition: Core.php:384
$composer
$dispatcher
Definition: Hoa.php:98
static enableExceptionHandler($enable=true)
Definition: Core.php:367
$content
Definition: Hoa.php:119