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.
66 lines
1.7 KiB
PHP
66 lines
1.7 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');
|
|
}
|
|
$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);
|
|
}
|
|
}
|