-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from dshoreman/databases
Add basic database listing Adds a basic (but filterable) table with a list of databases so the Databases item in the main sidebar menu finally has a purpose. To get the list we add a new Database class that wraps Doctrine's DBAL which can eventually also be used to list tables etc. This also sets up the ground work for #146.
- Loading branch information
Showing
11 changed files
with
422 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Servidor; | ||
|
||
use Doctrine\DBAL\Configuration; | ||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\DriverManager; | ||
use Doctrine\DBAL\Schema\MySqlSchemaManager; | ||
|
||
class Database | ||
{ | ||
/** | ||
* @var Connection | ||
*/ | ||
private $connection; | ||
|
||
public function dbal(): MySqlSchemaManager | ||
{ | ||
if (!$this->connection) { | ||
$this->connect(); | ||
} | ||
|
||
return $this->connection->getSchemaManager(); | ||
} | ||
|
||
private function connect(): Connection | ||
{ | ||
if (!$this->connection) { | ||
$this->connection = DriverManager::getConnection([ | ||
'user' => config('database.dbal.user'), | ||
'password' => config('database.dbal.password'), | ||
'host' => config('database.connections.mysql.host'), | ||
'driver' => 'pdo_mysql', | ||
], new Configuration()); | ||
} | ||
|
||
return $this->connection; | ||
} | ||
|
||
public function listDatabases(): array | ||
{ | ||
return $this->dbal()->listDatabases(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Servidor\Http\Controllers; | ||
|
||
use Servidor\Database; | ||
|
||
class DatabaseController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index() | ||
{ | ||
$db = new Database(); | ||
|
||
return $db->listDatabases(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.