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
9d2a76b2
Commit
9d2a76b2
authored
Aug 19, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring database.
parent
bf0aaa3c
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
37 additions
and
66 deletions
+37
-66
laravel/db.php
+2
-2
laravel/db/connection.php
+0
-18
laravel/db/connection/factory.php
+0
-31
laravel/db/connector/callback.php
+3
-2
laravel/db/connector/factory.php
+9
-7
laravel/db/query.php
+13
-1
laravel/db/query/factory.php
+7
-2
laravel/db/query/mysql.php
+3
-3
No files found.
laravel/db.php
View file @
9d2a76b2
...
...
@@ -37,9 +37,9 @@ class DB {
throw
new
\Exception
(
"Database connection [
$connection
] is not defined."
);
}
$connector
=
DB\Connector\Factory
::
make
(
$config
[
'driver'
]
);
$connector
=
DB\Connector\Factory
::
make
(
$config
);
static
::
$connections
[
$connection
]
=
DB\Connection\Factory
::
make
(
$connection
,
$config
,
$connector
);
static
::
$connections
[
$connection
]
=
new
DB\Connection
(
$connection
,
$config
,
$connector
);
}
return
static
::
$connections
[
$connection
];
...
...
laravel/db/connection.php
View file @
9d2a76b2
...
...
@@ -167,21 +167,4 @@ class Connection {
return
$this
->
pdo
->
getAttribute
(
\PDO
::
ATTR_DRIVER_NAME
);
}
/**
* Get the table prefix for the database connection.
*
* @return string
*/
public
function
prefix
()
{
return
(
array_key_exists
(
'prefix'
,
$this
->
config
))
?
$this
->
config
[
'prefix'
]
:
''
;
}
/**
* Get the keyword identifier wrapper for the connection.
*
* @return string
*/
public
function
wrapper
()
{
return
'"'
;
}
}
\ No newline at end of file
laravel/db/connection/factory.php
deleted
100644 → 0
View file @
bf0aaa3c
<?php
namespace
Laravel\DB\Connection
;
use
Laravel\DB\Connector
;
use
Laravel\DB\Connection
;
class
Factory
{
/**
* Get a connnection instance.
*
* The connection instance created depends on the driver being used.
*
* @param string $connection
* @param object $config
* @param Connector $connector
* @return Connection
*/
public
static
function
make
(
$connection
,
$config
,
Connector
$connector
)
{
switch
(
$config
[
'driver'
])
{
case
'mysql'
:
return
new
MySQL
(
$connection
,
$config
,
$connector
);
default
:
return
new
Connection
(
$connection
,
$config
,
$connector
);
}
}
}
\ No newline at end of file
laravel/db/connector/
generic
.php
→
laravel/db/connector/
callback
.php
View file @
9d2a76b2
...
...
@@ -2,7 +2,7 @@
use
Laravel\DB\Connector
;
class
Generic
extends
Connector
{
class
Callback
extends
Connector
{
/**
* Establish a PDO database connection.
...
...
@@ -12,7 +12,7 @@ class Generic extends Connector {
*/
public
function
connect
(
$config
)
{
return
new
\PDO
(
$config
[
'driver'
]
.
':'
.
$config
[
'dsn'
],
$config
[
'username'
],
$config
[
'password'
],
$this
->
options
);
return
call_user_func
(
$config
[
'connector'
]
);
}
}
\ No newline at end of file
laravel/db/connector/factory.php
View file @
9d2a76b2
...
...
@@ -5,12 +5,14 @@ class Factory {
/**
* Create a new database connector instance for a given driver.
*
* @param
string $driver
* @param
array $config
* @return Connector
*/
public
static
function
make
(
$
driver
)
public
static
function
make
(
$
config
)
{
switch
(
$driver
)
if
(
isset
(
$config
[
'connector'
]))
return
new
Callback
;
switch
(
$config
[
'driver'
])
{
case
'sqlite'
:
return
new
SQLite
;
...
...
@@ -18,12 +20,11 @@ class Factory {
case
'mysql'
:
return
new
MySQL
;
case
'p
ostgres
'
:
case
'p
gsql
'
:
return
new
Postgres
;
default
:
return
new
Generic
;
}
throw
new
\Exception
(
"Database configuration is invalid. Please verify your configuration."
);
}
}
\ No newline at end of file
laravel/db/query.php
View file @
9d2a76b2
...
...
@@ -630,7 +630,7 @@ class Query {
foreach
(
explode
(
'.'
,
$value
)
as
$segment
)
{
$wrapped
[]
=
(
$segment
!=
'*'
)
?
$this
->
connection
->
wrapper
()
.
$segment
.
$this
->
connection
->
wrapper
()
:
$segment
;
$wrapped
[]
=
(
$segment
!=
'*'
)
?
$this
->
wrapper
()
.
$segment
.
$this
->
wrapper
()
:
$segment
;
}
return
implode
(
'.'
,
$wrapped
);
...
...
@@ -650,6 +650,18 @@ class Query {
}
/**
* Get the keyword identifier wrapper for the connection.
*
* MySQL uses a non-standard wrapper
*
* @return string
*/
protected
function
wrapper
()
{
return
'"'
;
}
/**
* Create query parameters from an array of values.
*
* @param array $values
...
...
laravel/db/query/factory.php
View file @
9d2a76b2
...
...
@@ -14,11 +14,16 @@ class Factory {
*/
public
static
function
make
(
$table
,
Connection
$connection
)
{
switch
(
$connection
->
driver
())
$query
=
(
isset
(
$connection
->
config
[
'query'
]))
?
$connection
->
config
[
'query'
]
:
$connection
->
driver
();
switch
(
$query
)
{
case
'p
ostgres
'
:
case
'p
gsql
'
:
return
new
Postgres
(
$table
,
$connection
);
case
'mysql'
:
return
new
MySQL
(
$table
,
$connection
);
default
:
return
new
Query
(
$table
,
$connection
);
}
...
...
laravel/db/
connection
/mysql.php
→
laravel/db/
query
/mysql.php
View file @
9d2a76b2
<?php
namespace
Laravel\DB\
Connection
;
<?php
namespace
Laravel\DB\
Query
;
use
Laravel\DB\
Connection
;
use
Laravel\DB\
Query
;
class
MySQL
extends
Connection
{
class
MySQL
extends
Query
{
/**
* Get the keyword identifier wrapper for the connection.
...
...
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