ubah ke docker mode
This commit is contained in:
No files matched your search
+93
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Onecentlin\Adminer\Http\Controllers;
|
||||
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
class AdminerController extends Controller
|
||||
{
|
||||
protected $adminer;
|
||||
protected $version;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// add custom middleware to restrict access permission
|
||||
$this->middleware(config('adminer.middleware', 'adminer'));
|
||||
|
||||
// adminer version
|
||||
$this->version = '4.8.1';
|
||||
// default adminer
|
||||
$this->adminer = $this->getAdminerFileName();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
// Autologin
|
||||
$db_connection = config('database.default');
|
||||
if (!isset($_GET['db']) && config('adminer.autologin')) {
|
||||
$_POST['auth']['driver'] = $this->getDatabaseDriver(config("database.connections.{$db_connection}.driver"));
|
||||
$_POST['auth']['server'] = config("database.connections.{$db_connection}.host") . ':' . config("database.connections.{$db_connection}.port");
|
||||
$_POST['auth']['db'] = config("database.connections.{$db_connection}.database");
|
||||
$_POST['auth']['username'] = config("database.connections.{$db_connection}.username");
|
||||
$_POST['auth']['password'] = config("database.connections.{$db_connection}.password");
|
||||
}
|
||||
|
||||
$locale = strtolower(app()->getLocale());
|
||||
|
||||
// localization
|
||||
switch ($locale) {
|
||||
case 'zh-tw':
|
||||
case 'zh_tw':
|
||||
case 'zh-hant':
|
||||
$this->adminer = $this->getAdminerFileName('zh-tw');
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
include_once __DIR__ . '/../../../resources/plugin-loader.php';
|
||||
include_once __DIR__ . '/../../../resources/' . $this->adminer;
|
||||
}
|
||||
|
||||
private function getAdminerFileName($locale = 'en')
|
||||
{
|
||||
return sprintf('adminer-%s-%s.php', $this->version, strtolower($locale));
|
||||
}
|
||||
|
||||
/**
|
||||
* Mapping laravel connection driver to adminer driver
|
||||
*
|
||||
* @param $driver
|
||||
* @return string
|
||||
*/
|
||||
private function getDatabaseDriver($driver)
|
||||
{
|
||||
/*
|
||||
Adminer driver options
|
||||
|
||||
<option value="server">MySQL</option>
|
||||
<option value="sqlite">SQLite 3</option>
|
||||
<option value="sqlite2">SQLite 2</option>
|
||||
<option value="pgsql">PostgreSQL</option>
|
||||
<option value="oracle">Oracle (beta)</option>
|
||||
<option value="mssql">MS SQL (beta)</option>
|
||||
<option value="firebird">Firebird (alpha)</option>
|
||||
<option value="simpledb">SimpleDB</option>
|
||||
<option value="mongo">MongoDB</option>
|
||||
<option value="elastic">Elasticsearch (beta)</option>
|
||||
<option value="clickhouse">ClickHouse (alpha)</option>
|
||||
*/
|
||||
|
||||
switch ($driver) {
|
||||
case 'mysql':
|
||||
return 'server';
|
||||
case 'sqlsrv':
|
||||
return 'mssql';
|
||||
default:
|
||||
if (is_null($driver)) {
|
||||
return 'server';
|
||||
}
|
||||
|
||||
return $driver;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
Route::any('/', [
|
||||
'as' => 'index',
|
||||
'uses' => 'AdminerController@index',
|
||||
]);
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Onecentlin\Adminer;
|
||||
|
||||
use Illuminate\Routing\Router;
|
||||
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
|
||||
|
||||
class ServiceProvider extends BaseServiceProvider
|
||||
{
|
||||
protected $namespace = 'Onecentlin\Adminer\Http\Controllers';
|
||||
|
||||
public function boot(Router $router)
|
||||
{
|
||||
$this->publish();
|
||||
|
||||
$adminerEnabled = config('adminer.enabled');
|
||||
if (!$adminerEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->map($router);
|
||||
}
|
||||
|
||||
protected function map($router)
|
||||
{
|
||||
if ($this->app->routesAreCached() === false) {
|
||||
$prefix = config('adminer.route_prefix');
|
||||
|
||||
if ($prefix == null) {
|
||||
$prefix = 'adminer';
|
||||
}
|
||||
|
||||
$group = $router->group([
|
||||
'namespace' => $this->namespace,
|
||||
'as' => 'adminer::',
|
||||
'prefix' => $prefix,
|
||||
], function () {
|
||||
require __DIR__ . '/Http/routes.php';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected function publish()
|
||||
{
|
||||
$this->publishes([
|
||||
__DIR__ . '/../public' => public_path(),
|
||||
__DIR__ . '/../config/adminer.php' => config_path('adminer.php'),
|
||||
__DIR__ . '/../resources/plugins' => resource_path('adminer/plugins'),
|
||||
], 'adminer');
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user