22
33namespace App \Providers ;
44
5- use HMS \Entities \Link ;
6- use HMS \Entities \Meta ;
7- use HMS \Entities \Role ;
8- use HMS \Entities \User ;
9- use HMS \Entities \Invite ;
10- use HMS \Entities \Profile ;
11- use HMS \Entities \Banking \Account ;
12- use HMS \Repositories \LinkRepository ;
13- use HMS \Repositories \MetaRepository ;
14- use HMS \Repositories \RoleRepository ;
15- use HMS \Repositories \UserRepository ;
16- use HMS \Repositories \InviteRepository ;
17- use HMS \Repositories \ProfileRepository ;
185use Illuminate \Support \ServiceProvider ;
196use HMS \Repositories \PermissionRepository ;
20- use HMS \Repositories \Banking \AccountRepository ;
217use LaravelDoctrine \ACL \Permissions \Permission ;
22- use HMS \Repositories \Doctrine \DoctrineLinkRepository ;
23- use HMS \Repositories \Doctrine \DoctrineMetaRepository ;
24- use HMS \Repositories \Doctrine \DoctrineRoleRepository ;
25- use HMS \Repositories \Doctrine \DoctrineUserRepository ;
26- use HMS \Repositories \Doctrine \DoctrineInviteRepository ;
27- use HMS \Repositories \Doctrine \DoctrineProfileRepository ;
288use HMS \Repositories \Doctrine \DoctrinePermissionRepository ;
29- use HMS \Repositories \Banking \Doctrine \DoctrineAccountRepository ;
309
3110class RepositoryServiceProvider extends ServiceProvider
3211{
@@ -47,36 +26,23 @@ public function boot()
4726 */
4827 public function register ()
4928 {
50- $ this ->app ->singleton (LinkRepository::class, function ($ app ) {
51- return new DoctrineLinkRepository ($ app ['em ' ], $ app ['em ' ]->getClassMetaData (Link::class));
52- });
53-
54- $ this ->app ->singleton (MetaRepository::class, function ($ app ) {
55- return new DoctrineMetaRepository ($ app ['em ' ], $ app ['em ' ]->getClassMetaData (Meta::class));
56- });
57-
58- $ this ->app ->singleton (InviteRepository::class, function ($ app ) {
59- return new DoctrineInviteRepository ($ app ['em ' ], $ app ['em ' ]->getClassMetaData (Invite::class));
60- });
61-
62- $ this ->app ->singleton (RoleRepository::class, function ($ app ) {
63- return new DoctrineRoleRepository ($ app ['em ' ], $ app ['em ' ]->getClassMetaData (Role::class));
64- });
65-
66- $ this ->app ->singleton (UserRepository::class, function ($ app ) {
67- return new DoctrineUserRepository ($ app ['em ' ], $ app ['em ' ]->getClassMetaData (User::class));
68- });
69-
70- $ this ->app ->singleton (ProfileRepository::class, function ($ app ) {
71- return new DoctrineProfileRepository ($ app ['em ' ], $ app ['em ' ]->getClassMetaData (Profile::class));
72- });
73-
29+ foreach (config ('repositories.repositories ' ) as $ repository ) {
30+ $ entity = config ('repositories.entity_namespace ' ) . '\\' . $ repository ;
31+ $ interface = config ('repositories.repositoriy_namespace ' ) . '\\' . $ repository . 'Repository ' ;
32+ $ implmentation = config ('repositories.repositoriy_namespace ' ) . '\\' .
33+ (strpos ($ repository , '\\' ) ? explode ('\\' , $ repository )[0 ] . '\\' : '' ) .
34+ 'Doctrine \\Doctrine ' .
35+ (strpos ($ repository , '\\' ) ? explode ('\\' , $ repository )[1 ] : $ repository ) .
36+ 'Repository ' ;
37+
38+ $ this ->app ->singleton ($ interface , function ($ app ) use ($ implmentation , $ entity ) {
39+ return new $ implmentation ($ app ['em ' ], $ app ['em ' ]->getClassMetaData ($ entity ));
40+ });
41+ }
42+
43+ // Special case so do this one by hand
7444 $ this ->app ->singleton (PermissionRepository::class, function ($ app ) {
7545 return new DoctrinePermissionRepository ($ app ['em ' ], $ app ['em ' ]->getClassMetaData (Permission::class));
7646 });
77-
78- $ this ->app ->singleton (AccountRepository::class, function ($ app ) {
79- return new DoctrineAccountRepository ($ app ['em ' ], $ app ['em ' ]->getClassMetaData (Account::class));
80- });
8147 }
8248}
0 commit comments