Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
045858d8
Commit
045858d8
authored
Sep 13, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring the database layer.
parent
b8a901c7
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
111 deletions
+73
-111
connection.php
laravel/database/connection.php
+43
-15
factory.php
laravel/database/connector/factory.php
+0
-30
manager.php
laravel/database/manager.php
+27
-2
factory.php
laravel/database/query/compiler/factory.php
+0
-34
factory.php
laravel/database/query/factory.php
+0
-27
query.php
laravel/database/query/query.php
+3
-3
No files found.
laravel/database/connection.php
View file @
045858d8
...
...
@@ -5,6 +5,13 @@ use PDOStatement;
class
Connection
{
/**
* The database connector instance.
*
* @var Connector\Connector
*/
protected
$connector
;
/**
* The connection name.
*
...
...
@@ -19,13 +26,6 @@ class Connection {
*/
protected
$config
;
/**
* The database connector instance.
*
* @var Connector\Connector
*/
protected
$connector
;
/**
* The PDO connection.
*
...
...
@@ -44,18 +44,14 @@ class Connection {
* Create a new Connection instance.
*
* @param Connector\Connector $connector
* @param Query\Factory $factory
* @param Compiler\Factory $compiler
* @param string $name
* @param array $config
* @return void
*/
public
function
__construct
(
Connector\Connector
$connector
,
Query\Factory
$query
,
Query\Compiler\Factory
$compiler
,
$name
,
$config
)
public
function
__construct
(
Connector\Connector
$connector
,
$name
,
$config
)
{
$this
->
name
=
$name
;
$this
->
query
=
$query
;
$this
->
config
=
$config
;
$this
->
compiler
=
$compiler
;
$this
->
connector
=
$connector
;
}
...
...
@@ -181,14 +177,46 @@ class Connection {
* <code>
* // Begin a fluent query against the "users" table
* $query = DB::connection()->table('users');
*
* // Retrieve an entire table using a fluent query
* $users = DB::connection()->table('users')->get();
* </code>
*
* @param string $table
* @return Query
* @return Query
\Query
*/
public
function
table
(
$table
)
{
return
$this
->
query
->
make
(
$this
,
$this
->
compiler
->
make
(
$this
),
$table
);
switch
(
$this
->
driver
())
{
case
'pgsql'
:
return
new
Query\Postgres
(
$this
,
$this
->
compiler
(),
$table
);
default
:
return
new
Query\Query
(
$this
,
$this
->
compiler
(),
$table
);
}
}
/**
* Create a new query compiler for the connection.
*
* @return Query\Compiler
*/
protected
function
compiler
()
{
$compiler
=
(
isset
(
$this
->
config
[
'compiler'
]))
?
$this
->
config
[
'compiler'
]
:
$this
->
driver
();
switch
(
$compiler
)
{
case
'mysql'
:
return
new
Query\Compiler\MySQL
;
case
'pgsql'
:
return
new
Query\Compiler\Postgres
;
default
:
return
new
Query\Compiler\Compiler
;
}
}
/**
...
...
laravel/database/connector/factory.php
deleted
100644 → 0
View file @
b8a901c7
<?php
namespace
Laravel\Database\Connector
;
class
Factory
{
/**
* Create a new database connector instance for a given driver.
*
* @param array $config
* @return Connector
*/
public
function
make
(
$config
)
{
if
(
isset
(
$config
[
'connector'
]))
return
new
Callback
;
switch
(
$config
[
'driver'
])
{
case
'sqlite'
:
return
new
SQLite
;
case
'mysql'
:
return
new
MySQL
;
case
'pgsql'
:
return
new
Postgres
;
}
throw
new
\Exception
(
"Database configuration is invalid. Please verify your configuration."
);
}
}
\ No newline at end of file
laravel/database/manager.php
View file @
045858d8
...
...
@@ -73,14 +73,39 @@ class Manager {
throw
new
\Exception
(
"Database connection [
$connection
] is not defined."
);
}
list
(
$connector
,
$query
,
$compiler
)
=
array
(
$this
->
connector
->
make
(
$this
->
config
[
$connection
]),
new
Query\Factory
,
new
Query\Compiler\Factory
)
;
$config
=
$this
->
config
[
$connection
]
;
$this
->
connections
[
$connection
]
=
new
Connection
(
$
connector
,
$query
,
$compiler
,
$connection
,
$this
->
config
[
$connection
]
);
$this
->
connections
[
$connection
]
=
new
Connection
(
$
this
->
connector
(
$config
),
$connection
,
$config
);
}
return
$this
->
connections
[
$connection
];
}
/**
* Create a new database connector instance base on a connection configuration.
*
* @param array $config
* @return Connector\Connector
*/
protected
function
connector
(
$config
)
{
if
(
isset
(
$config
[
'connector'
]))
return
new
Connector\Callback
;
switch
(
$config
[
'driver'
])
{
case
'sqlite'
:
return
new
Connector\SQLite
;
case
'mysql'
:
return
new
Connector\MySQL
;
case
'pgsql'
:
return
new
Connector\Postgres
;
}
throw
new
\Exception
(
"Database configuration is invalid. Please verify your configuration."
);
}
/**
* Begin a fluent query against a table.
*
...
...
laravel/database/query/compiler/factory.php
deleted
100644 → 0
View file @
b8a901c7
<?php
namespace
Laravel\Database\Query\Compiler
;
use
Laravel\Database\Connection
;
class
Factory
{
/**
* Create a new query compiler for a given connection.
*
* Using driver-based compilers allows us to provide the proper syntax to different database
* systems using a common API. A core set of functions is provided through the base Compiler
* class, which can be extended and overridden for various database systems.
*
* @param Connection $connection
* @return Compiler
*/
public
static
function
make
(
Connection
$connection
)
{
$compiler
=
(
isset
(
$connection
->
config
[
'compiler'
]))
?
$connection
->
config
[
'compiler'
]
:
$connection
->
driver
();
switch
(
$compiler
)
{
case
'mysql'
:
return
new
MySQL
;
case
'pgsql'
:
return
new
Postgres
;
default
:
return
new
Compiler
;
}
}
}
\ No newline at end of file
laravel/database/query/factory.php
deleted
100644 → 0
View file @
b8a901c7
<?php
namespace
Laravel\Database\Query
;
use
Laravel\Database\Connection
;
class
Factory
{
/**
* Create a new query instance based on the connection driver.
*
* @param Connection $connection
* @param Compiler $compiler
* @param string $table
* @return Query
*/
public
function
make
(
Connection
$connection
,
Compiler
$compiler
,
$table
)
{
switch
(
$connection
->
driver
())
{
case
'pgsql'
:
return
new
Postgres
(
$connection
,
$compiler
,
$table
);
default
:
return
new
Query
(
$connection
,
$compiler
,
$table
);
}
}
}
\ No newline at end of file
laravel/database/query/query.php
View file @
045858d8
...
...
@@ -7,14 +7,14 @@ class Query {
/**
* The database connection.
*
* @var Connection
* @var
Database\
Connection
*/
public
$connection
;
/**
* The query compiler instance.
*
* @var Compiler
* @var Compiler
\Compiler
*/
public
$compiler
;
...
...
@@ -93,7 +93,7 @@ class Query {
* Create a new query instance.
*
* @param Database\Connection $connection
* @param Compiler
$compiler
* @param Compiler
\Compiler
$compiler
* @param string $table
* @return void
*/
...
...
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