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
904654dc
Commit
904654dc
authored
Apr 01, 2013
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More features
parent
9d26ccb9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
136 additions
and
410 deletions
+136
-410
ConnectionResolver.php
src/Jenssegers/Mongodb/ConnectionResolver.php
+1
-1
Model.php
src/Jenssegers/Mongodb/Model.php
+28
-211
Query.php
src/Jenssegers/Mongodb/Query.php
+107
-198
No files found.
src/Jenssegers/Mongodb/ConnectionResolver.php
View file @
904654dc
...
@@ -41,7 +41,7 @@ class ConnectionResolver implements ConnectionResolverInterface {
...
@@ -41,7 +41,7 @@ class ConnectionResolver implements ConnectionResolverInterface {
* Get a database connection instance.
* Get a database connection instance.
*
*
* @param string $name
* @param string $name
* @return
\Illuminate\Database\
Connection
* @return Connection
*/
*/
public
function
connection
(
$name
=
null
)
public
function
connection
(
$name
=
null
)
{
{
...
...
src/Jenssegers/Mongodb/Model.php
View file @
904654dc
...
@@ -2,15 +2,9 @@
...
@@ -2,15 +2,9 @@
use
Illuminate\Database\ConnectionResolverInterface
as
Resolver
;
use
Illuminate\Database\ConnectionResolverInterface
as
Resolver
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Database\Eloquent\Collection
;
use
Jenssegers\Mongodb\Query
as
QueryBuilder
;
abstract
class
Model
extends
\ArrayObject
{
abstract
class
Model
extends
\Illuminate\Database\Eloquent\Model
{
/**
* The connection name for the model.
*
* @var string
*/
protected
$connection
;
/**
/**
* The collection associated with the model.
* The collection associated with the model.
...
@@ -27,225 +21,48 @@ abstract class Model extends \ArrayObject {
...
@@ -27,225 +21,48 @@ abstract class Model extends \ArrayObject {
protected
$primaryKey
=
'_id'
;
protected
$primaryKey
=
'_id'
;
/**
/**
* The connection resolver instance.
* Perform a model insert operation.
*
* @var Jenssegers\Mongodb\ConnectionResolverInterface
*/
protected
static
$resolver
;
/**
* Get properties from internal array
*
* @param string $name
* @return mixed
*/
public
function
__get
(
$name
)
{
return
$this
[
$name
];
}
/**
* Write all properties to internal array
*
* @param string $name
* @param mixed $value
*/
public
function
__set
(
$name
,
$value
)
{
$this
[
$name
]
=
$value
;
}
/**
* Handle dynamic method calls into the method.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public
function
__call
(
$method
,
$parameters
)
{
// Create a query
$query
=
$this
->
newQuery
();
return
call_user_func_array
(
array
(
$query
,
$method
),
$parameters
);
}
/**
* Handle dynamic static method calls into the method.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public
static
function
__callStatic
(
$method
,
$parameters
)
{
$instance
=
new
static
;
return
call_user_func_array
(
array
(
$instance
,
$method
),
$parameters
);
}
/**
* Get all of the models from the database.
*
*
* @param
array $columns
* @param
\Illuminate\Database\Eloquent\Builder
* @return
\Illuminate\Database\Eloquent\Collection
* @return
bool
*/
*/
p
ublic
static
function
all
(
$columns
=
array
(
'*'
)
)
p
rotected
function
performInsert
(
$query
)
{
{
$instance
=
new
static
;
if
(
$this
->
fireModelEvent
(
'creating'
)
===
false
)
return
false
;
return
$instance
->
newQuery
()
->
get
(
$columns
);
$attributes
=
$this
->
attributes
;
}
/**
// If the model has an incrementing key, we can use the "insertGetId" method on
* Find a model by its primary key.
// the query builder, which will give us back the final inserted ID for this
*
// table from the database. Not all tables have to be incrementing though.
* @param mixed $id
if
(
$this
->
incrementing
)
* @param array $columns
* @return \Jenssegers\Mongodb\Model|\Illuminate\Database\Eloquent\Collection
*/
public
static
function
find
(
$id
,
$columns
=
array
(
'*'
))
{
$instance
=
new
static
;
if
(
is_array
(
$id
))
{
{
$id
=
array_map
(
function
(
$value
)
$keyName
=
$this
->
getKeyName
();
{
$this
->
setAttribute
(
$keyName
,
$query
->
insert
(
$attributes
));
return
(
$value
instanceof
MongoID
)
?
$value
:
new
MongoID
(
$value
);
},
$id
);
return
$instance
->
newQuery
()
->
whereIn
(
$instance
->
getKeyName
(),
$id
)
->
get
(
$columns
);
}
}
return
$instance
->
newQuery
()
->
find
(
$id
,
$columns
);
// If the table is not incrementing we'll simply insert this attributes as they
}
// are, as this attributes arrays must contain an "id" column already placed
// there by the developer as the manually determined key for these models.
/**
else
* Create a new instance of the given model.
{
*
$query
->
insert
(
$attributes
);
* @param array $attributes
}
* @param bool $exists
* @return \Jenssegers\Mongodb\Model
*/
public
function
newInstance
(
$attributes
=
array
(),
$exists
=
false
)
{
// This method just provides a convenient way for us to generate fresh model
// instances of this current model. It is particularly useful during the
// hydration of new objects via the Eloquent query builder instances.
$model
=
new
static
((
array
)
$attributes
);
$model
->
exists
=
$exists
;
return
$model
;
}
/**
* Get a new query for the model's table.
*
* @return \Jenssegers\Mongodb\Query
*/
public
function
newQuery
()
{
$query
=
new
Query
(
$this
);
return
$query
;
}
/**
* Create a new Collection instance.
*
* @param array $models
* @return LMongo\Eloquent\Collection
*/
public
function
newCollection
(
array
$models
=
array
())
{
return
new
Collection
(
$models
);
}
/**
* Get the database collection for the model.
*
* @return \Jenssegers\Mongodb\Connection
*/
public
function
getCollection
()
{
return
$this
->
collection
;
}
/**
* Get the database connection for the model.
*
* @return \Jenssegers\Mongodb\Connection
*/
public
function
getConnection
()
{
return
static
::
resolveConnection
(
$this
->
connection
);
}
/**
* Get the current connection name for the model.
*
* @return string
*/
public
function
getConnectionName
()
{
return
$this
->
connection
;
}
/**
* Set the connection associated with the model.
*
* @param string $name
* @return void
*/
public
function
setConnection
(
$name
)
{
$this
->
connection
=
$name
;
}
/**
* Get the primary key for the model.
*
* @return string
*/
public
function
getKeyName
()
{
return
$this
->
primaryKey
;
}
/**
$this
->
fireModelEvent
(
'created'
,
false
);
* Resolve a connection instance by name.
*
* @param string $connection
* @return \Jenssegers\Mongodb\Connection
*/
public
static
function
resolveConnection
(
$connection
)
{
return
static
::
$resolver
->
connection
(
$connection
);
}
/**
return
true
;
* Get the connection resolver instance.
*
* @return \Jenssegers\Mongodb\ConnectionResolverInterface
*/
public
static
function
getConnectionResolver
()
{
return
static
::
$resolver
;
}
}
/**
/**
*
Set the connection resolver instance
.
*
Get a new query builder instance for the connection
.
*
*
* @param Jenssegers\Mongodb\ConnectionResolverInterface $resolver
* @return Builder
* @return void
*/
*/
p
ublic
static
function
setConnectionResolver
(
Resolver
$resolver
)
p
rotected
function
newBaseQueryBuilder
(
)
{
{
static
::
$resolver
=
$resolver
;
$connection
=
$this
->
getConnection
();
return
new
QueryBuilder
(
$connection
,
$this
->
collection
);
}
}
}
}
\ No newline at end of file
src/Jenssegers/Mongodb/Query.php
View file @
904654dc
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