Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
laravel-mongodb
Commits
42b6cb95
Commit
42b6cb95
authored
May 25, 2013
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed backup source folder
parent
e80273b4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
0 additions
and
782 deletions
+0
-782
Connection.php
srcb/Jenssegers/Mongodb/Connection.php
+0
-104
ConnectionResolver.php
srcb/Jenssegers/Mongodb/ConnectionResolver.php
+0
-100
Model.php
srcb/Jenssegers/Mongodb/Model.php
+0
-81
MongodbServiceProvider.php
srcb/Jenssegers/Mongodb/MongodbServiceProvider.php
+0
-35
Query.php
srcb/Jenssegers/Mongodb/Query.php
+0
-462
No files found.
srcb/Jenssegers/Mongodb/Connection.php
deleted
100644 → 0
View file @
e80273b4
<?php
namespace
Jenssegers\Mongodb
;
class
Connection
{
/**
* The MongoDB database handler.
*
* @var resource
*/
protected
$db
;
/**
* The MongoClient connection handler.
*
* @var resource
*/
protected
$connection
;
/**
* The database connection configuration options.
*
* @var string
*/
protected
$config
=
array
();
/**
* Create a new database connection instance.
*
* @param array $config
* @return void
*/
public
function
__construct
(
array
$config
)
{
if
(
!
is_null
(
$this
->
connection
))
return
;
// Store configuration
$this
->
config
=
$config
;
// Check for connection options
$options
=
array_get
(
$config
,
'options'
,
array
());
// Create connection
$this
->
connection
=
new
\MongoClient
(
$this
->
getDsn
(
$config
),
$options
);
// Select database
$this
->
db
=
$this
->
connection
->
{
$config
[
'database'
]};
return
$this
;
}
/**
* Get a mongodb collection.
*
* @param string $name
* @return MongoDB
*/
public
function
getCollection
(
$name
)
{
return
$this
->
db
->
{
$name
};
}
/**
* Get the mongodb database object.
*
* @return MongoDB
*/
public
function
getDb
()
{
return
$this
->
db
;
}
/**
* Create a DSN string from a configuration.
*
* @param array $config
* @return string
*/
protected
function
getDsn
(
array
$config
)
{
// First we will create the basic DSN setup as well as the port if it is in
// in the configuration options. This will give us the basic DSN we will
// need to establish the MongoClient and return them back for use.
extract
(
$config
);
$dsn
=
"mongodb://"
;
if
(
isset
(
$config
[
'username'
])
and
isset
(
$config
[
'password'
]))
{
$dsn
.=
"
{
$username
}
:
{
$password
}
@"
;
}
$dsn
.=
"
{
$host
}
"
;
if
(
isset
(
$config
[
'port'
]))
{
$dsn
.=
":
{
$port
}
"
;
}
$dsn
.=
"/
{
$database
}
"
;
return
$dsn
;
}
}
\ No newline at end of file
srcb/Jenssegers/Mongodb/ConnectionResolver.php
deleted
100644 → 0
View file @
e80273b4
<?php
namespace
Jenssegers\Mongodb
;
use
Illuminate\Database\ConnectionResolverInterface
;
use
Jenssegers\Mongodb\Connection
;
class
ConnectionResolver
implements
ConnectionResolverInterface
{
/**
* The application instance.
*
* @var Illuminate\Foundation\Application
*/
protected
$app
;
/**
* All of the registered connections.
*
* @var array
*/
protected
$connections
=
array
();
/**
* The default connection name.
*
* @var string
*/
protected
$default
=
'mongodb'
;
/**
* Create a new database manager instance.
*
* @param Illuminate\Foundation\Application $app
* @return void
*/
public
function
__construct
(
$app
)
{
$this
->
app
=
$app
;
}
/**
* Get a database connection instance.
*
* @param string $name
* @return Connection
*/
public
function
connection
(
$name
=
null
)
{
if
(
is_null
(
$name
))
$name
=
$this
->
getDefaultConnection
();
// If we haven't created this connection, we'll create it based on the config
// provided in the application.
if
(
!
isset
(
$this
->
connections
[
$name
]))
{
// Get connection configuration
$connections
=
$this
->
app
[
'config'
][
'database'
][
'connections'
];
if
(
is_null
(
$config
=
array_get
(
$connections
,
$name
)))
{
throw
new
\InvalidArgumentException
(
"MongoDB [
$name
] not configured."
);
}
// Make connection
$this
->
connections
[
$name
]
=
$this
->
makeConnection
(
$connections
[
$name
]);
}
return
$this
->
connections
[
$name
];
}
/**
* Create a connection.
*
* @param array $config
*/
public
function
makeConnection
(
$config
)
{
return
new
Connection
(
$config
);
}
/**
* Get the default connection name.
*
* @return string
*/
public
function
getDefaultConnection
()
{
return
$this
->
default
;
}
/**
* Set the default connection name.
*
* @param string $name
* @return void
*/
public
function
setDefaultConnection
(
$name
)
{
$this
->
default
=
$name
;
}
}
\ No newline at end of file
srcb/Jenssegers/Mongodb/Model.php
deleted
100644 → 0
View file @
e80273b4
<?php
namespace
Jenssegers\Mongodb
;
use
Illuminate\Database\ConnectionResolverInterface
as
Resolver
;
use
Illuminate\Database\Eloquent\Collection
;
use
Jenssegers\Mongodb\Query
as
QueryBuilder
;
use
DateTime
;
use
MongoDate
;
abstract
class
Model
extends
\Illuminate\Database\Eloquent\Model
{
/**
* The collection associated with the model.
*
* @var string
*/
protected
$collection
;
/**
* The primary key for the model.
*
* @var string
*/
protected
$primaryKey
=
'_id'
;
/**
* Convert a DateTime to a storable string.
*
* @param DateTime $value
* @return MongoDate
*/
protected
function
fromDateTime
(
DateTime
$value
)
{
return
new
MongoDate
(
$value
->
getTimestamp
());
}
/**
* Return a timestamp as DateTime object.
*
* @param mixed $value
* @return DateTime
*/
protected
function
asDateTime
(
$value
)
{
if
(
$value
instanceof
MongoDate
)
{
$value
=
$value
->
sec
;
}
if
(
is_int
(
$value
))
{
$value
=
"@
$value
"
;
}
return
new
DateTime
(
$value
);
}
/**
* Get the table associated with the model.
*
* @return string
*/
public
function
getTable
()
{
if
(
isset
(
$this
->
collection
))
return
$this
->
collection
;
return
parent
::
getTable
();
}
/**
* Get a new query builder instance for the connection.
*
* @return Builder
*/
protected
function
newBaseQueryBuilder
()
{
$connection
=
$this
->
getConnection
();
return
new
QueryBuilder
(
$connection
);
}
}
\ No newline at end of file
srcb/Jenssegers/Mongodb/MongodbServiceProvider.php
deleted
100644 → 0
View file @
e80273b4
<?php
namespace
Jenssegers\Mongodb
;
use
Jenssegers\Mongodb\Model
;
use
Jenssegers\Mongodb\ConnectionResolver
;
use
Illuminate\Support\ServiceProvider
;
class
MongodbServiceProvider
extends
ServiceProvider
{
/**
* Bootstrap the application events.
*
* @return void
*/
public
function
boot
()
{
Model
::
setConnectionResolver
(
$this
->
app
[
'db.mongodb'
]);
}
/**
* Register the service provider.
*
* @return void
*/
public
function
register
()
{
// The database manager is used to resolve various connections, since multiple
// connections might be managed. It also implements the connection resolver
// interface which may be used by other components requiring connections.
$this
->
app
[
'db.mongodb'
]
=
$this
->
app
->
share
(
function
(
$app
)
{
return
new
ConnectionResolver
(
$app
);
});
}
}
\ No newline at end of file
srcb/Jenssegers/Mongodb/Query.php
deleted
100644 → 0
View file @
e80273b4
This diff is collapsed.
Click to expand it.
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