forked from izejuy/gemrffrff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.php
85 lines (76 loc) · 2.39 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
<?php
declare(strict_types=1);
/**
* @author Gem Chess Contributors <https://github.com/izejuy/gem-chess/graphs/contributors>.
* @link <https://github.com/izejuy/gem-chess> Source.
*/
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Templating\PhpEngine;
use Symfony\Component\Templating\TemplateNameParser;
use Symfony\Component\Templating\Loader\FilesystemLoader;
/**
* Render a template to client-side.
*
* @param string $template The template name.
* @param array $bindData The bind data for template.
*
* @return void Returns nothing.
*/
function render(string $template, array $bindData = []): void
{
$filesystemLoader = new FilesystemLoader(__DIR__ . '/lib/views/%name%');
$templating = new PhpEngine(new TemplateNameParser(), $filesystemLoader);
echo $templating->render($template, $bindData);
}
/**
* Redirect the user to a different internal page or external.
*
* @param string $location The location in which they will go.
*
* @return void Returns nothing.
*/
function redirect(string $location = '/'): void
{
if (!headers_sent()) {
header("Location: $location");
} else {
echo "<script type=\"text/javascript\">";
echo "window.location.href=\"$loction\";";
echo "</script>";
echo "<noscript>";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$location\">";
echo "</noscript>";
}
exit;
}
// Construct the container.
$containerBuilder = new ContainerBuilder();
// Database initialization.
$driverOptions = [
'persistent' => $_ENV['DB_PERSISTENT'],
'database' => $_ENV['DB_NAME'],
'username' => $_ENV['DB_USER'],
'password' => $_ENV['DB_PASS'],
'host' => $_ENV['DB_HOST'],
];
// Apply driver options.
$containerBuilder->setParameter('driver.options', $driverOptions);
$containerBuilder->register('driver', 'Cake\Database\Driver\Mysql')
->addArgument('%driver.options%');
// Create a stable connection.
$containerBuilder->register('connection', 'Cake\Database\Connection')->addArgument(['driver' => new Reference('driver')]);
// Finalize container.
$container = $containerBuilder;
/**
* Make the container accessible via app function.
*
* @param string $service The service to access.
*
* @return mixed The service container.
*/
function app(string $service)
{
global $container;
return $container->get($service);
}