generated from ghostwriter/wip
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.php
94 lines (79 loc) · 3.05 KB
/
generate.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
declare(strict_types=1);
namespace Ghostwriter\TnTherapists;
use ErrorException;
use Ghostwriter\TnTherapists\Model\Therapist;
use Illuminate\Container\Container;
use Illuminate\Database\Capsule\Manager as Database;
use Illuminate\Events\Dispatcher;
use Illuminate\Filesystem\Filesystem;
use function collect;
use function dirname;
use function dump;
use function file_exists;
use function fwrite;
use function set_error_handler;
use function sprintf;
use function str_replace;
use const DIRECTORY_SEPARATOR;
use const PHP_EOL;
use const STDERR;
(static function (string $autoloader): void {
set_error_handler(static function (int $severity, string $message, string $file, int $line): never {
throw new ErrorException($message, 255, $severity, $file, $line);
});
if (! file_exists($autoloader)) {
fwrite(
STDERR,
sprintf('[ERROR]Cannot locate "%s"%s please run "composer install"%s', $autoloader, PHP_EOL, PHP_EOL)
);
exit;
}
require $autoloader;
$filesystem = new Filesystem();
$databasePath = './database.sqlite';
if ($filesystem->missing($databasePath)) {
$filesystem->put($databasePath, '');
}
$database = new Database();
$database->addConnection([
'driver' => 'sqlite',
'database' => 'database.sqlite',
'prefix' => '',
]);
$database->setEventDispatcher(new Dispatcher(new Container()));
$database->setAsGlobal();
$database->bootEloquent();
$tableTemplate = $filesystem->get('./table.html');
$filesystem->put(
'./README.md',
str_replace(
'{therapists}',
collect([
'> Collection of Black and African American Therapists in Nashville, TN and Therapists serving Black and African American communities.',
PHP_EOL,
'> Publicly available information collected to help promote Healing Ourselves and Healing Others. #BlackLivesMatter',
PHP_EOL,
])->merge(
Therapist::all()
->sortBy('title')
->collect()
->map(
static fn (Therapist $therapist): mixed => dump(sprintf(
$tableTemplate,
$therapist->getAttribute('subtitle'),
$therapist->getAttribute('hash'),
$therapist->getAttribute('image'),
$therapist->getAttribute('title'),
$therapist->getAttribute('statement'),
$therapist->getAttribute('offersOnlineTherapy'),
$therapist->getAttribute('acceptingAppointments'),
$therapist->getAttribute('location'),
$therapist->getAttribute('contact'),
))
)
)->join(PHP_EOL),
$filesystem->get('./README.md.tmp')
)
);
})(\implode(DIRECTORY_SEPARATOR,[__DIR__ , 'vendor','autoload.php']));