OrmBootstrapper::getBindings()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Contact\Bootstrappers\Orm;
6
7
use AbterPhp\Admin\Bootstrappers\Orm\OrmBootstrapper as AbterAdminOrmBootstrapper;
8
use AbterPhp\Contact\Domain\Entities\Form;
9
use AbterPhp\Contact\Orm\DataMappers\FormSqlDataMapper;
10
use AbterPhp\Contact\Orm\FormRepo;
11
use Opulence\Ioc\IContainer;
12
use Opulence\Ioc\IocException;
13
use Opulence\Orm\IUnitOfWork;
14
use RuntimeException;
15
16
class OrmBootstrapper extends AbterAdminOrmBootstrapper
17
{
18
    /** @var array */
19
    protected $repoMappers = [
20
        FormRepo::class => [FormSqlDataMapper::class, Form::class],
21
    ];
22
23
    /**
24
     * @inheritdoc
25
     */
26
    public function getBindings(): array
27
    {
28
        return array_keys($this->repoMappers);
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function registerBindings(IContainer $container)
35
    {
36
        try {
37
            $unitOfWork = $container->resolve(IUnitOfWork::class);
38
            $this->bindRepositories($container, $unitOfWork);
39
        } catch (IocException $ex) {
40
            $namespace = explode('\\', __NAMESPACE__)[0];
41
            throw new RuntimeException("Failed to register $namespace bindings", 0, $ex);
42
        }
43
    }
44
}
45