-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeBundle.php
More file actions
70 lines (60 loc) · 2.18 KB
/
PrimeBundle.php
File metadata and controls
70 lines (60 loc) · 2.18 KB
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
<?php
namespace Bdf\PrimeBundle;
use Bdf\Prime\Locatorizable;
use Bdf\Prime\MongoDB\Collection\MongoCollectionLocator;
use Bdf\Prime\MongoDB\Mongo;
use Bdf\Prime\ServiceLocator;
use Bdf\PrimeBundle\DependencyInjection\Compiler\IgnorePrimeAnnotationsPass;
use Bdf\PrimeBundle\DependencyInjection\Compiler\PrimeConnectionFactoryPass;
use Bdf\PrimeBundle\DependencyInjection\Compiler\PrimeMiddlewarePass;
use Bdf\PrimeBundle\DependencyInjection\Compiler\RegisterClockPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
/**
* PrimeBundle.
*
* @author Seb
*/
class PrimeBundle extends Bundle
{
public function boot(): void
{
if ($this->container->getParameter('prime.locatorizable')) {
Locatorizable::configure(function () {
return $this->container->get('prime');
});
if (class_exists(Mongo::class)) {
Mongo::configure(function () {
return $this->container->get(MongoCollectionLocator::class);
});
}
}
}
public function build(ContainerBuilder $container): void
{
$container->addCompilerPass(new PrimeConnectionFactoryPass());
$container->addCompilerPass(new IgnorePrimeAnnotationsPass());
$container->addCompilerPass(new PrimeMiddlewarePass());
$container->addCompilerPass(new RegisterClockPass());
}
public function shutdown(): void
{
if ($this->container->initialized('prime')) {
/** @var ServiceLocator $prime */
$prime = $this->container->get('prime');
// Clear circle references
$prime->clearRepositories();
// Close all loaded connections
foreach ($prime->connections() as $connection) {
$connection->close();
}
}
// Always unconfigure locator, because it's configured even if prime is not initialized
if ($this->container->getParameter('prime.locatorizable')) {
Locatorizable::configure(null);
if (class_exists(Mongo::class)) {
Mongo::configure(null);
}
}
}
}