-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap.php
150 lines (129 loc) · 5.37 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
require_once 'vendor/autoload.php';
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\PsrCachedReader;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\Events;
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\EntityManager;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use Gedmo\Blameable\BlameableListener;
use Gedmo\Sluggable\SluggableListener;
use Gedmo\Timestampable\TimestampableListener;
use Listeners\ArsavListener;
use mkw\store;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\ApcuAdapter;
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
use Doctrine\Common\EventManager;
use Listeners\BizonylatfejListener;
use Listeners\BankbizonylatfejListener;
use Listeners\BizonylattetelListener;
use Listeners\JogareszvetelListener;
use Listeners\KuponListener;
use Listeners\PartnerListener;
use Listeners\PenztarbizonylatfejListener;
use Listeners\RendezvenyListener;
use Listeners\MPTNGYSzakmaianyagListener;
use Doctrine\DBAL\Event\Listeners;
$ini = parse_ini_file('config.ini');
$setini = parse_ini_file('setup.ini');
store::setConfig($ini);
store::setSetup($setini);
$config = new Configuration();
if (array_key_exists('cache', $ini)) {
switch ($ini['cache']) {
case 'apc':
$metacache = new ApcuAdapter('mkwmetadata');
$querycache = new ApcuAdapter('mkwquery');
break;
case 'file':
$metacache = new PhpFilesAdapter('mkwmetadata');
$querycache = new PhpFilesAdapter('mkwquery');
break;
default:
$metacache = new ArrayAdapter();
$querycache = new ArrayAdapter();
break;
}
} else {
$metacache = new ArrayAdapter();
$querycache = new ArrayAdapter();
}
$config->setMetadataCache($metacache);
$config->setQueryCache($querycache);
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
if ($ini['developer']) {
$config->setAutoGenerateProxyClasses(true);
} else {
$config->setAutoGenerateProxyClasses(false);
}
AnnotationRegistry::registerFile('vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
$annotationReader = new AnnotationReader;
$cachedAnnotationReader = new PsrCachedReader(
$annotationReader,
$metacache
);
$driverchain = new MappingDriverChain();
// Gedmo DoctrineExtensions annotations
Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM(
$driverchain,
$cachedAnnotationReader
);
// Doctrine annotations
$defaultDriverImpl = ORMSetup::createDefaultAnnotationDriver([__DIR__ . '/Entities']);
$driverchain->addDriver($defaultDriverImpl, 'Entities');
$config->setMetadataDriverImpl($driverchain);
if ($ini['sqllog']) {
$config->setSQLLogger(new \mkwhelpers\FileSQLLogger('sql.log'));
}
$config->addCustomStringFunction('YEAR', 'mkwhelpers\year');
$config->addCustomStringFunction('NOW', 'mkwhelpers\now');
$config->addCustomStringFunction('IF', 'mkwhelpers\ifelse');
$config->addCustomStringFunction('RAND', 'mkwhelpers\rand');
$config->addCustomStringFunction('CURDATE', 'mkwhelpers\curdate');
$evm = new EventManager();
// new MysqlSessionInit('UTF8','utf8_hungarian_ci')
$evm->addEventSubscriber(new Listeners\SQLSessionInit('SET NAMES UTF8 COLLATE utf8_hungarian_ci'));
$sluggableListener = new SluggableListener;
$sluggableListener->setAnnotationReader($cachedAnnotationReader);
//$sluggableListener->setUrlizer();
$evm->addEventSubscriber($sluggableListener);
$timestampableListener = new TimestampableListener;
$timestampableListener->setAnnotationReader($cachedAnnotationReader);
$evm->addEventSubscriber($timestampableListener);
$blameableListener = new BlameableListener();
$blameableListener->setAnnotationReader($cachedAnnotationReader);
store::setBlameableListener($blameableListener);
$evm->addEventSubscriber($blameableListener);
if (mkw\store::isMultilang()) {
$translatableListener = new Gedmo\Translatable\TranslatableListener();
$translatableListener->setAnnotationReader($cachedAnnotationReader);
$translatableListener->setDefaultLocale('hu_hu');
$translatableListener->setTranslatableLocale('hu_hu');
$translatableListener->setTranslationFallback(true);
$evm->addEventSubscriber($translatableListener);
mkw\store::setTranslationListener($translatableListener);
}
$evm->addEventListener(['onFlush', 'prePersist'], new BizonylatfejListener());
$evm->addEventListener(['onFlush', 'prePersist'], new BankbizonylatfejListener());
$evm->addEventListener(['onFlush', 'prePersist'], new PenztarbizonylatfejListener());
$evm->addEventListener([Events::onFlush, Events::postFlush], new BizonylattetelListener());
$evm->addEventListener(['prePersist'], new KuponListener());
$evm->addEventListener(['prePersist'], new RendezvenyListener());
$evm->addEventListener(['onFlush'], new JogareszvetelListener());
$evm->addEventListener(['onFlush'], new PartnerListener());
$evm->addEventListener(['onFlush'], new MPTNGYSzakmaianyagListener());
$evm->addEventListener(['onFlush'], new ArsavListener());
$connectionOptions = [
'driver' => $ini['db.driver'],
'user' => $ini['db.username'],
'password' => $ini['db.password'],
'host' => $ini['db.host'],
'dbname' => $ini['db.dbname'],
'port' => $ini['db.port']
];
$entityManager = EntityManager::create($connectionOptions, $config, $evm);
mkw\store::setEm($entityManager);