Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
7e33ec5f
Commit
7e33ec5f
authored
Apr 30, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow the registration of custom database drivers.
parent
cf29450b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
3 deletions
+43
-3
laravel/database.php
+28
-0
laravel/database/connection.php
+10
-3
laravel/database/schema.php
+5
-0
No files found.
laravel/database.php
View file @
7e33ec5f
...
...
@@ -13,6 +13,13 @@ class Database {
public
static
$connections
=
array
();
/**
* The third-party driver registrar.
*
* @var array
*/
public
static
$registrar
=
array
();
/**
* Get a database connection.
*
* If no database name is specified, the default connection will be returned.
...
...
@@ -66,6 +73,11 @@ class Database {
*/
protected
static
function
connector
(
$driver
)
{
if
(
isset
(
static
::
$registrar
[
$driver
]))
{
return
static
::
$registrar
[
$driver
][
'connector'
]();
}
switch
(
$driver
)
{
case
'sqlite'
:
...
...
@@ -121,6 +133,22 @@ class Database {
}
/**
* Register a database connector and grammars.
*
* @param string $name
* @param Closure $connector
* @param Closure $query
* @param Closure $schema
* @return void
*/
public
static
function
register
(
$name
,
Closure
$connector
,
$query
=
null
,
$schema
=
null
)
{
if
(
is_null
(
$query
))
$query
=
'\Laravel\Database\Query\Grammars\Grammar'
;
static
::
$registrar
[
$name
]
=
compact
(
'connector'
,
'query'
,
'schema'
);
}
/**
* Magic Method for calling methods on the default database connection.
*
* <code>
...
...
laravel/database/connection.php
View file @
7e33ec5f
<?php
namespace
Laravel\Database
;
use
PDO
,
PDOStatement
,
Laravel\Config
,
Laravel\Event
;
<?php
namespace
Laravel\Database
;
use
PDO
,
PDOStatement
,
Laravel\Config
,
Laravel\Event
;
class
Connection
{
...
...
@@ -71,7 +73,12 @@ class Connection {
{
if
(
isset
(
$this
->
grammar
))
return
$this
->
grammar
;
switch
(
isset
(
$this
->
config
[
'grammar'
])
?
$this
->
config
[
'grammar'
]
:
$this
->
driver
())
if
(
isset
(
\Laravel\Database
::
$registrar
[
$this
->
driver
()]))
{
\Laravel\Database
::
$registrar
[
$this
->
driver
()][
'query'
]();
}
switch
(
$this
->
driver
())
{
case
'mysql'
:
return
$this
->
grammar
=
new
Query\Grammars\MySQL
(
$this
);
...
...
@@ -300,7 +307,7 @@ class Connection {
*/
public
function
driver
()
{
return
$this
->
pdo
->
getAttribute
(
PDO
::
ATTR_DRIVER_NAME
)
;
return
$this
->
config
[
'driver'
]
;
}
/**
...
...
laravel/database/schema.php
View file @
7e33ec5f
...
...
@@ -148,6 +148,11 @@ class Schema {
{
$driver
=
$connection
->
driver
();
if
(
isset
(
\Laravel\Database
::
$registrar
[
$driver
]))
{
return
\Laravel\Database
::
$registrar
[
$driver
][
'schema'
]();
}
switch
(
$driver
)
{
case
'mysql'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment