You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/app/Services/Boot.php

71 lines
2.0 KiB
PHP

<?php
namespace App\Services;
use Dotenv\Dotenv;
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
class Boot
{
public static function loadEnv()
{
// Env
$env = Dotenv::createImmutable(BASE_PATH);
$env->safeLoad();
}
public static function setDebug()
{
// debug
if (Config::get('debug') == "true") {
define("DEBUG", true);
}
}
public static function setTimezone()
{
// config time zone
date_default_timezone_set(Config::get('timeZone'));
}
public static function bootDb()
{
// Init Eloquent ORM Connection
$capsule = new Capsule;
$capsule->addConnection(Config::getDbConfig(), 'default');
if (Config::get('enable_log')=='true') {
$capsule->addConnection(Config::getLogDbConfig(), 'log');
}
// Several database-only coordinators intentionally use Capsule's
// static query builder so every write in one workflow shares the
// connection selected by the surrounding transaction. Eloquent's
// resolver alone does not initialize that static Capsule instance.
$capsule->setAsGlobal();
$capsule->bootEloquent();
self::bootPaginator();
}
private static function bootPaginator()
{
$factoryResolver = function () {
return new PaginationViewFactory();
};
Paginator::viewFactoryResolver($factoryResolver);
LengthAwarePaginator::viewFactoryResolver($factoryResolver);
$pathResolver = function () {
$uri = isset($_SERVER['REQUEST_URI']) ? (string) $_SERVER['REQUEST_URI'] : '/';
$path = parse_url($uri, PHP_URL_PATH);
return $path === null || $path === false || $path === '' ? '/' : $path;
};
Paginator::currentPathResolver($pathResolver);
LengthAwarePaginator::currentPathResolver($pathResolver);
}
}