forked from Ahmard/reactphp-live-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact.php
84 lines (65 loc) · 2.28 KB
/
react.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env php
<?php
require 'vendor/autoload.php';
use App\Providers\EventServiceProvider;
use Dotenv\Dotenv;
use React\EventLoop\Factory;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Contracts\EventDispatcher\Event;
$commandNamespace = 'App\\Console\\Commands\\';
$seedNamespace = 'Database\\Seeds\\';
$_ENV['ARGV'] = $argv;
/**
* Handles exception thrown in the application
* @param Throwable $exception
*/
function handleApplicationException(Throwable $exception) {
//Save error log
$filename = __DIR__ . '/storage/logs/error-' . date('d_m_Y-H_i_s') . '.log';
file_put_contents($filename, $exception);
//Display to console
echo("\n[*] Error: {$exception->getMessage()} => {$exception->getFile()} @ Line {$exception->getLine()}\n\t --> Log File: {$filename}\n");
}
//Handle all exceptions thrown
set_exception_handler('handleApplicationException');
setLoop(Factory::create());
//Load environment variables
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
//Instantiate console application
$app = new Application($_ENV['APP_NAME'], $_ENV['APP_VERSION']);
$symfonyEventDispatcher = new EventDispatcher();
//Load helpers
require 'app/Core/Helpers/generalHelperFunctions.php';
require 'app/Core/Helpers/socketHelperFunctions.php';
require 'app/Core/Helpers/httpHelperFunctions.php';
//Load all commands
$dirIterator = new DirectoryIterator(app_path('Console/Commands'));
foreach ($dirIterator as $item){
if($item->isFile()){
$className = $commandNamespace. substr($item->getFilename(), 0, -4);
$command = new $className;
$app->add($command);
}
}
//Load all seeders
$dirIterator = new DirectoryIterator(root_path('database/Seeds'));
foreach ($dirIterator as $item){
if($item->isFile()){
$_ENV['seeds'][] = $seedNamespace. substr($item->getFilename(), 0, -4);
}
}
$symfonyEventDispatcher->addListener(ConsoleEvents::COMMAND, function (Event $event){
//var_dump($event->getCommand()->getName());
});
$app->setDispatcher($symfonyEventDispatcher);
//Load event listeners
EventServiceProvider::init()->boot();
//Run console application
try {
$app->run();
} catch (Exception $e) {
handleApplicationException($e);
}