97 lines
3.0 KiB
PHP
97 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Repositories\Country\CountryRepository;
|
|
use App\Repositories\Country\EloquentCountry;
|
|
use App\Repositories\Permission\EloquentPermission;
|
|
use App\Repositories\Permission\PermissionRepository;
|
|
use App\Repositories\Role\EloquentRole;
|
|
use App\Repositories\Role\RoleRepository;
|
|
use App\Repositories\Session\DbSession;
|
|
use App\Repositories\Session\SessionRepository;
|
|
use App\Repositories\User\EloquentUser;
|
|
use App\Repositories\User\UserRepository;
|
|
use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Database\Schema\Builder;
|
|
use Illuminate\Pagination\Paginator;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Intervention\Image\Drivers\Gd\Driver;
|
|
use Intervention\Image\ImageManager;
|
|
use Route;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Bootstrap any application services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
Carbon::setLocale(config('app.locale'));
|
|
config(['app.name' => setting('app_name')]);
|
|
Builder::defaultStringLength(191);
|
|
|
|
Factory::guessFactoryNamesUsing(function (string $modelName) {
|
|
return 'Database\Factories\\'.class_basename($modelName).'Factory';
|
|
});
|
|
|
|
Paginator::useBootstrapFive();
|
|
|
|
$this->bindUser();
|
|
$this->bindRole();
|
|
$this->bindSession();
|
|
}
|
|
|
|
/**
|
|
* Register any application services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
$this->app->singleton(UserRepository::class, EloquentUser::class);
|
|
$this->app->singleton(RoleRepository::class, EloquentRole::class);
|
|
$this->app->singleton(PermissionRepository::class, EloquentPermission::class);
|
|
$this->app->singleton(SessionRepository::class, DbSession::class);
|
|
$this->app->singleton(CountryRepository::class, EloquentCountry::class);
|
|
|
|
$this->app->bind(ImageManager::class, function ($app) {
|
|
return new ImageManager(
|
|
new Driver
|
|
);
|
|
});
|
|
|
|
if ($this->app->environment('local')) {
|
|
$this->app->register(IdeHelperServiceProvider::class);
|
|
$this->app->register(\Fruitcake\LaravelDebugbar\ServiceProvider::class);
|
|
}
|
|
}
|
|
|
|
private function bindUser(): void
|
|
{
|
|
$this->bindUsingRepository('user', UserRepository::class);
|
|
}
|
|
|
|
private function bindRole(): void
|
|
{
|
|
$this->bindUsingRepository('role', RoleRepository::class);
|
|
}
|
|
|
|
private function bindSession(): void
|
|
{
|
|
$this->bindUsingRepository('session', SessionRepository::class);
|
|
}
|
|
|
|
private function bindUsingRepository($entity, $repository, $method = 'find'): void
|
|
{
|
|
Route::bind($entity, function ($id) use ($repository, $method) {
|
|
if ($object = app($repository)->$method($id)) {
|
|
return $object;
|
|
}
|
|
|
|
throw new NotFoundHttpException('Resource not found.');
|
|
});
|
|
}
|
|
}
|