-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.php
118 lines (87 loc) · 3.96 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Illuminate\Database\Capsule\Manager;
use Symfony\Component\Dotenv\Dotenv;
(new Dotenv())->load(__DIR__.'/.env');
// Symfony dependency injection IOC container
//$containerBuilder = new ContainerBuilder();
$containerBuilder = new \fantomx1\PhanconX1\SymfonyContainerBuilderAdapter();
$loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__));
$result = $loader->load('services.yaml');
# to have env vars parsed
$containerBuilder->compile(true);
// load laravel dataaccess layer , database manager, from symfony DI, lazy loading by default
$dbManager = $containerBuilder->get('manager');
//print_r($containerBuilder->get('manager'));
// $results = Manager::select(Manager::raw('select * from users'));
##-------------------------------------
$entityManager = $containerBuilder->get('entityManager');
// workaround for Doctrine enum type
$conn = $entityManager->getConnection();
$conn->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
use Symfony\Bridge\Twig\Extension\FormExtension;
use Symfony\Bridge\Twig\Form\TwigRendererEngine;
use Symfony\Component\Form\FormRenderer;
use Symfony\Component\Form\Forms;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
use Twig\RuntimeLoader\FactoryRuntimeLoader;
use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
//use Symfony\Component\Form\Forms;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Security\Csrf\CsrfTokenManager;
use Symfony\Component\Security\Csrf\TokenGenerator\UriSafeTokenGenerator;
use Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage;
// creates a Session object from the HttpFoundation component
$session = new Session();
$csrfGenerator = new UriSafeTokenGenerator();
$csrfStorage = new SessionTokenStorage($session);
$csrfManager = new CsrfTokenManager($csrfGenerator, $csrfStorage);
$formFactory = Forms::createFormFactoryBuilder()
// ...
->addExtension(new CsrfExtension($csrfManager))
->getFormFactory();
// the Twig file that holds all the default markup for rendering forms
// this file comes with TwigBridge
$defaultFormTheme = 'form_div_layout.html.twig';
$vendorDirectory = realpath(__DIR__.'/../vendor');
// the path to TwigBridge library so Twig can locate the
// form_div_layout.html.twig file
$appVariableReflection = new \ReflectionClass('\Symfony\Bridge\Twig\AppVariable');
$vendorTwigBridgeDirectory = dirname($appVariableReflection->getFileName());
// the path to your other templates
$viewsDirectory = realpath(__DIR__.'/views');
$twig = new Environment(new FilesystemLoader([
$viewsDirectory,
$vendorTwigBridgeDirectory.'/Resources/views/Form',
]));
$formEngine = new TwigRendererEngine([$defaultFormTheme], $twig);
$twig->addRuntimeLoader(new FactoryRuntimeLoader([
FormRenderer::class => function () use ($formEngine, $csrfManager) {
return new FormRenderer($formEngine, $csrfManager);
},
]));
// ... (see the previous CSRF Protection section for more information)
// adds the FormExtension to Twig
$twig->addExtension(new FormExtension());
use Symfony\Bridge\Twig\Extension\TranslationExtension;
//use Symfony\Component\Form\Forms;
use Symfony\Component\Translation\Loader\XliffFileLoader;
use Symfony\Component\Translation\Translator;
// creates the Translator
$translator = new Translator('en');
// somehow load some translations into it
//$translator->addLoader('xlf', new XliffFileLoader());
//$translator->addResource(
// 'xlf',
// __DIR__.'/path/to/translations/messages.en.xlf',
// 'en'
//);
// adds the TranslationExtension (it gives us trans filter)
$twig->addExtension(new TranslationExtension($translator));
//$containerBuilder->register('adas',$ads);
$containerBuilder->set('twig' , $twig);
// require not require once is not supposed to be called encapsulated inside something else
#require "doctrineBootstrap.php";