|
1
|
|
|
<?php declare(strict_types = 1); |
|
2
|
|
|
|
|
3
|
|
|
use Aerys\Host; |
|
4
|
|
|
use Auryn\Injector; |
|
5
|
|
|
use ekinhbayar\GitAmp\Github\Credentials; |
|
6
|
|
|
use ekinhbayar\GitAmp\Http\Origin; |
|
7
|
|
|
use ekinhbayar\GitAmp\Log\Request as RequestLogger; |
|
8
|
|
|
use ekinhbayar\GitAmp\Storage\Counter; |
|
9
|
|
|
use ekinhbayar\GitAmp\Storage\NativeCounter; |
|
10
|
|
|
use ekinhbayar\GitAmp\Websocket\Handler; |
|
11
|
|
|
use Monolog\Logger; |
|
12
|
|
|
use Monolog\Handler\StreamHandler; |
|
13
|
|
|
use Psr\Log\LoggerInterface; |
|
14
|
|
|
use function Aerys\root; |
|
15
|
|
|
use function Aerys\router; |
|
16
|
|
|
use function Aerys\websocket; |
|
17
|
|
|
|
|
18
|
|
|
$configuration = require_once __DIR__ . '/config.php'; |
|
19
|
|
|
|
|
20
|
|
|
$injector = new Injector; |
|
21
|
|
|
|
|
22
|
|
|
$injector->alias(Counter::class, NativeCounter::class); |
|
23
|
|
|
|
|
24
|
|
|
$injector->alias(Credentials::class, get_class($configuration['github'])); |
|
25
|
|
|
|
|
26
|
|
|
$injector->share($configuration['github']); |
|
27
|
|
|
|
|
28
|
|
|
$injector->alias(LoggerInterface::class, Logger::class); |
|
29
|
|
|
$injector->share(Logger::class); |
|
30
|
|
|
|
|
31
|
|
|
$injector->delegate(Logger::class, function() use ($configuration) { |
|
32
|
|
|
$logger = new Logger('gitamp'); |
|
33
|
|
|
|
|
34
|
|
|
$logger->pushHandler(new StreamHandler('php://stdout', $configuration['logLevel'])); |
|
35
|
|
|
|
|
36
|
|
|
return $logger; |
|
37
|
|
|
}); |
|
38
|
|
|
|
|
39
|
|
|
$injector->define(Handler::class, [ |
|
40
|
|
|
':origin' => (new Origin($configuration))->get(), |
|
41
|
|
|
]); |
|
42
|
|
|
|
|
43
|
|
|
$injector->define(Client::class, [ |
|
44
|
|
|
':uri' => $configuration['redis'] |
|
45
|
|
|
]); |
|
46
|
|
|
|
|
47
|
|
|
$websocket = $injector->make(Handler::class); |
|
48
|
|
|
|
|
49
|
|
|
$router = router()->get('/ws', websocket($websocket)); |
|
50
|
|
|
|
|
51
|
|
|
$requestLogger = new RequestLogger(); |
|
52
|
|
|
|
|
53
|
|
|
if (isset($configuration['ssl'])) { |
|
54
|
|
|
(new Host()) |
|
55
|
|
|
->name($configuration['hostname']) |
|
56
|
|
|
->expose($configuration['expose']['ip'], $configuration['expose']['port']) |
|
57
|
|
|
->use($requestLogger) |
|
58
|
|
|
->redirect('https://' . $configuration['hostname']) |
|
59
|
|
|
; |
|
60
|
|
|
|
|
61
|
|
|
(new Host()) |
|
62
|
|
|
->name($configuration['hostname']) |
|
63
|
|
|
->expose($configuration['ssl']['ip'], $configuration['ssl']['port']) |
|
64
|
|
|
->encrypt($configuration['ssl']['certificate'], $configuration['ssl']['key']) |
|
65
|
|
|
->use($requestLogger) |
|
66
|
|
|
->use($router) |
|
67
|
|
|
->use(root(__DIR__ . '/public')) |
|
|
|
|
|
|
68
|
|
|
; |
|
69
|
|
|
} else { |
|
70
|
|
|
(new Host()) |
|
71
|
|
|
->name($configuration['hostname']) |
|
72
|
|
|
->expose($configuration['expose']['ip'], $configuration['expose']['port']) |
|
73
|
|
|
->use($requestLogger) |
|
74
|
|
|
->use($router) |
|
75
|
|
|
->use(root(__DIR__ . '/public')) |
|
|
|
|
|
|
76
|
|
|
; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$logger = $injector->make(LoggerInterface::class); |
|
80
|
|
|
|
|
81
|
|
|
\Amp\onError(function(Throwable $e) use ($logger) { |
|
82
|
|
|
$logger->emergency('GitAmp blew up', ['exception' => $e]); |
|
83
|
|
|
}); |
|
84
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: