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 \RoleUpdate ;
12- use HMS \Entities \Banking \Account ;
13- use HMS \Repositories \LinkRepository ;
14- use HMS \Repositories \MetaRepository ;
15- use HMS \Repositories \RoleRepository ;
16- use HMS \Repositories \UserRepository ;
17- use HMS \Repositories \InviteRepository ;
18- use HMS \Repositories \ProfileRepository ;
195use Illuminate \Support \ServiceProvider ;
206use HMS \Repositories \PermissionRepository ;
21- use HMS \Repositories \RoleUpdateRepository ;
22- use HMS \Repositories \Banking \AccountRepository ;
237use LaravelDoctrine \ACL \Permissions \Permission ;
24- use HMS \Repositories \Doctrine \DoctrineLinkRepository ;
25- use HMS \Repositories \Doctrine \DoctrineMetaRepository ;
26- use HMS \Repositories \Doctrine \DoctrineRoleRepository ;
27- use HMS \Repositories \Doctrine \DoctrineUserRepository ;
28- use HMS \Repositories \Doctrine \DoctrineInviteRepository ;
29- use HMS \Repositories \Doctrine \DoctrineProfileRepository ;
308use HMS \Repositories \Doctrine \DoctrinePermissionRepository ;
31- use HMS \Repositories \Doctrine \DoctrineRoleUpdateRepository ;
32- use HMS \Repositories \Banking \Doctrine \DoctrineAccountRepository ;
339
3410class RepositoryServiceProvider extends ServiceProvider
3511{
@@ -50,40 +26,23 @@ public function boot()
5026 */
5127 public function register ()
5228 {
53- $ this ->app ->singleton (LinkRepository::class, function ($ app ) {
54- return new DoctrineLinkRepository ($ app ['em ' ], $ app ['em ' ]->getClassMetaData (Link::class));
55- });
56-
57- $ this ->app ->singleton (MetaRepository::class, function ($ app ) {
58- return new DoctrineMetaRepository ($ app ['em ' ], $ app ['em ' ]->getClassMetaData (Meta::class));
59- });
60-
61- $ this ->app ->singleton (InviteRepository::class, function ($ app ) {
62- return new DoctrineInviteRepository ($ app ['em ' ], $ app ['em ' ]->getClassMetaData (Invite::class));
63- });
64-
65- $ this ->app ->singleton (RoleRepository::class, function ($ app ) {
66- return new DoctrineRoleRepository ($ app ['em ' ], $ app ['em ' ]->getClassMetaData (Role::class));
67- });
68-
69- $ this ->app ->singleton (UserRepository::class, function ($ app ) {
70- return new DoctrineUserRepository ($ app ['em ' ], $ app ['em ' ]->getClassMetaData (User::class));
71- });
72-
73- $ this ->app ->singleton (ProfileRepository::class, function ($ app ) {
74- return new DoctrineProfileRepository ($ app ['em ' ], $ app ['em ' ]->getClassMetaData (Profile::class));
75- });
76-
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
7744 $ this ->app ->singleton (PermissionRepository::class, function ($ app ) {
7845 return new DoctrinePermissionRepository ($ app ['em ' ], $ app ['em ' ]->getClassMetaData (Permission::class));
7946 });
80-
81- $ this ->app ->singleton (AccountRepository::class, function ($ app ) {
82- return new DoctrineAccountRepository ($ app ['em ' ], $ app ['em ' ]->getClassMetaData (Account::class));
83- });
84-
85- $ this ->app ->singleton (RoleUpdateRepository::class, function ($ app ) {
86- return new DoctrineRoleUpdateRepository ($ app ['em ' ], $ app ['em ' ]->getClassMetaData (RoleUpdate::class));
87- });
8847 }
8948}
0 commit comments