52 lines
1.3 KiB
PHP
Executable File
52 lines
1.3 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: kirill
|
|
* Date: 03.08.19
|
|
* Time: 23:51
|
|
*/
|
|
|
|
namespace kernel;
|
|
|
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
|
use Illuminate\Database\Schema\Builder;
|
|
use Illuminate\Container\Container;
|
|
use Phroute\Phroute\Dispatcher;
|
|
|
|
class Database
|
|
{
|
|
/** @var Builder $capsule */
|
|
public Builder $schema;
|
|
|
|
/** @var Capsule $capsule */
|
|
public Capsule $capsule;
|
|
|
|
function __construct()
|
|
{
|
|
$this->capsule = new Capsule;
|
|
$this->capsule->addConnection([
|
|
'driver' => $_ENV['DB_DRIVER'],
|
|
'host' => $_ENV['DB_HOST'],
|
|
'database' => $_ENV['DB_NAME'],
|
|
'username' => $_ENV['DB_USER'],
|
|
'password' => $_ENV['DB_PASSWORD'],
|
|
'charset' => $_ENV['DB_CHARSET'],
|
|
'collation' => $_ENV['DB_COLLATION'],
|
|
'prefix' => $_ENV['DB_PREFIX'],
|
|
]);
|
|
// Setup the Eloquent ORM…
|
|
|
|
$this->capsule->setAsGlobal();
|
|
|
|
$this->capsule->bootEloquent();
|
|
|
|
$this->schema = $this->capsule->schema();
|
|
}
|
|
|
|
public function createBuilder(string $table_name): \Illuminate\Database\Query\Builder
|
|
{
|
|
$builder = new \Illuminate\Database\Query\Builder($this->schema->getConnection());
|
|
$builder->from($table_name);
|
|
return $builder;
|
|
}
|
|
} |