1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\Files\Bootstrappers\Orm; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Admin\Bootstrappers\Orm\OrmBootstrapper as AbterAdminOrmBootstrapper; |
8
|
|
|
use AbterPhp\Files\Domain\Entities\File; |
9
|
|
|
use AbterPhp\Files\Domain\Entities\FileCategory; |
10
|
|
|
use AbterPhp\Files\Domain\Entities\FileDownload; |
11
|
|
|
use AbterPhp\Files\Orm\DataMappers\FileCategorySqlDataMapper; |
12
|
|
|
use AbterPhp\Files\Orm\DataMappers\FileDownloadSqlDataMapper; |
13
|
|
|
use AbterPhp\Files\Orm\DataMappers\FileSqlDataMapper; |
14
|
|
|
use AbterPhp\Files\Orm\FileCategoryRepo; |
15
|
|
|
use AbterPhp\Files\Orm\FileDownloadRepo; |
16
|
|
|
use AbterPhp\Files\Orm\FileRepo; |
17
|
|
|
use Opulence\Ioc\IContainer; |
18
|
|
|
use Opulence\Ioc\IocException; |
19
|
|
|
use Opulence\Orm\IUnitOfWork; |
20
|
|
|
use RuntimeException; |
21
|
|
|
|
22
|
|
|
class OrmBootstrapper extends AbterAdminOrmBootstrapper |
23
|
|
|
{ |
24
|
|
|
/** @var array */ |
25
|
|
|
protected $repoMappers = [ |
26
|
|
|
FileDownloadRepo::class => [FileDownloadSqlDataMapper::class, FileDownload::class], |
27
|
|
|
FileCategoryRepo::class => [FileCategorySqlDataMapper::class, FileCategory::class], |
28
|
|
|
FileRepo::class => [FileSqlDataMapper::class, File::class], |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @inheritdoc |
33
|
|
|
*/ |
34
|
|
|
public function getBindings(): array |
35
|
|
|
{ |
36
|
|
|
return array_keys($this->repoMappers); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @inheritdoc |
41
|
|
|
*/ |
42
|
|
|
public function registerBindings(IContainer $container) |
43
|
|
|
{ |
44
|
|
|
try { |
45
|
|
|
$unitOfWork = $container->resolve(IUnitOfWork::class); |
46
|
|
|
$this->bindRepositories($container, $unitOfWork); |
47
|
|
|
} catch (IocException $ex) { |
48
|
|
|
$namespace = explode('\\', __NAMESPACE__)[0]; |
49
|
|
|
throw new RuntimeException("Failed to register $namespace bindings", 0, $ex); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|