Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 15 additions & 49 deletions app/Providers/RepositoryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,10 @@

namespace App\Providers;

use HMS\Entities\Link;
use HMS\Entities\Meta;
use HMS\Entities\Role;
use HMS\Entities\User;
use HMS\Entities\Invite;
use HMS\Entities\Profile;
use HMS\Entities\Banking\Account;
use HMS\Repositories\LinkRepository;
use HMS\Repositories\MetaRepository;
use HMS\Repositories\RoleRepository;
use HMS\Repositories\UserRepository;
use HMS\Repositories\InviteRepository;
use HMS\Repositories\ProfileRepository;
use Illuminate\Support\ServiceProvider;
use HMS\Repositories\PermissionRepository;
use HMS\Repositories\Banking\AccountRepository;
use LaravelDoctrine\ACL\Permissions\Permission;
use HMS\Repositories\Doctrine\DoctrineLinkRepository;
use HMS\Repositories\Doctrine\DoctrineMetaRepository;
use HMS\Repositories\Doctrine\DoctrineRoleRepository;
use HMS\Repositories\Doctrine\DoctrineUserRepository;
use HMS\Repositories\Doctrine\DoctrineInviteRepository;
use HMS\Repositories\Doctrine\DoctrineProfileRepository;
use HMS\Repositories\Doctrine\DoctrinePermissionRepository;
use HMS\Repositories\Banking\Doctrine\DoctrineAccountRepository;

class RepositoryServiceProvider extends ServiceProvider
{
Expand All @@ -47,36 +26,23 @@ public function boot()
*/
public function register()
{
$this->app->singleton(LinkRepository::class, function ($app) {
return new DoctrineLinkRepository($app['em'], $app['em']->getClassMetaData(Link::class));
});

$this->app->singleton(MetaRepository::class, function ($app) {
return new DoctrineMetaRepository($app['em'], $app['em']->getClassMetaData(Meta::class));
});

$this->app->singleton(InviteRepository::class, function ($app) {
return new DoctrineInviteRepository($app['em'], $app['em']->getClassMetaData(Invite::class));
});

$this->app->singleton(RoleRepository::class, function ($app) {
return new DoctrineRoleRepository($app['em'], $app['em']->getClassMetaData(Role::class));
});

$this->app->singleton(UserRepository::class, function ($app) {
return new DoctrineUserRepository($app['em'], $app['em']->getClassMetaData(User::class));
});

$this->app->singleton(ProfileRepository::class, function ($app) {
return new DoctrineProfileRepository($app['em'], $app['em']->getClassMetaData(Profile::class));
});

foreach (config('repositories.repositories') as $repository) {
$entity = config('repositories.entity_namespace') . '\\' . $repository;
$interface = config('repositories.repositoriy_namespace') . '\\' . $repository . 'Repository';
$implmentation = config('repositories.repositoriy_namespace') . '\\' .
(strpos($repository, '\\') ? explode('\\', $repository)[0] . '\\' : '') .
'Doctrine\\Doctrine' .
(strpos($repository, '\\') ? explode('\\', $repository)[1] : $repository) .
'Repository';

$this->app->singleton($interface, function ($app) use ($implmentation, $entity) {
return new $implmentation($app['em'], $app['em']->getClassMetaData($entity));
});
}

// Special case so do this one by hand
$this->app->singleton(PermissionRepository::class, function ($app) {
return new DoctrinePermissionRepository($app['em'], $app['em']->getClassMetaData(Permission::class));
});

$this->app->singleton(AccountRepository::class, function ($app) {
return new DoctrineAccountRepository($app['em'], $app['em']->getClassMetaData(Account::class));
});
}
}
44 changes: 44 additions & 0 deletions config/repositories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| Repository Interface Namespace
|--------------------------------------------------------------------------
|
| This base namespace prefix will be used with each of the repositories listed
| below to generate the full interface and implementation class names.
|
*/
'repositoriy_namespace' => 'HMS\Repositories',

/*
|--------------------------------------------------------------------------
| Entity Namespace
|--------------------------------------------------------------------------
|
| This base prefix will be used with each repositories listed below to
| generate the Entity full class name.
|
*/
'entity_namespace' => 'HMS\Entities',

/*
|--------------------------------------------------------------------------
| Autoloaded Repositories
|--------------------------------------------------------------------------
|
| The repositories listed here will be automatically loaded on the
| request to your application.
|
*/
'repositories' => [
'Link',
'Meta',
'Role',
'User',
'Invite',
'Profile',
'Banking\Account',
],
];