-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
94 lines (77 loc) · 2.27 KB
/
bootstrap.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
85
86
87
88
89
90
91
92
93
94
<?php
use App\Client;
use App\Clock;
use App\Message\Envelope;
use App\Provider\Market\TwseHolidayScheduleProvider;
use App\Type\Value;
use Illuminate\Cache\CacheManager;
use Illuminate\Container\Container;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Facade;
use Longman\TelegramBot\Request as TelegramRequest;
use Longman\TelegramBot\Telegram;
require __DIR__ . '/vendor/autoload.php';
$dotenv = Dotenv\Dotenv::create(__DIR__);
$dotenv->load();
$container = Container::getInstance();
$container->singleton(Clock::class, function () {
// CarbonImmutable::setTestNow('2021-06-10 16:00 +08:00');
return (new Clock)->touchNow();
});
/**
* Telegram Client bindings
*/
$container->when(Telegram::class)
->needs('$api_key')
->give(env('TELEGRAM_BOT_TOKEN'));
$container->when(Envelope::class)
->needs('$receiver')
->give(env('TELEGRAM_CHAT_ID'));
$container->singleton(TelegramRequest::class, function () use ($container) {
$request = new TelegramRequest;
$request->initialize($container->get(Telegram::class));
return $request;;
});
/**
* Application config bindings.
*/
$container->singleton('config', function () {
return [
'cache.default' => 'files',
'cache.stores.files' => [
'driver' => 'file',
'path' => __DIR__ . '/cache',
],
];
});
$container->singleton('files', Filesystem::class);
$container->instance('cache', new CacheManager($container));
Facade::setFacadeApplication($container);
/**
* Ensure Clock::$tradingHolidays is exists.
*/
$clock = $container->get(Clock::class);
$holidayKey = "twse:holiday:{$clock->getNow()->year}";
$holidays = Cache::remember($holidayKey, $clock->getNow()->addWeeks(), function () use ($container) {
$schedules = $container->call(Client::class . "@get", [new TwseHolidayScheduleProvider]);
return collect($schedules)->reject(function ($schedule) {
return $schedule->isTradingDay();
})->transform(function ($schedule) {
return $schedule->getDate();
})->values()->all();
});
$clock->setTradingHolidays($holidays);
/**
* Custom helpers.
*/
/**
* Create a Value instance.
*
* @param int|float $value
* @return Value
*/
function v($value)
{
return Value::make($value);
}