Commit c76f333e authored by Jens Segers's avatar Jens Segers

Work on Laravel 5.4 compatibility

parent e3bea541
<?php namespace Jenssegers\Mongodb\Auth; <?php namespace Jenssegers\Mongodb\Auth;
use Illuminate\Auth\Passwords\DatabaseTokenRepository as BaseDatabaseTokenRepository;
use MongoDB\BSON\UTCDateTime;
use DateTime; use DateTime;
use DateTimeZone; use DateTimeZone;
use Illuminate\Auth\Passwords\DatabaseTokenRepository as BaseDatabaseTokenRepository;
use MongoDB\BSON\UTCDateTime;
class DatabaseTokenRepository extends BaseDatabaseTokenRepository class DatabaseTokenRepository extends BaseDatabaseTokenRepository
{ {
/** /**
* Build the record payload for the table. * @inheritdoc
*
* @param string $email
* @param string $token
* @return array
*/ */
protected function getPayload($email, $token) protected function getPayload($email, $token)
{ {
...@@ -20,10 +16,7 @@ class DatabaseTokenRepository extends BaseDatabaseTokenRepository ...@@ -20,10 +16,7 @@ class DatabaseTokenRepository extends BaseDatabaseTokenRepository
} }
/** /**
* Determine if the token has expired. * @inheritdoc
*
* @param array $token
* @return bool
*/ */
protected function tokenExpired($token) protected function tokenExpired($token)
{ {
......
...@@ -5,10 +5,7 @@ use Illuminate\Auth\Passwords\PasswordBrokerManager as BasePasswordBrokerManager ...@@ -5,10 +5,7 @@ use Illuminate\Auth\Passwords\PasswordBrokerManager as BasePasswordBrokerManager
class PasswordBrokerManager extends BasePasswordBrokerManager class PasswordBrokerManager extends BasePasswordBrokerManager
{ {
/** /**
* Create a token repository instance based on the given configuration. * @inheritdoc
*
* @param array $config
* @return \Illuminate\Auth\Passwords\TokenRepositoryInterface
*/ */
protected function createTokenRepository(array $config) protected function createTokenRepository(array $config)
{ {
......
...@@ -28,9 +28,7 @@ class PasswordResetServiceProvider extends BasePasswordResetServiceProvider ...@@ -28,9 +28,7 @@ class PasswordResetServiceProvider extends BasePasswordResetServiceProvider
} }
/** /**
* Register the password broker instance. * @inheritdoc
*
* @return void
*/ */
protected function registerPasswordBroker() protected function registerPasswordBroker()
{ {
......
<?php namespace Jenssegers\Mongodb; <?php namespace Jenssegers\Mongodb;
use Exception; use Exception;
use MongoDB\Collection as MongoCollection;
use MongoDB\BSON\ObjectID; use MongoDB\BSON\ObjectID;
use MongoDB\Collection as MongoCollection;
class Collection class Collection
{ {
...@@ -21,7 +21,8 @@ class Collection ...@@ -21,7 +21,8 @@ class Collection
protected $collection; protected $collection;
/** /**
* Constructor. * @param Connection $connection
* @param MongoCollection $collection
*/ */
public function __construct(Connection $connection, MongoCollection $collection) public function __construct(Connection $connection, MongoCollection $collection)
{ {
...@@ -32,8 +33,8 @@ class Collection ...@@ -32,8 +33,8 @@ class Collection
/** /**
* Handle dynamic method calls. * Handle dynamic method calls.
* *
* @param string $method * @param string $method
* @param array $parameters * @param array $parameters
* @return mixed * @return mixed
*/ */
public function __call($method, $parameters) public function __call($method, $parameters)
...@@ -65,7 +66,7 @@ class Collection ...@@ -65,7 +66,7 @@ class Collection
} }
} }
$queryString = $this->collection->getCollectionName() . '.' . $method . '(' . implode(',', $query) . ')'; $queryString = $this->collection->getCollectionName().'.'.$method.'('.implode(',', $query).')';
$this->connection->logQuery($queryString, [], $time); $this->connection->logQuery($queryString, [], $time);
} }
......
...@@ -21,7 +21,7 @@ class Connection extends \Illuminate\Database\Connection ...@@ -21,7 +21,7 @@ class Connection extends \Illuminate\Database\Connection
/** /**
* Create a new database connection instance. * Create a new database connection instance.
* *
* @param array $config * @param array $config
*/ */
public function __construct(array $config) public function __construct(array $config)
{ {
...@@ -45,9 +45,7 @@ class Connection extends \Illuminate\Database\Connection ...@@ -45,9 +45,7 @@ class Connection extends \Illuminate\Database\Connection
} }
/** /**
* Get the default post processor instance. * @inheritdoc
*
* @return Query\Processor
*/ */
protected function getDefaultPostProcessor() protected function getDefaultPostProcessor()
{ {
...@@ -57,7 +55,7 @@ class Connection extends \Illuminate\Database\Connection ...@@ -57,7 +55,7 @@ class Connection extends \Illuminate\Database\Connection
/** /**
* Begin a fluent query against a database collection. * Begin a fluent query against a database collection.
* *
* @param string $collection * @param string $collection
* @return Query\Builder * @return Query\Builder
*/ */
public function collection($collection) public function collection($collection)
...@@ -72,7 +70,7 @@ class Connection extends \Illuminate\Database\Connection ...@@ -72,7 +70,7 @@ class Connection extends \Illuminate\Database\Connection
/** /**
* Begin a fluent query against a database collection. * Begin a fluent query against a database collection.
* *
* @param string $table * @param string $table
* @return Query\Builder * @return Query\Builder
*/ */
public function table($table) public function table($table)
...@@ -83,7 +81,7 @@ class Connection extends \Illuminate\Database\Connection ...@@ -83,7 +81,7 @@ class Connection extends \Illuminate\Database\Connection
/** /**
* Get a MongoDB collection. * Get a MongoDB collection.
* *
* @param string $name * @param string $name
* @return Collection * @return Collection
*/ */
public function getCollection($name) public function getCollection($name)
...@@ -92,9 +90,7 @@ class Connection extends \Illuminate\Database\Connection ...@@ -92,9 +90,7 @@ class Connection extends \Illuminate\Database\Connection
} }
/** /**
* Get a schema builder instance for the connection. * @inheritdoc
*
* @return Schema\Builder
*/ */
public function getSchemaBuilder() public function getSchemaBuilder()
{ {
...@@ -124,9 +120,9 @@ class Connection extends \Illuminate\Database\Connection ...@@ -124,9 +120,9 @@ class Connection extends \Illuminate\Database\Connection
/** /**
* Create a new MongoDB connection. * Create a new MongoDB connection.
* *
* @param string $dsn * @param string $dsn
* @param array $config * @param array $config
* @param array $options * @param array $options
* @return \MongoDB\Client * @return \MongoDB\Client
*/ */
protected function createConnection($dsn, array $config, array $options) protected function createConnection($dsn, array $config, array $options)
...@@ -139,10 +135,10 @@ class Connection extends \Illuminate\Database\Connection ...@@ -139,10 +135,10 @@ class Connection extends \Illuminate\Database\Connection
} }
// Check if the credentials are not already set in the options // Check if the credentials are not already set in the options
if (!isset($options['username']) && !empty($config['username'])) { if (! isset($options['username']) && ! empty($config['username'])) {
$options['username'] = $config['username']; $options['username'] = $config['username'];
} }
if (!isset($options['password']) && !empty($config['password'])) { if (! isset($options['password']) && ! empty($config['password'])) {
$options['password'] = $config['password']; $options['password'] = $config['password'];
} }
...@@ -150,7 +146,7 @@ class Connection extends \Illuminate\Database\Connection ...@@ -150,7 +146,7 @@ class Connection extends \Illuminate\Database\Connection
} }
/** /**
* Disconnect from the underlying MongoDB connection. * @inheritdoc
*/ */
public function disconnect() public function disconnect()
{ {
...@@ -160,7 +156,7 @@ class Connection extends \Illuminate\Database\Connection ...@@ -160,7 +156,7 @@ class Connection extends \Illuminate\Database\Connection
/** /**
* Create a DSN string from a configuration. * Create a DSN string from a configuration.
* *
* @param array $config * @param array $config
* @return string * @return string
*/ */
protected function getDsn(array $config) protected function getDsn(array $config)
...@@ -176,21 +172,18 @@ class Connection extends \Illuminate\Database\Connection ...@@ -176,21 +172,18 @@ class Connection extends \Illuminate\Database\Connection
foreach ($hosts as &$host) { foreach ($hosts as &$host) {
// Check if we need to add a port to the host // Check if we need to add a port to the host
if (strpos($host, ':') === false && ! empty($config['port'])) { if (strpos($host, ':') === false && ! empty($config['port'])) {
$host = $host . ':' . $config['port']; $host = $host.':'.$config['port'];
} }
} }
// Check if we want to authenticate against a specific database. // Check if we want to authenticate against a specific database.
$auth_database = isset($config['options']) && ! empty($config['options']['database']) ? $config['options']['database'] : null; $auth_database = isset($config['options']) && ! empty($config['options']['database']) ? $config['options']['database'] : null;
return 'mongodb://' . implode(',', $hosts) . ($auth_database ? '/' . $auth_database : ''); return 'mongodb://'.implode(',', $hosts).($auth_database ? '/'.$auth_database : '');
} }
/** /**
* Get the elapsed time since a given starting point. * @inheritdoc
*
* @param int $start
* @return float
*/ */
public function getElapsedTime($start) public function getElapsedTime($start)
{ {
...@@ -198,9 +191,7 @@ class Connection extends \Illuminate\Database\Connection ...@@ -198,9 +191,7 @@ class Connection extends \Illuminate\Database\Connection
} }
/** /**
* Get the PDO driver name. * @inheritdoc
*
* @return string
*/ */
public function getDriverName() public function getDriverName()
{ {
...@@ -208,9 +199,7 @@ class Connection extends \Illuminate\Database\Connection ...@@ -208,9 +199,7 @@ class Connection extends \Illuminate\Database\Connection
} }
/** /**
* Get the default schema grammar instance. * @inheritdoc
*
* @return Schema\Grammar
*/ */
protected function getDefaultSchemaGrammar() protected function getDefaultSchemaGrammar()
{ {
...@@ -220,8 +209,8 @@ class Connection extends \Illuminate\Database\Connection ...@@ -220,8 +209,8 @@ class Connection extends \Illuminate\Database\Connection
/** /**
* Dynamically pass methods to the connection. * Dynamically pass methods to the connection.
* *
* @param string $method * @param string $method
* @param array $parameters * @param array $parameters
* @return mixed * @return mixed
*/ */
public function __call($method, $parameters) public function __call($method, $parameters)
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Collection;
use MongoDB\Driver\Cursor; use MongoDB\Driver\Cursor;
use MongoDB\Model\BSONDocument; use MongoDB\Model\BSONDocument;
...@@ -14,16 +13,22 @@ class Builder extends EloquentBuilder ...@@ -14,16 +13,22 @@ class Builder extends EloquentBuilder
* @var array * @var array
*/ */
protected $passthru = [ protected $passthru = [
'toSql', 'insert', 'insertGetId', 'pluck', 'toSql',
'count', 'min', 'max', 'avg', 'sum', 'exists', 'push', 'pull', 'insert',
'insertGetId',
'pluck',
'count',
'min',
'max',
'avg',
'sum',
'exists',
'push',
'pull',
]; ];
/** /**
* Update a record in the database. * @inheritdoc
*
* @param array $values
* @param array $options
* @return int
*/ */
public function update(array $values, array $options = []) public function update(array $values, array $options = [])
{ {
...@@ -39,10 +44,7 @@ class Builder extends EloquentBuilder ...@@ -39,10 +44,7 @@ class Builder extends EloquentBuilder
} }
/** /**
* Insert a new record into the database. * @inheritdoc
*
* @param array $values
* @return bool
*/ */
public function insert(array $values) public function insert(array $values)
{ {
...@@ -58,11 +60,7 @@ class Builder extends EloquentBuilder ...@@ -58,11 +60,7 @@ class Builder extends EloquentBuilder
} }
/** /**
* Insert a new record and get the value of the primary key. * @inheritdoc
*
* @param array $values
* @param string $sequence
* @return int
*/ */
public function insertGetId(array $values, $sequence = null) public function insertGetId(array $values, $sequence = null)
{ {
...@@ -78,9 +76,7 @@ class Builder extends EloquentBuilder ...@@ -78,9 +76,7 @@ class Builder extends EloquentBuilder
} }
/** /**
* Delete a record from the database. * @inheritdoc
*
* @return mixed
*/ */
public function delete() public function delete()
{ {
...@@ -96,12 +92,7 @@ class Builder extends EloquentBuilder ...@@ -96,12 +92,7 @@ class Builder extends EloquentBuilder
} }
/** /**
* Increment a column's value by a given amount. * @inheritdoc
*
* @param string $column
* @param int $amount
* @param array $extra
* @return int
*/ */
public function increment($column, $amount = 1, array $extra = []) public function increment($column, $amount = 1, array $extra = [])
{ {
...@@ -126,12 +117,7 @@ class Builder extends EloquentBuilder ...@@ -126,12 +117,7 @@ class Builder extends EloquentBuilder
} }
/** /**
* Decrement a column's value by a given amount. * @inheritdoc
*
* @param string $column
* @param int $amount
* @param array $extra
* @return int
*/ */
public function decrement($column, $amount = 1, array $extra = []) public function decrement($column, $amount = 1, array $extra = [])
{ {
...@@ -154,14 +140,7 @@ class Builder extends EloquentBuilder ...@@ -154,14 +140,7 @@ class Builder extends EloquentBuilder
} }
/** /**
* Add the "has" condition where clause to the query. * @inheritdoc
*
* @param \Illuminate\Database\Eloquent\Builder $hasQuery
* @param \Illuminate\Database\Eloquent\Relations\Relation $relation
* @param string $operator
* @param int $count
* @param string $boolean
* @return \Illuminate\Database\Eloquent\Builder
*/ */
protected function addHasWhere(EloquentBuilder $hasQuery, Relation $relation, $operator, $count, $boolean) protected function addHasWhere(EloquentBuilder $hasQuery, Relation $relation, $operator, $count, $boolean)
{ {
...@@ -198,7 +177,7 @@ class Builder extends EloquentBuilder ...@@ -198,7 +177,7 @@ class Builder extends EloquentBuilder
// If we are comparing to 0, we need an additional $not flip. // If we are comparing to 0, we need an additional $not flip.
if ($count == 0) { if ($count == 0) {
$not = !$not; $not = ! $not;
} }
// All related ids. // All related ids.
...@@ -209,10 +188,7 @@ class Builder extends EloquentBuilder ...@@ -209,10 +188,7 @@ class Builder extends EloquentBuilder
} }
/** /**
* Create a raw database expression. * @inheritdoc
*
* @param closure $expression
* @return mixed
*/ */
public function raw($expression = null) public function raw($expression = null)
{ {
...@@ -223,15 +199,11 @@ class Builder extends EloquentBuilder ...@@ -223,15 +199,11 @@ class Builder extends EloquentBuilder
if ($results instanceof Cursor) { if ($results instanceof Cursor) {
$results = iterator_to_array($results, false); $results = iterator_to_array($results, false);
return $this->model->hydrate($results); return $this->model->hydrate($results);
} } // Convert Mongo BSONDocument to a single object.
// Convert Mongo BSONDocument to a single object.
elseif ($results instanceof BSONDocument) { elseif ($results instanceof BSONDocument) {
$results = $results->getArrayCopy(); $results = $results->getArrayCopy();
return $this->model->newFromBuilder((array) $results); return $this->model->newFromBuilder((array) $results);
} } // The result is a single object.
// The result is a single object.
elseif (is_array($results) and array_key_exists('_id', $results)) { elseif (is_array($results) and array_key_exists('_id', $results)) {
return $this->model->newFromBuilder((array) $results); return $this->model->newFromBuilder((array) $results);
} }
......
<?php namespace Jenssegers\Mongodb\Eloquent;
use Jenssegers\Mongodb\Relations\EmbedsMany;
use Jenssegers\Mongodb\Relations\EmbedsOne;
trait EmbedsRelations
{
/**
* Define an embedded one-to-many relationship.
*
* @param string $related
* @param string $localKey
* @param string $foreignKey
* @param string $relation
* @return \Jenssegers\Mongodb\Relations\EmbedsMany
*/
protected function embedsMany($related, $localKey = null, $foreignKey = null, $relation = null)
{
// If no relation name was given, we will use this debug backtrace to extract
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relationships.
if (is_null($relation)) {
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
}
if (is_null($localKey)) {
$localKey = $relation;
}
if (is_null($foreignKey)) {
$foreignKey = snake_case(class_basename($this));
}
$query = $this->newQuery();
$instance = new $related;
return new EmbedsMany($query, $this, $instance, $localKey, $foreignKey, $relation);
}
/**
* Define an embedded one-to-many relationship.
*
* @param string $related
* @param string $localKey
* @param string $foreignKey
* @param string $relation
* @return \Jenssegers\Mongodb\Relations\EmbedsOne
*/
protected function embedsOne($related, $localKey = null, $foreignKey = null, $relation = null)
{
// If no relation name was given, we will use this debug backtrace to extract
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relationships.
if (is_null($relation)) {
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
}
if (is_null($localKey)) {
$localKey = $relation;
}
if (is_null($foreignKey)) {
$foreignKey = snake_case(class_basename($this));
}
$query = $this->newQuery();
$instance = new $related;
return new EmbedsOne($query, $this, $instance, $localKey, $foreignKey, $relation);
}
}
...@@ -14,9 +14,9 @@ trait HybridRelations ...@@ -14,9 +14,9 @@ trait HybridRelations
/** /**
* Define a one-to-one relationship. * Define a one-to-one relationship.
* *
* @param string $related * @param string $related
* @param string $foreignKey * @param string $foreignKey
* @param string $localKey * @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\HasOne * @return \Illuminate\Database\Eloquent\Relations\HasOne
*/ */
public function hasOne($related, $foreignKey = null, $localKey = null) public function hasOne($related, $foreignKey = null, $localKey = null)
...@@ -38,11 +38,11 @@ trait HybridRelations ...@@ -38,11 +38,11 @@ trait HybridRelations
/** /**
* Define a polymorphic one-to-one relationship. * Define a polymorphic one-to-one relationship.
* *
* @param string $related * @param string $related
* @param string $name * @param string $name
* @param string $type * @param string $type
* @param string $id * @param string $id
* @param string $localKey * @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\MorphOne * @return \Illuminate\Database\Eloquent\Relations\MorphOne
*/ */
public function morphOne($related, $name, $type = null, $id = null, $localKey = null) public function morphOne($related, $name, $type = null, $id = null, $localKey = null)
...@@ -66,9 +66,9 @@ trait HybridRelations ...@@ -66,9 +66,9 @@ trait HybridRelations
/** /**
* Define a one-to-many relationship. * Define a one-to-many relationship.
* *
* @param string $related * @param string $related
* @param string $foreignKey * @param string $foreignKey
* @param string $localKey * @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\HasMany * @return \Illuminate\Database\Eloquent\Relations\HasMany
*/ */
public function hasMany($related, $foreignKey = null, $localKey = null) public function hasMany($related, $foreignKey = null, $localKey = null)
...@@ -90,11 +90,11 @@ trait HybridRelations ...@@ -90,11 +90,11 @@ trait HybridRelations
/** /**
* Define a polymorphic one-to-many relationship. * Define a polymorphic one-to-many relationship.
* *
* @param string $related * @param string $related
* @param string $name * @param string $name
* @param string $type * @param string $type
* @param string $id * @param string $id
* @param string $localKey * @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\MorphMany * @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/ */
public function morphMany($related, $name, $type = null, $id = null, $localKey = null) public function morphMany($related, $name, $type = null, $id = null, $localKey = null)
...@@ -121,10 +121,10 @@ trait HybridRelations ...@@ -121,10 +121,10 @@ trait HybridRelations
/** /**
* Define an inverse one-to-one or many relationship. * Define an inverse one-to-one or many relationship.
* *
* @param string $related * @param string $related
* @param string $foreignKey * @param string $foreignKey
* @param string $otherKey * @param string $otherKey
* @param string $relation * @param string $relation
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/ */
public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null) public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
...@@ -147,7 +147,7 @@ trait HybridRelations ...@@ -147,7 +147,7 @@ trait HybridRelations
// foreign key name by using the name of the relationship function, which // foreign key name by using the name of the relationship function, which
// when combined with an "_id" should conventionally match the columns. // when combined with an "_id" should conventionally match the columns.
if (is_null($foreignKey)) { if (is_null($foreignKey)) {
$foreignKey = Str::snake($relation) . '_id'; $foreignKey = Str::snake($relation).'_id';
} }
$instance = new $related; $instance = new $related;
...@@ -165,9 +165,9 @@ trait HybridRelations ...@@ -165,9 +165,9 @@ trait HybridRelations
/** /**
* Define a polymorphic, inverse one-to-one or many relationship. * Define a polymorphic, inverse one-to-one or many relationship.
* *
* @param string $name * @param string $name
* @param string $type * @param string $type
* @param string $id * @param string $id
* @return \Illuminate\Database\Eloquent\Relations\MorphTo * @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/ */
public function morphTo($name = null, $type = null, $id = null) public function morphTo($name = null, $type = null, $id = null)
...@@ -209,11 +209,11 @@ trait HybridRelations ...@@ -209,11 +209,11 @@ trait HybridRelations
/** /**
* Define a many-to-many relationship. * Define a many-to-many relationship.
* *
* @param string $related * @param string $related
* @param string $collection * @param string $collection
* @param string $foreignKey * @param string $foreignKey
* @param string $otherKey * @param string $otherKey
* @param string $relation * @param string $relation
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/ */
public function belongsToMany($related, $collection = null, $foreignKey = null, $otherKey = null, $relation = null) public function belongsToMany($related, $collection = null, $foreignKey = null, $otherKey = null, $relation = null)
...@@ -233,11 +233,11 @@ trait HybridRelations ...@@ -233,11 +233,11 @@ trait HybridRelations
// First, we'll need to determine the foreign key and "other key" for the // First, we'll need to determine the foreign key and "other key" for the
// relationship. Once we have determined the keys we'll make the query // relationship. Once we have determined the keys we'll make the query
// instances as well as the relationship instances we need for this. // instances as well as the relationship instances we need for this.
$foreignKey = $foreignKey ?: $this->getForeignKey() . 's'; $foreignKey = $foreignKey ?: $this->getForeignKey().'s';
$instance = new $related; $instance = new $related;
$otherKey = $otherKey ?: $instance->getForeignKey() . 's'; $otherKey = $otherKey ?: $instance->getForeignKey().'s';
// If no table name was provided, we can guess it by concatenating the two // If no table name was provided, we can guess it by concatenating the two
// models using underscores in alphabetical order. The two model names // models using underscores in alphabetical order. The two model names
......
...@@ -5,14 +5,12 @@ use DateTime; ...@@ -5,14 +5,12 @@ use DateTime;
use Illuminate\Database\Eloquent\Model as BaseModel; use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Eloquent\Relations\Relation;
use Jenssegers\Mongodb\Query\Builder as QueryBuilder; use Jenssegers\Mongodb\Query\Builder as QueryBuilder;
use Jenssegers\Mongodb\Relations\EmbedsMany;
use Jenssegers\Mongodb\Relations\EmbedsOne;
use MongoDB\BSON\ObjectID; use MongoDB\BSON\ObjectID;
use MongoDB\BSON\UTCDateTime; use MongoDB\BSON\UTCDateTime;
abstract class Model extends BaseModel abstract class Model extends BaseModel
{ {
use HybridRelations; use HybridRelations, EmbedsRelations;
/** /**
* The collection associated with the model. * The collection associated with the model.
...@@ -38,7 +36,7 @@ abstract class Model extends BaseModel ...@@ -38,7 +36,7 @@ abstract class Model extends BaseModel
/** /**
* Custom accessor for the model's id. * Custom accessor for the model's id.
* *
* @param mixed $value * @param mixed $value
* @return mixed * @return mixed
*/ */
public function getIdAttribute($value) public function getIdAttribute($value)
...@@ -58,9 +56,7 @@ abstract class Model extends BaseModel ...@@ -58,9 +56,7 @@ abstract class Model extends BaseModel
} }
/** /**
* Get the table qualified key name. * @inheritdoc
*
* @return string
*/ */
public function getQualifiedKeyName() public function getQualifiedKeyName()
{ {
...@@ -68,80 +64,7 @@ abstract class Model extends BaseModel ...@@ -68,80 +64,7 @@ abstract class Model extends BaseModel
} }
/** /**
* Define an embedded one-to-many relationship. * @inheritdoc
*
* @param string $related
* @param string $localKey
* @param string $foreignKey
* @param string $relation
* @return \Jenssegers\Mongodb\Relations\EmbedsMany
*/
protected function embedsMany($related, $localKey = null, $foreignKey = null, $relation = null)
{
// If no relation name was given, we will use this debug backtrace to extract
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relatinoships.
if (is_null($relation)) {
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
}
if (is_null($localKey)) {
$localKey = $relation;
}
if (is_null($foreignKey)) {
$foreignKey = snake_case(class_basename($this));
}
$query = $this->newQuery();
$instance = new $related;
return new EmbedsMany($query, $this, $instance, $localKey, $foreignKey, $relation);
}
/**
* Define an embedded one-to-many relationship.
*
* @param string $related
* @param string $localKey
* @param string $foreignKey
* @param string $relation
* @return \Jenssegers\Mongodb\Relations\EmbedsOne
*/
protected function embedsOne($related, $localKey = null, $foreignKey = null, $relation = null)
{
// If no relation name was given, we will use this debug backtrace to extract
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relationships.
if (is_null($relation)) {
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
}
if (is_null($localKey)) {
$localKey = $relation;
}
if (is_null($foreignKey)) {
$foreignKey = snake_case(class_basename($this));
}
$query = $this->newQuery();
$instance = new $related;
return new EmbedsOne($query, $this, $instance, $localKey, $foreignKey, $relation);
}
/**
* Convert a DateTime to a storable UTCDateTime object.
*
* @param DateTime|int $value
* @return UTCDateTime
*/ */
public function fromDateTime($value) public function fromDateTime($value)
{ {
...@@ -159,10 +82,7 @@ abstract class Model extends BaseModel ...@@ -159,10 +82,7 @@ abstract class Model extends BaseModel
} }
/** /**
* Return a timestamp as DateTime object. * @inheritdoc
*
* @param mixed $value
* @return DateTime
*/ */
protected function asDateTime($value) protected function asDateTime($value)
{ {
...@@ -175,9 +95,7 @@ abstract class Model extends BaseModel ...@@ -175,9 +95,7 @@ abstract class Model extends BaseModel
} }
/** /**
* Get the format for database stored dates. * @inheritdoc
*
* @return string
*/ */
protected function getDateFormat() protected function getDateFormat()
{ {
...@@ -185,9 +103,7 @@ abstract class Model extends BaseModel ...@@ -185,9 +103,7 @@ abstract class Model extends BaseModel
} }
/** /**
* Get a fresh timestamp for the model. * @inheritdoc
*
* @return UTCDateTime
*/ */
public function freshTimestamp() public function freshTimestamp()
{ {
...@@ -195,9 +111,7 @@ abstract class Model extends BaseModel ...@@ -195,9 +111,7 @@ abstract class Model extends BaseModel
} }
/** /**
* Get the table associated with the model. * @inheritdoc
*
* @return string
*/ */
public function getTable() public function getTable()
{ {
...@@ -205,10 +119,7 @@ abstract class Model extends BaseModel ...@@ -205,10 +119,7 @@ abstract class Model extends BaseModel
} }
/** /**
* Get an attribute from the model. * @inheritdoc
*
* @param string $key
* @return mixed
*/ */
public function getAttribute($key) public function getAttribute($key)
{ {
...@@ -230,10 +141,7 @@ abstract class Model extends BaseModel ...@@ -230,10 +141,7 @@ abstract class Model extends BaseModel
} }
/** /**
* Get an attribute from the $attributes array. * @inheritdoc
*
* @param string $key
* @return mixed
*/ */
protected function getAttributeFromArray($key) protected function getAttributeFromArray($key)
{ {
...@@ -246,10 +154,7 @@ abstract class Model extends BaseModel ...@@ -246,10 +154,7 @@ abstract class Model extends BaseModel
} }
/** /**
* Set a given attribute on the model. * @inheritdoc
*
* @param string $key
* @param mixed $value
*/ */
public function setAttribute($key, $value) public function setAttribute($key, $value)
{ {
...@@ -258,9 +163,7 @@ abstract class Model extends BaseModel ...@@ -258,9 +163,7 @@ abstract class Model extends BaseModel
$builder = $this->newBaseQueryBuilder(); $builder = $this->newBaseQueryBuilder();
$value = $builder->convertKey($value); $value = $builder->convertKey($value);
} } // Support keys in dot notation.
// Support keys in dot notation.
elseif (str_contains($key, '.')) { elseif (str_contains($key, '.')) {
if (in_array($key, $this->getDates()) && $value) { if (in_array($key, $this->getDates()) && $value) {
$value = $this->fromDateTime($value); $value = $this->fromDateTime($value);
...@@ -275,9 +178,7 @@ abstract class Model extends BaseModel ...@@ -275,9 +178,7 @@ abstract class Model extends BaseModel
} }
/** /**
* Convert the model's attributes to an array. * @inheritdoc
*
* @return array
*/ */
public function attributesToArray() public function attributesToArray()
{ {
...@@ -304,9 +205,7 @@ abstract class Model extends BaseModel ...@@ -304,9 +205,7 @@ abstract class Model extends BaseModel
} }
/** /**
* Get the casts array. * @inheritdoc
*
* @return array
*/ */
public function getCasts() public function getCasts()
{ {
...@@ -314,10 +213,7 @@ abstract class Model extends BaseModel ...@@ -314,10 +213,7 @@ abstract class Model extends BaseModel
} }
/** /**
* Determine if the new and old values for a given key are numerically equivalent. * @inheritdoc
*
* @param string $key
* @return bool
*/ */
protected function originalIsNumericallyEquivalent($key) protected function originalIsNumericallyEquivalent($key)
{ {
...@@ -338,7 +234,7 @@ abstract class Model extends BaseModel ...@@ -338,7 +234,7 @@ abstract class Model extends BaseModel
/** /**
* Remove one or more fields. * Remove one or more fields.
* *
* @param mixed $columns * @param mixed $columns
* @return int * @return int
*/ */
public function drop($columns) public function drop($columns)
...@@ -357,9 +253,7 @@ abstract class Model extends BaseModel ...@@ -357,9 +253,7 @@ abstract class Model extends BaseModel
} }
/** /**
* Append one or more values to an array. * @inheritdoc
*
* @return mixed
*/ */
public function push() public function push()
{ {
...@@ -390,8 +284,8 @@ abstract class Model extends BaseModel ...@@ -390,8 +284,8 @@ abstract class Model extends BaseModel
/** /**
* Remove one or more values from an array. * Remove one or more values from an array.
* *
* @param string $column * @param string $column
* @param mixed $values * @param mixed $values
* @return mixed * @return mixed
*/ */
public function pull($column, $values) public function pull($column, $values)
...@@ -411,9 +305,9 @@ abstract class Model extends BaseModel ...@@ -411,9 +305,9 @@ abstract class Model extends BaseModel
/** /**
* Append one or more values to the underlying attribute value and sync with original. * Append one or more values to the underlying attribute value and sync with original.
* *
* @param string $column * @param string $column
* @param array $values * @param array $values
* @param bool $unique * @param bool $unique
*/ */
protected function pushAttributeValues($column, array $values, $unique = false) protected function pushAttributeValues($column, array $values, $unique = false)
{ {
...@@ -436,8 +330,8 @@ abstract class Model extends BaseModel ...@@ -436,8 +330,8 @@ abstract class Model extends BaseModel
/** /**
* Remove one or more values to the underlying attribute value and sync with original. * Remove one or more values to the underlying attribute value and sync with original.
* *
* @param string $column * @param string $column
* @param array $values * @param array $values
*/ */
protected function pullAttributeValues($column, array $values) protected function pullAttributeValues($column, array $values)
{ {
...@@ -459,7 +353,7 @@ abstract class Model extends BaseModel ...@@ -459,7 +353,7 @@ abstract class Model extends BaseModel
/** /**
* Set the parent relation. * Set the parent relation.
* *
* @param \Illuminate\Database\Eloquent\Relations\Relation $relation * @param \Illuminate\Database\Eloquent\Relations\Relation $relation
*/ */
public function setParentRelation(Relation $relation) public function setParentRelation(Relation $relation)
{ {
...@@ -477,10 +371,7 @@ abstract class Model extends BaseModel ...@@ -477,10 +371,7 @@ abstract class Model extends BaseModel
} }
/** /**
* Create a new Eloquent query builder for the model. * @inheritdoc
*
* @param \Jenssegers\Mongodb\Query\Builder $query
* @return \Jenssegers\Mongodb\Eloquent\Builder|static
*/ */
public function newEloquentBuilder($query) public function newEloquentBuilder($query)
{ {
...@@ -488,9 +379,7 @@ abstract class Model extends BaseModel ...@@ -488,9 +379,7 @@ abstract class Model extends BaseModel
} }
/** /**
* Get a new query builder instance for the connection. * @inheritdoc
*
* @return Builder
*/ */
protected function newBaseQueryBuilder() protected function newBaseQueryBuilder()
{ {
...@@ -498,12 +387,9 @@ abstract class Model extends BaseModel ...@@ -498,12 +387,9 @@ abstract class Model extends BaseModel
return new QueryBuilder($connection, $connection->getPostProcessor()); return new QueryBuilder($connection, $connection->getPostProcessor());
} }
/** /**
* We just return original key here in order to support keys in dot-notation * @inheritdoc
*
* @param string $key
* @return string
*/ */
protected function removeTableFromKey($key) protected function removeTableFromKey($key)
{ {
...@@ -511,11 +397,7 @@ abstract class Model extends BaseModel ...@@ -511,11 +397,7 @@ abstract class Model extends BaseModel
} }
/** /**
* Handle dynamic method calls into the method. * @inheritdoc
*
* @param string $method
* @param array $parameters
* @return mixed
*/ */
public function __call($method, $parameters) public function __call($method, $parameters)
{ {
......
...@@ -5,9 +5,7 @@ trait SoftDeletes ...@@ -5,9 +5,7 @@ trait SoftDeletes
use \Illuminate\Database\Eloquent\SoftDeletes; use \Illuminate\Database\Eloquent\SoftDeletes;
/** /**
* Get the fully qualified "deleted at" column. * @inheritdoc
*
* @return string
*/ */
public function getQualifiedDeletedAtColumn() public function getQualifiedDeletedAtColumn()
{ {
......
...@@ -6,9 +6,7 @@ use Jenssegers\Mongodb\Queue\Failed\MongoFailedJobProvider; ...@@ -6,9 +6,7 @@ use Jenssegers\Mongodb\Queue\Failed\MongoFailedJobProvider;
class MongodbQueueServiceProvider extends QueueServiceProvider class MongodbQueueServiceProvider extends QueueServiceProvider
{ {
/** /**
* Register the failed job services. * @inheritdoc
*
* @return void
*/ */
protected function registerFailedJobServices() protected function registerFailedJobServices()
{ {
......
...@@ -7,6 +7,7 @@ use Illuminate\Database\Query\Expression; ...@@ -7,6 +7,7 @@ use Illuminate\Database\Query\Expression;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Jenssegers\Mongodb\Connection; use Jenssegers\Mongodb\Connection;
use MongoCollection;
use MongoDB\BSON\ObjectID; use MongoDB\BSON\ObjectID;
use MongoDB\BSON\Regex; use MongoDB\BSON\Regex;
use MongoDB\BSON\UTCDateTime; use MongoDB\BSON\UTCDateTime;
...@@ -61,13 +62,46 @@ class Builder extends BaseBuilder ...@@ -61,13 +62,46 @@ class Builder extends BaseBuilder
* @var array * @var array
*/ */
public $operators = [ public $operators = [
'=', '<', '>', '<=', '>=', '<>', '!=', '=',
'like', 'not like', 'between', 'ilike', '<',
'&', '|', '^', '<<', '>>', '>',
'rlike', 'regexp', 'not regexp', '<=',
'exists', 'type', 'mod', 'where', 'all', 'size', 'regex', 'text', 'slice', 'elemmatch', '>=',
'geowithin', 'geointersects', 'near', 'nearsphere', 'geometry', '<>',
'maxdistance', 'center', 'centersphere', 'box', 'polygon', 'uniquedocs', '!=',
'like',
'not like',
'between',
'ilike',
'&',
'|',
'^',
'<<',
'>>',
'rlike',
'regexp',
'not regexp',
'exists',
'type',
'mod',
'where',
'all',
'size',
'regex',
'text',
'slice',
'elemmatch',
'geowithin',
'geointersects',
'near',
'nearsphere',
'geometry',
'maxdistance',
'center',
'centersphere',
'box',
'polygon',
'uniquedocs',
]; ];
/** /**
...@@ -76,12 +110,12 @@ class Builder extends BaseBuilder ...@@ -76,12 +110,12 @@ class Builder extends BaseBuilder
* @var array * @var array
*/ */
protected $conversion = [ protected $conversion = [
'=' => '=', '=' => '=',
'!=' => '$ne', '!=' => '$ne',
'<>' => '$ne', '<>' => '$ne',
'<' => '$lt', '<' => '$lt',
'<=' => '$lte', '<=' => '$lte',
'>' => '$gt', '>' => '$gt',
'>=' => '$gte', '>=' => '$gte',
]; ];
...@@ -93,10 +127,7 @@ class Builder extends BaseBuilder ...@@ -93,10 +127,7 @@ class Builder extends BaseBuilder
protected $useCollections; protected $useCollections;
/** /**
* Create a new query builder instance. * @inheritdoc
*
* @param Connection $connection
* @param Processor $processor
*/ */
public function __construct(Connection $connection, Processor $processor) public function __construct(Connection $connection, Processor $processor)
{ {
...@@ -105,7 +136,7 @@ class Builder extends BaseBuilder ...@@ -105,7 +136,7 @@ class Builder extends BaseBuilder
$this->processor = $processor; $this->processor = $processor;
$this->useCollections = $this->shouldUseCollections(); $this->useCollections = $this->shouldUseCollections();
} }
/** /**
* Returns true if Laravel or Lumen >= 5.3 * Returns true if Laravel or Lumen >= 5.3
* *
...@@ -123,7 +154,7 @@ class Builder extends BaseBuilder ...@@ -123,7 +154,7 @@ class Builder extends BaseBuilder
/** /**
* Set the projections. * Set the projections.
* *
* @param array $columns * @param array $columns
* @return $this * @return $this
*/ */
public function project($columns) public function project($columns)
...@@ -160,11 +191,7 @@ class Builder extends BaseBuilder ...@@ -160,11 +191,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Execute a query for a single record by ID. * @inheritdoc
*
* @param mixed $id
* @param array $columns
* @return mixed
*/ */
public function find($id, $columns = []) public function find($id, $columns = [])
{ {
...@@ -172,10 +199,7 @@ class Builder extends BaseBuilder ...@@ -172,10 +199,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Execute the query as a "select" statement. * @inheritdoc
*
* @param array $columns
* @return array|static[]|Collection
*/ */
public function get($columns = []) public function get($columns = [])
{ {
...@@ -185,7 +209,7 @@ class Builder extends BaseBuilder ...@@ -185,7 +209,7 @@ class Builder extends BaseBuilder
/** /**
* Execute the query as a fresh "select" statement. * Execute the query as a fresh "select" statement.
* *
* @param array $columns * @param array $columns
* @return array|static[]|Collection * @return array|static[]|Collection
*/ */
public function getFresh($columns = []) public function getFresh($columns = [])
...@@ -213,18 +237,18 @@ class Builder extends BaseBuilder ...@@ -213,18 +237,18 @@ class Builder extends BaseBuilder
// Add grouping columns to the $group part of the aggregation pipeline. // Add grouping columns to the $group part of the aggregation pipeline.
if ($this->groups) { if ($this->groups) {
foreach ($this->groups as $column) { foreach ($this->groups as $column) {
$group['_id'][$column] = '$' . $column; $group['_id'][$column] = '$'.$column;
// When grouping, also add the $last operator to each grouped field, // When grouping, also add the $last operator to each grouped field,
// this mimics MySQL's behaviour a bit. // this mimics MySQL's behaviour a bit.
$group[$column] = ['$last' => '$' . $column]; $group[$column] = ['$last' => '$'.$column];
} }
// Do the same for other columns that are selected. // Do the same for other columns that are selected.
foreach ($this->columns as $column) { foreach ($this->columns as $column) {
$key = str_replace('.', '_', $column); $key = str_replace('.', '_', $column);
$group[$key] = ['$last' => '$' . $column]; $group[$key] = ['$last' => '$'.$column];
} }
} }
...@@ -244,10 +268,9 @@ class Builder extends BaseBuilder ...@@ -244,10 +268,9 @@ class Builder extends BaseBuilder
// Translate count into sum. // Translate count into sum.
if ($function == 'count') { if ($function == 'count') {
$group['aggregate'] = ['$sum' => 1]; $group['aggregate'] = ['$sum' => 1];
} } // Pass other functions directly.
// Pass other functions directly.
else { else {
$group['aggregate'] = ['$' . $function => '$' . $column]; $group['aggregate'] = ['$'.$function => '$'.$column];
} }
} }
} }
...@@ -273,7 +296,7 @@ class Builder extends BaseBuilder ...@@ -273,7 +296,7 @@ class Builder extends BaseBuilder
// apply unwinds for subdocument array aggregation // apply unwinds for subdocument array aggregation
foreach ($unwinds as $unwind) { foreach ($unwinds as $unwind) {
$pipeline[] = ['$unwind' => '$' . $unwind]; $pipeline[] = ['$unwind' => '$'.$unwind];
} }
if ($group) { if ($group) {
...@@ -308,9 +331,7 @@ class Builder extends BaseBuilder ...@@ -308,9 +331,7 @@ class Builder extends BaseBuilder
// Return results // Return results
return $this->useCollections ? new Collection($results) : $results; return $this->useCollections ? new Collection($results) : $results;
} } // Distinct query
// Distinct query
elseif ($this->distinct) { elseif ($this->distinct) {
// Return distinct results directly // Return distinct results directly
$column = isset($this->columns[0]) ? $this->columns[0] : '_id'; $column = isset($this->columns[0]) ? $this->columns[0] : '_id';
...@@ -323,9 +344,7 @@ class Builder extends BaseBuilder ...@@ -323,9 +344,7 @@ class Builder extends BaseBuilder
} }
return $this->useCollections ? new Collection($result) : $result; return $this->useCollections ? new Collection($result) : $result;
} } // Normal query
// Normal query
else { else {
$columns = []; $columns = [];
...@@ -385,24 +404,20 @@ class Builder extends BaseBuilder ...@@ -385,24 +404,20 @@ class Builder extends BaseBuilder
$key = [ $key = [
'connection' => $this->collection->getDatabaseName(), 'connection' => $this->collection->getDatabaseName(),
'collection' => $this->collection->getCollectionName(), 'collection' => $this->collection->getCollectionName(),
'wheres' => $this->wheres, 'wheres' => $this->wheres,
'columns' => $this->columns, 'columns' => $this->columns,
'groups' => $this->groups, 'groups' => $this->groups,
'orders' => $this->orders, 'orders' => $this->orders,
'offset' => $this->offset, 'offset' => $this->offset,
'limit' => $this->limit, 'limit' => $this->limit,
'aggregate' => $this->aggregate, 'aggregate' => $this->aggregate,
]; ];
return md5(serialize(array_values($key))); return md5(serialize(array_values($key)));
} }
/** /**
* Execute an aggregate function on the database. * @inheritdoc
*
* @param string $function
* @param array $columns
* @return mixed
*/ */
public function aggregate($function, $columns = []) public function aggregate($function, $columns = [])
{ {
...@@ -424,9 +439,7 @@ class Builder extends BaseBuilder ...@@ -424,9 +439,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Determine if any rows exist for the current query. * @inheritdoc
*
* @return bool
*/ */
public function exists() public function exists()
{ {
...@@ -434,9 +447,7 @@ class Builder extends BaseBuilder ...@@ -434,9 +447,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Force the query to only return distinct results. * @inheritdoc
*
* @return Builder
*/ */
public function distinct($column = false) public function distinct($column = false)
{ {
...@@ -450,11 +461,7 @@ class Builder extends BaseBuilder ...@@ -450,11 +461,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Add an "order by" clause to the query. * @inheritdoc
*
* @param string $column
* @param string $direction
* @return Builder
*/ */
public function orderBy($column, $direction = 'asc') public function orderBy($column, $direction = 'asc')
{ {
...@@ -472,13 +479,7 @@ class Builder extends BaseBuilder ...@@ -472,13 +479,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Add a where between statement to the query. * @inheritdoc
*
* @param string $column
* @param array $values
* @param string $boolean
* @param bool $not
* @return Builder
*/ */
public function whereBetween($column, array $values, $boolean = 'and', $not = false) public function whereBetween($column, array $values, $boolean = 'and', $not = false)
{ {
...@@ -490,11 +491,7 @@ class Builder extends BaseBuilder ...@@ -490,11 +491,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Set the limit and offset for a given page. * @inheritdoc
*
* @param int $page
* @param int $perPage
* @return \Illuminate\Database\Query\Builder|static
*/ */
public function forPage($page, $perPage = 15) public function forPage($page, $perPage = 15)
{ {
...@@ -504,10 +501,7 @@ class Builder extends BaseBuilder ...@@ -504,10 +501,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Insert a new record into the database. * @inheritdoc
*
* @param array $values
* @return bool
*/ */
public function insert(array $values) public function insert(array $values)
{ {
...@@ -535,11 +529,7 @@ class Builder extends BaseBuilder ...@@ -535,11 +529,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Insert a new record and get the value of the primary key. * @inheritdoc
*
* @param array $values
* @param string $sequence
* @return int
*/ */
public function insertGetId(array $values, $sequence = null) public function insertGetId(array $values, $sequence = null)
{ {
...@@ -556,11 +546,7 @@ class Builder extends BaseBuilder ...@@ -556,11 +546,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Update a record in the database. * @inheritdoc
*
* @param array $values
* @param array $options
* @return int
*/ */
public function update(array $values, array $options = []) public function update(array $values, array $options = [])
{ {
...@@ -573,12 +559,7 @@ class Builder extends BaseBuilder ...@@ -573,12 +559,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Increment a column's value by a given amount. * @inheritdoc
*
* @param string $column
* @param int $amount
* @param array $extra
* @return int
*/ */
public function increment($column, $amount = 1, array $extra = [], array $options = []) public function increment($column, $amount = 1, array $extra = [], array $options = [])
{ {
...@@ -599,12 +580,7 @@ class Builder extends BaseBuilder ...@@ -599,12 +580,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Decrement a column's value by a given amount. * @inheritdoc
*
* @param string $column
* @param int $amount
* @param array $extra
* @return int
*/ */
public function decrement($column, $amount = 1, array $extra = [], array $options = []) public function decrement($column, $amount = 1, array $extra = [], array $options = [])
{ {
...@@ -612,11 +588,7 @@ class Builder extends BaseBuilder ...@@ -612,11 +588,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Get an array with the values of a given column. * @inheritdoc
*
* @param string $column
* @param string|null $key
* @return array
*/ */
public function pluck($column, $key = null) public function pluck($column, $key = null)
{ {
...@@ -635,10 +607,7 @@ class Builder extends BaseBuilder ...@@ -635,10 +607,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Delete a record from the database. * @inheritdoc
*
* @param mixed $id
* @return int
*/ */
public function delete($id = null) public function delete($id = null)
{ {
...@@ -652,10 +621,7 @@ class Builder extends BaseBuilder ...@@ -652,10 +621,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Set the collection which the query is targeting. * @inheritdoc
*
* @param string $collection
* @return Builder
*/ */
public function from($collection) public function from($collection)
{ {
...@@ -667,7 +633,7 @@ class Builder extends BaseBuilder ...@@ -667,7 +633,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Run a truncate statement on the table. * @inheritdoc
*/ */
public function truncate() public function truncate()
{ {
...@@ -680,8 +646,8 @@ class Builder extends BaseBuilder ...@@ -680,8 +646,8 @@ class Builder extends BaseBuilder
* Get an array with the values of a given column. * Get an array with the values of a given column.
* *
* @deprecated * @deprecated
* @param string $column * @param string $column
* @param string $key * @param string $key
* @return array * @return array
*/ */
public function lists($column, $key = null) public function lists($column, $key = null)
...@@ -690,19 +656,14 @@ class Builder extends BaseBuilder ...@@ -690,19 +656,14 @@ class Builder extends BaseBuilder
} }
/** /**
* Create a raw database expression. * @inheritdoc
*
* @param closure $expression
* @return mixed
*/ */
public function raw($expression = null) public function raw($expression = null)
{ {
// Execute the closure on the mongodb collection // Execute the closure on the mongodb collection
if ($expression instanceof Closure) { if ($expression instanceof Closure) {
return call_user_func($expression, $this->collection); return call_user_func($expression, $this->collection);
} } // Create an expression for the given value
// Create an expression for the given value
elseif (! is_null($expression)) { elseif (! is_null($expression)) {
return new Expression($expression); return new Expression($expression);
} }
...@@ -714,8 +675,9 @@ class Builder extends BaseBuilder ...@@ -714,8 +675,9 @@ class Builder extends BaseBuilder
/** /**
* Append one or more values to an array. * Append one or more values to an array.
* *
* @param mixed $column * @param mixed $column
* @param mixed $value * @param mixed $value
* @param bool $unique
* @return int * @return int
*/ */
public function push($column, $value = null, $unique = false) public function push($column, $value = null, $unique = false)
...@@ -740,8 +702,8 @@ class Builder extends BaseBuilder ...@@ -740,8 +702,8 @@ class Builder extends BaseBuilder
/** /**
* Remove one or more values from an array. * Remove one or more values from an array.
* *
* @param mixed $column * @param mixed $column
* @param mixed $value * @param mixed $value
* @return int * @return int
*/ */
public function pull($column, $value = null) public function pull($column, $value = null)
...@@ -785,9 +747,7 @@ class Builder extends BaseBuilder ...@@ -785,9 +747,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Get a new instance of the query builder. * @inheritdoc
*
* @return Builder
*/ */
public function newQuery() public function newQuery()
{ {
...@@ -797,8 +757,8 @@ class Builder extends BaseBuilder ...@@ -797,8 +757,8 @@ class Builder extends BaseBuilder
/** /**
* Perform an update query. * Perform an update query.
* *
* @param array $query * @param array $query
* @param array $options * @param array $options
* @return int * @return int
*/ */
protected function performUpdate($query, array $options = []) protected function performUpdate($query, array $options = [])
...@@ -833,15 +793,7 @@ class Builder extends BaseBuilder ...@@ -833,15 +793,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Add a basic where clause to the query. * @inheritdoc
*
* @param string $column
* @param string $operator
* @param mixed $value
* @param string $boolean
* @return \Illuminate\Database\Query\Builder|static
*
* @throws \InvalidArgumentException
*/ */
public function where($column, $operator = null, $value = null, $boolean = 'and') public function where($column, $operator = null, $value = null, $boolean = 'and')
{ {
...@@ -879,14 +831,14 @@ class Builder extends BaseBuilder ...@@ -879,14 +831,14 @@ class Builder extends BaseBuilder
// Operator conversions // Operator conversions
$convert = [ $convert = [
'regexp' => 'regex', 'regexp' => 'regex',
'elemmatch' => 'elemMatch', 'elemmatch' => 'elemMatch',
'geointersects' => 'geoIntersects', 'geointersects' => 'geoIntersects',
'geowithin' => 'geoWithin', 'geowithin' => 'geoWithin',
'nearsphere' => 'nearSphere', 'nearsphere' => 'nearSphere',
'maxdistance' => 'maxDistance', 'maxdistance' => 'maxDistance',
'centersphere' => 'centerSphere', 'centersphere' => 'centerSphere',
'uniquedocs' => 'uniqueDocs', 'uniquedocs' => 'uniqueDocs',
]; ];
if (array_key_exists($where['operator'], $convert)) { if (array_key_exists($where['operator'], $convert)) {
...@@ -901,9 +853,7 @@ class Builder extends BaseBuilder ...@@ -901,9 +853,7 @@ class Builder extends BaseBuilder
foreach ($where['values'] as &$value) { foreach ($where['values'] as &$value) {
$value = $this->convertKey($value); $value = $this->convertKey($value);
} }
} } // Single value.
// Single value.
elseif (isset($where['value'])) { elseif (isset($where['value'])) {
$where['value'] = $this->convertKey($where['value']); $where['value'] = $this->convertKey($where['value']);
} }
...@@ -953,7 +903,11 @@ class Builder extends BaseBuilder ...@@ -953,7 +903,11 @@ class Builder extends BaseBuilder
return $compiled; return $compiled;
} }
protected function compileWhereBasic($where) /**
* @param array $where
* @return array
*/
protected function compileWhereBasic(array $where)
{ {
extract($where); extract($where);
...@@ -966,16 +920,14 @@ class Builder extends BaseBuilder ...@@ -966,16 +920,14 @@ class Builder extends BaseBuilder
// Convert like to regular expression. // Convert like to regular expression.
if (! starts_with($value, '%')) { if (! starts_with($value, '%')) {
$regex = '^' . $regex; $regex = '^'.$regex;
} }
if (! ends_with($value, '%')) { if (! ends_with($value, '%')) {
$regex = $regex . '$'; $regex = $regex.'$';
} }
$value = new Regex($regex, 'i'); $value = new Regex($regex, 'i');
} } // Manipulate regexp operations.
// Manipulate regexp operations.
elseif (in_array($operator, ['regexp', 'not regexp', 'regex', 'not regex'])) { elseif (in_array($operator, ['regexp', 'not regexp', 'regex', 'not regex'])) {
// Automatically convert regular expression strings to Regex objects. // Automatically convert regular expression strings to Regex objects.
if (! $value instanceof Regex) { if (! $value instanceof Regex) {
...@@ -997,34 +949,50 @@ class Builder extends BaseBuilder ...@@ -997,34 +949,50 @@ class Builder extends BaseBuilder
} elseif (array_key_exists($operator, $this->conversion)) { } elseif (array_key_exists($operator, $this->conversion)) {
$query = [$column => [$this->conversion[$operator] => $value]]; $query = [$column => [$this->conversion[$operator] => $value]];
} else { } else {
$query = [$column => ['$' . $operator => $value]]; $query = [$column => ['$'.$operator => $value]];
} }
return $query; return $query;
} }
protected function compileWhereNested($where) /**
* @param array $where
* @return mixed
*/
protected function compileWhereNested(array $where)
{ {
extract($where); extract($where);
return $query->compileWheres(); return $query->compileWheres();
} }
protected function compileWhereIn($where) /**
* @param array $where
* @return array
*/
protected function compileWhereIn(array $where)
{ {
extract($where); extract($where);
return [$column => ['$in' => array_values($values)]]; return [$column => ['$in' => array_values($values)]];
} }
protected function compileWhereNotIn($where) /**
* @param array $where
* @return array
*/
protected function compileWhereNotIn(array $where)
{ {
extract($where); extract($where);
return [$column => ['$nin' => array_values($values)]]; return [$column => ['$nin' => array_values($values)]];
} }
protected function compileWhereNull($where) /**
* @param array $where
* @return array
*/
protected function compileWhereNull(array $where)
{ {
$where['operator'] = '='; $where['operator'] = '=';
$where['value'] = null; $where['value'] = null;
...@@ -1032,7 +1000,11 @@ class Builder extends BaseBuilder ...@@ -1032,7 +1000,11 @@ class Builder extends BaseBuilder
return $this->compileWhereBasic($where); return $this->compileWhereBasic($where);
} }
protected function compileWhereNotNull($where) /**
* @param array $where
* @return array
*/
protected function compileWhereNotNull(array $where)
{ {
$where['operator'] = '!='; $where['operator'] = '!=';
$where['value'] = null; $where['value'] = null;
...@@ -1040,7 +1012,11 @@ class Builder extends BaseBuilder ...@@ -1040,7 +1012,11 @@ class Builder extends BaseBuilder
return $this->compileWhereBasic($where); return $this->compileWhereBasic($where);
} }
protected function compileWhereBetween($where) /**
* @param array $where
* @return array
*/
protected function compileWhereBetween(array $where)
{ {
extract($where); extract($where);
...@@ -1069,7 +1045,11 @@ class Builder extends BaseBuilder ...@@ -1069,7 +1045,11 @@ class Builder extends BaseBuilder
} }
} }
protected function compileWhereRaw($where) /**
* @param array $where
* @return mixed
*/
protected function compileWhereRaw(array $where)
{ {
return $where['sql']; return $where['sql'];
} }
...@@ -1077,7 +1057,7 @@ class Builder extends BaseBuilder ...@@ -1077,7 +1057,7 @@ class Builder extends BaseBuilder
/** /**
* Set custom options for the query. * Set custom options for the query.
* *
* @param array $options * @param array $options
* @return $this * @return $this
*/ */
public function options(array $options) public function options(array $options)
...@@ -1088,11 +1068,7 @@ class Builder extends BaseBuilder ...@@ -1088,11 +1068,7 @@ class Builder extends BaseBuilder
} }
/** /**
* Handle dynamic method calls into the method. * @inheritdoc
*
* @param string $method
* @param array $parameters
* @return mixed
*/ */
public function __call($method, $parameters) public function __call($method, $parameters)
{ {
......
<?php namespace Jenssegers\Mongodb\Queue;
use Illuminate\Queue\Jobs\DatabaseJob;
class MongoJob extends DatabaseJob
{
/**
* Indicates if the job has been reserved.
*
* @return bool
*/
public function isReserved()
{
return $this->job->reserved;
}
/**
* @return \DateTime
*/
public function reservedAt()
{
return $this->job->reserved_at;
}
}
...@@ -8,22 +8,19 @@ use MongoDB\Operation\FindOneAndUpdate; ...@@ -8,22 +8,19 @@ use MongoDB\Operation\FindOneAndUpdate;
class MongoQueue extends DatabaseQueue class MongoQueue extends DatabaseQueue
{ {
/** /**
* Pop the next job off of the queue. * @inheritdoc
*
* @param string $queue
* @return \Illuminate\Contracts\Queue\Job|null
*/ */
public function pop($queue = null) public function pop($queue = null)
{ {
$queue = $this->getQueue($queue); $queue = $this->getQueue($queue);
if (!is_null($this->expire)) { if (! is_null($this->retryAfter)) {
$this->releaseJobsThatHaveBeenReservedTooLong($queue); $this->releaseJobsThatHaveBeenReservedTooLong($queue);
} }
if ($job = $this->getNextAvailableJobAndReserve($queue)) { if ($job = $this->getNextAvailableJobAndReserve($queue)) {
return new DatabaseJob( return new MongoJob(
$this->container, $this, $job, $queue $this->container, $this, $job, $this->connectionName, $queue
); );
} }
} }
...@@ -47,20 +44,19 @@ class MongoQueue extends DatabaseQueue ...@@ -47,20 +44,19 @@ class MongoQueue extends DatabaseQueue
{ {
$job = $this->database->getCollection($this->table)->findOneAndUpdate( $job = $this->database->getCollection($this->table)->findOneAndUpdate(
[ [
'queue' => $this->getQueue($queue), 'queue' => $this->getQueue($queue),
'reserved' => 0, 'reserved' => 0,
'available_at' => ['$lte' => $this->getTime()], 'available_at' => ['$lte' => Carbon::now()->getTimestamp()],
], ],
[ [
'$set' => [ '$set' => [
'reserved' => 1, 'reserved' => 1,
'reserved_at' => $this->getTime(), 'reserved_at' => Carbon::now()->getTimestamp(),
], ],
], ],
[ [
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER, 'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER,
'sort' => ['available_at' => 1], 'sort' => ['available_at' => 1],
] ]
); );
...@@ -74,12 +70,12 @@ class MongoQueue extends DatabaseQueue ...@@ -74,12 +70,12 @@ class MongoQueue extends DatabaseQueue
/** /**
* Release the jobs that have been reserved for too long. * Release the jobs that have been reserved for too long.
* *
* @param string $queue * @param string $queue
* @return void * @return void
*/ */
protected function releaseJobsThatHaveBeenReservedTooLong($queue) protected function releaseJobsThatHaveBeenReservedTooLong($queue)
{ {
$expiration = Carbon::now()->subSeconds($this->expire)->getTimestamp(); $expiration = Carbon::now()->subSeconds($this->retryAfter)->getTimestamp();
$now = time(); $now = time();
$reserved = $this->database->collection($this->table) $reserved = $this->database->collection($this->table)
...@@ -105,24 +101,20 @@ class MongoQueue extends DatabaseQueue ...@@ -105,24 +101,20 @@ class MongoQueue extends DatabaseQueue
* Release the given job ID from reservation. * Release the given job ID from reservation.
* *
* @param string $id * @param string $id
* @param int $attempts * @param int $attempts
* @return void * @return void
*/ */
protected function releaseJob($id, $attempts) protected function releaseJob($id, $attempts)
{ {
$this->database->table($this->table)->where('_id', $id)->update([ $this->database->table($this->table)->where('_id', $id)->update([
'reserved' => 0, 'reserved' => 0,
'reserved_at' => null, 'reserved_at' => null,
'attempts' => $attempts, 'attempts' => $attempts,
]); ]);
} }
/** /**
* Delete a reserved job from the queue. * @inheritdoc
*
* @param string $queue
* @param string $id
* @return void
*/ */
public function deleteReserved($queue, $id) public function deleteReserved($queue, $id)
{ {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo
{ {
/** /**
* Set the base constraints on the relation query. * @inheritdoc
*/ */
public function addConstraints() public function addConstraints()
{ {
...@@ -16,9 +16,7 @@ class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo ...@@ -16,9 +16,7 @@ class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo
} }
/** /**
* Set the constraints for an eager load of the relation. * @inheritdoc
*
* @param array $models
*/ */
public function addEagerConstraints(array $models) public function addEagerConstraints(array $models)
{ {
......
...@@ -7,9 +7,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany as EloquentBelongsToMan ...@@ -7,9 +7,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany as EloquentBelongsToMan
class BelongsToMany extends EloquentBelongsToMany class BelongsToMany extends EloquentBelongsToMany
{ {
/** /**
* Hydrate the pivot table relationship on the models. * @inheritdoc
*
* @param array $models
*/ */
protected function hydratePivotRelation(array $models) protected function hydratePivotRelation(array $models)
{ {
...@@ -19,8 +17,8 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -19,8 +17,8 @@ class BelongsToMany extends EloquentBelongsToMany
/** /**
* Set the select clause for the relation query. * Set the select clause for the relation query.
* *
* @param array $columns * @param array $columns
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany * @return array
*/ */
protected function getSelectColumns(array $columns = ['*']) protected function getSelectColumns(array $columns = ['*'])
{ {
...@@ -28,7 +26,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -28,7 +26,7 @@ class BelongsToMany extends EloquentBelongsToMany
} }
/** /**
* Set the base constraints on the relation query. * @inheritdoc
*/ */
public function addConstraints() public function addConstraints()
{ {
...@@ -52,12 +50,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -52,12 +50,7 @@ class BelongsToMany extends EloquentBelongsToMany
} }
/** /**
* Save a new model and attach it to the parent model. * @inheritdoc
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param array $joining
* @param bool $touch
* @return \Illuminate\Database\Eloquent\Model
*/ */
public function save(Model $model, array $joining = [], $touch = true) public function save(Model $model, array $joining = [], $touch = true)
{ {
...@@ -69,12 +62,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -69,12 +62,7 @@ class BelongsToMany extends EloquentBelongsToMany
} }
/** /**
* Create a new instance of the related model. * @inheritdoc
*
* @param array $attributes
* @param array $joining
* @param bool $touch
* @return \Illuminate\Database\Eloquent\Model
*/ */
public function create(array $attributes, array $joining = [], $touch = true) public function create(array $attributes, array $joining = [], $touch = true)
{ {
...@@ -91,16 +79,14 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -91,16 +79,14 @@ class BelongsToMany extends EloquentBelongsToMany
} }
/** /**
* Sync the intermediate tables with a list of IDs or collection of models. * @inheritdoc
*
* @param array $ids
* @param bool $detaching
* @return array
*/ */
public function sync($ids, $detaching = true) public function sync($ids, $detaching = true)
{ {
$changes = [ $changes = [
'attached' => [], 'detached' => [], 'updated' => [], 'attached' => [],
'detached' => [],
'updated' => [],
]; ];
if ($ids instanceof Collection) { if ($ids instanceof Collection) {
...@@ -151,11 +137,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -151,11 +137,7 @@ class BelongsToMany extends EloquentBelongsToMany
} }
/** /**
* Update an existing pivot record on the table. * @inheritdoc
*
* @param mixed $id
* @param array $attributes
* @param bool $touch
*/ */
public function updateExistingPivot($id, array $attributes, $touch = true) public function updateExistingPivot($id, array $attributes, $touch = true)
{ {
...@@ -163,11 +145,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -163,11 +145,7 @@ class BelongsToMany extends EloquentBelongsToMany
} }
/** /**
* Attach a model to the parent. * @inheritdoc
*
* @param mixed $id
* @param array $attributes
* @param bool $touch
*/ */
public function attach($id, array $attributes = [], $touch = true) public function attach($id, array $attributes = [], $touch = true)
{ {
...@@ -200,11 +178,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -200,11 +178,7 @@ class BelongsToMany extends EloquentBelongsToMany
} }
/** /**
* Detach models from the relationship. * @inheritdoc
*
* @param int|array $ids
* @param bool $touch
* @return int
*/ */
public function detach($ids = [], $touch = true) public function detach($ids = [], $touch = true)
{ {
...@@ -238,10 +212,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -238,10 +212,7 @@ class BelongsToMany extends EloquentBelongsToMany
} }
/** /**
* Build model dictionary keyed by the relation's foreign key. * @inheritdoc
*
* @param \Illuminate\Database\Eloquent\Collection $results
* @return array
*/ */
protected function buildDictionary(Collection $results) protected function buildDictionary(Collection $results)
{ {
...@@ -262,9 +233,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -262,9 +233,7 @@ class BelongsToMany extends EloquentBelongsToMany
} }
/** /**
* Create a new query builder for the related model. * @inheritdoc
*
* @return \Illuminate\Database\Query\Builder
*/ */
protected function newPivotQuery() protected function newPivotQuery()
{ {
...@@ -296,7 +265,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -296,7 +265,7 @@ class BelongsToMany extends EloquentBelongsToMany
* The original function has been renamed to formatRecordsList since Laravel 5.3 * The original function has been renamed to formatRecordsList since Laravel 5.3
* *
* @deprecated * @deprecated
* @param array $records * @param array $records
* @return array * @return array
*/ */
protected function formatSyncList(array $records) protected function formatSyncList(array $records)
......
<?php namespace Jenssegers\Mongodb\Relations; <?php namespace Jenssegers\Mongodb\Relations;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator; use Illuminate\Pagination\Paginator;
...@@ -8,10 +9,7 @@ use MongoDB\BSON\ObjectID; ...@@ -8,10 +9,7 @@ use MongoDB\BSON\ObjectID;
class EmbedsMany extends EmbedsOneOrMany class EmbedsMany extends EmbedsOneOrMany
{ {
/** /**
* Initialize the relation on a set of models. * @inheritdoc
*
* @param array $models
* @param string $relation
*/ */
public function initRelation(array $models, $relation) public function initRelation(array $models, $relation)
{ {
...@@ -23,9 +21,7 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -23,9 +21,7 @@ class EmbedsMany extends EmbedsOneOrMany
} }
/** /**
* Get the results of the relationship. * @inheritdoc
*
* @return \Illuminate\Database\Eloquent\Collection
*/ */
public function getResults() public function getResults()
{ {
...@@ -35,8 +31,8 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -35,8 +31,8 @@ class EmbedsMany extends EmbedsOneOrMany
/** /**
* Save a new model and attach it to the parent model. * Save a new model and attach it to the parent model.
* *
* @param \Illuminate\Database\Eloquent\Model $model * @param Model $model
* @return \Illuminate\Database\Eloquent\Model * @return Model|bool
*/ */
public function performInsert(Model $model) public function performInsert(Model $model)
{ {
...@@ -48,8 +44,7 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -48,8 +44,7 @@ class EmbedsMany extends EmbedsOneOrMany
// For deeply nested documents, let the parent handle the changes. // For deeply nested documents, let the parent handle the changes.
if ($this->isNested()) { if ($this->isNested()) {
$this->associate($model); $this->associate($model);
return $this->parent->save() ? $model : false;
return $this->parent->save();
} }
// Push the new model to the database. // Push the new model to the database.
...@@ -66,7 +61,7 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -66,7 +61,7 @@ class EmbedsMany extends EmbedsOneOrMany
/** /**
* Save an existing model and attach it to the parent model. * Save an existing model and attach it to the parent model.
* *
* @param \Illuminate\Database\Eloquent\Model $model * @param Model $model
* @return Model|bool * @return Model|bool
*/ */
public function performUpdate(Model $model) public function performUpdate(Model $model)
...@@ -82,11 +77,11 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -82,11 +77,11 @@ class EmbedsMany extends EmbedsOneOrMany
$foreignKey = $this->getForeignKeyValue($model); $foreignKey = $this->getForeignKeyValue($model);
// Use array dot notation for better update behavior. // Use array dot notation for better update behavior.
$values = array_dot($model->getDirty(), $this->localKey . '.$.'); $values = array_dot($model->getDirty(), $this->localKey.'.$.');
// Update document in database. // Update document in database.
$result = $this->getBaseQuery()->where($this->localKey . '.' . $model->getKeyName(), $foreignKey) $result = $this->getBaseQuery()->where($this->localKey.'.'.$model->getKeyName(), $foreignKey)
->update($values); ->update($values);
// Attach the model to its parent. // Attach the model to its parent.
if ($result) { if ($result) {
...@@ -99,7 +94,7 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -99,7 +94,7 @@ class EmbedsMany extends EmbedsOneOrMany
/** /**
* Delete an existing model and detach it from the parent model. * Delete an existing model and detach it from the parent model.
* *
* @param Model $model * @param Model $model
* @return int * @return int
*/ */
public function performDelete(Model $model) public function performDelete(Model $model)
...@@ -126,8 +121,8 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -126,8 +121,8 @@ class EmbedsMany extends EmbedsOneOrMany
/** /**
* Associate the model instance to the given parent, without saving it to the database. * Associate the model instance to the given parent, without saving it to the database.
* *
* @param \Illuminate\Database\Eloquent\Model $model * @param Model $model
* @return \Illuminate\Database\Eloquent\Model * @return Model
*/ */
public function associate(Model $model) public function associate(Model $model)
{ {
...@@ -141,7 +136,7 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -141,7 +136,7 @@ class EmbedsMany extends EmbedsOneOrMany
/** /**
* Dissociate the model instance from the given parent, without saving it to the database. * Dissociate the model instance from the given parent, without saving it to the database.
* *
* @param mixed $ids * @param mixed $ids
* @return int * @return int
*/ */
public function dissociate($ids = []) public function dissociate($ids = [])
...@@ -170,7 +165,7 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -170,7 +165,7 @@ class EmbedsMany extends EmbedsOneOrMany
/** /**
* Destroy the embedded models for the given IDs. * Destroy the embedded models for the given IDs.
* *
* @param mixed $ids * @param mixed $ids
* @return int * @return int
*/ */
public function destroy($ids = []) public function destroy($ids = [])
...@@ -212,7 +207,7 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -212,7 +207,7 @@ class EmbedsMany extends EmbedsOneOrMany
/** /**
* Destroy alias. * Destroy alias.
* *
* @param mixed $ids * @param mixed $ids
* @return int * @return int
*/ */
public function detach($ids = []) public function detach($ids = [])
...@@ -223,8 +218,8 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -223,8 +218,8 @@ class EmbedsMany extends EmbedsOneOrMany
/** /**
* Save alias. * Save alias.
* *
* @param \Illuminate\Database\Eloquent\Model $model * @param Model $model
* @return \Illuminate\Database\Eloquent\Model * @return Model
*/ */
public function attach(Model $model) public function attach(Model $model)
{ {
...@@ -234,8 +229,8 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -234,8 +229,8 @@ class EmbedsMany extends EmbedsOneOrMany
/** /**
* Associate a new model instance to the given parent, without saving it to the database. * Associate a new model instance to the given parent, without saving it to the database.
* *
* @param \Illuminate\Database\Eloquent\Model $model * @param Model $model
* @return \Illuminate\Database\Eloquent\Model * @return Model
*/ */
protected function associateNew($model) protected function associateNew($model)
{ {
...@@ -255,8 +250,8 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -255,8 +250,8 @@ class EmbedsMany extends EmbedsOneOrMany
/** /**
* Associate an existing model instance to the given parent, without saving it to the database. * Associate an existing model instance to the given parent, without saving it to the database.
* *
* @param \Illuminate\Database\Eloquent\Model $model * @param Model $model
* @return \Illuminate\Database\Eloquent\Model * @return Model
*/ */
protected function associateExisting($model) protected function associateExisting($model)
{ {
...@@ -281,8 +276,8 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -281,8 +276,8 @@ class EmbedsMany extends EmbedsOneOrMany
/** /**
* Get a paginator for the "select" statement. * Get a paginator for the "select" statement.
* *
* @param int $perPage * @param int $perPage
* @return \Illuminate\Pagination\Paginator * @return \Illuminate\Pagination\AbstractPaginator
*/ */
public function paginate($perPage = null) public function paginate($perPage = null)
{ {
...@@ -302,9 +297,7 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -302,9 +297,7 @@ class EmbedsMany extends EmbedsOneOrMany
} }
/** /**
* Get the embedded records array. * @inheritdoc
*
* @return array
*/ */
protected function getEmbedded() protected function getEmbedded()
{ {
...@@ -312,9 +305,7 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -312,9 +305,7 @@ class EmbedsMany extends EmbedsOneOrMany
} }
/** /**
* Set the embedded records array. * @inheritdoc
*
* @param array $models
*/ */
protected function setEmbedded($models) protected function setEmbedded($models)
{ {
...@@ -326,15 +317,11 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -326,15 +317,11 @@ class EmbedsMany extends EmbedsOneOrMany
} }
/** /**
* Handle dynamic method calls to the relationship. * @inheritdoc
*
* @param string $method
* @param array $parameters
* @return mixed
*/ */
public function __call($method, $parameters) public function __call($method, $parameters)
{ {
if (method_exists('Illuminate\Database\Eloquent\Collection', $method)) { if (method_exists(Collection::class, $method)) {
return call_user_func_array([$this->getResults(), $method], $parameters); return call_user_func_array([$this->getResults(), $method], $parameters);
} }
......
...@@ -6,10 +6,7 @@ use MongoDB\BSON\ObjectID; ...@@ -6,10 +6,7 @@ use MongoDB\BSON\ObjectID;
class EmbedsOne extends EmbedsOneOrMany class EmbedsOne extends EmbedsOneOrMany
{ {
/** /**
* Initialize the relation on a set of models. * @inheritdoc
*
* @param array $models
* @param string $relation
*/ */
public function initRelation(array $models, $relation) public function initRelation(array $models, $relation)
{ {
...@@ -21,9 +18,7 @@ class EmbedsOne extends EmbedsOneOrMany ...@@ -21,9 +18,7 @@ class EmbedsOne extends EmbedsOneOrMany
} }
/** /**
* Get the results of the relationship. * @inheritdoc
*
* @return \Illuminate\Database\Eloquent\Model
*/ */
public function getResults() public function getResults()
{ {
...@@ -33,8 +28,8 @@ class EmbedsOne extends EmbedsOneOrMany ...@@ -33,8 +28,8 @@ class EmbedsOne extends EmbedsOneOrMany
/** /**
* Save a new model and attach it to the parent model. * Save a new model and attach it to the parent model.
* *
* @param \Illuminate\Database\Eloquent\Model $model * @param Model $model
* @return \Illuminate\Database\Eloquent\Model * @return Model|bool
*/ */
public function performInsert(Model $model) public function performInsert(Model $model)
{ {
...@@ -46,8 +41,7 @@ class EmbedsOne extends EmbedsOneOrMany ...@@ -46,8 +41,7 @@ class EmbedsOne extends EmbedsOneOrMany
// For deeply nested documents, let the parent handle the changes. // For deeply nested documents, let the parent handle the changes.
if ($this->isNested()) { if ($this->isNested()) {
$this->associate($model); $this->associate($model);
return $this->parent->save() ? $model : false;
return $this->parent->save();
} }
$result = $this->getBaseQuery()->update([$this->localKey => $model->getAttributes()]); $result = $this->getBaseQuery()->update([$this->localKey => $model->getAttributes()]);
...@@ -63,8 +57,8 @@ class EmbedsOne extends EmbedsOneOrMany ...@@ -63,8 +57,8 @@ class EmbedsOne extends EmbedsOneOrMany
/** /**
* Save an existing model and attach it to the parent model. * Save an existing model and attach it to the parent model.
* *
* @param \Illuminate\Database\Eloquent\Model $model * @param Model $model
* @return \Illuminate\Database\Eloquent\Model|bool * @return Model|bool
*/ */
public function performUpdate(Model $model) public function performUpdate(Model $model)
{ {
...@@ -75,7 +69,7 @@ class EmbedsOne extends EmbedsOneOrMany ...@@ -75,7 +69,7 @@ class EmbedsOne extends EmbedsOneOrMany
} }
// Use array dot notation for better update behavior. // Use array dot notation for better update behavior.
$values = array_dot($model->getDirty(), $this->localKey . '.'); $values = array_dot($model->getDirty(), $this->localKey.'.');
$result = $this->getBaseQuery()->update($values); $result = $this->getBaseQuery()->update($values);
...@@ -90,15 +84,13 @@ class EmbedsOne extends EmbedsOneOrMany ...@@ -90,15 +84,13 @@ class EmbedsOne extends EmbedsOneOrMany
/** /**
* Delete an existing model and detach it from the parent model. * Delete an existing model and detach it from the parent model.
* *
* @param \Illuminate\Database\Eloquent\Model $model
* @return int * @return int
*/ */
public function performDelete(Model $model) public function performDelete()
{ {
// For deeply nested documents, let the parent handle the changes. // For deeply nested documents, let the parent handle the changes.
if ($this->isNested()) { if ($this->isNested()) {
$this->dissociate($model); $this->dissociate();
return $this->parent->save(); return $this->parent->save();
} }
...@@ -116,8 +108,8 @@ class EmbedsOne extends EmbedsOneOrMany ...@@ -116,8 +108,8 @@ class EmbedsOne extends EmbedsOneOrMany
/** /**
* Attach the model to its parent. * Attach the model to its parent.
* *
* @param \Illuminate\Database\Eloquent\Model $model * @param Model $model
* @return \Illuminate\Database\Eloquent\Model * @return Model
*/ */
public function associate(Model $model) public function associate(Model $model)
{ {
...@@ -127,7 +119,7 @@ class EmbedsOne extends EmbedsOneOrMany ...@@ -127,7 +119,7 @@ class EmbedsOne extends EmbedsOneOrMany
/** /**
* Detach the model from its parent. * Detach the model from its parent.
* *
* @return \Illuminate\Database\Eloquent\Model * @return Model
*/ */
public function dissociate() public function dissociate()
{ {
...@@ -141,8 +133,6 @@ class EmbedsOne extends EmbedsOneOrMany ...@@ -141,8 +133,6 @@ class EmbedsOne extends EmbedsOneOrMany
*/ */
public function delete() public function delete()
{ {
$model = $this->getResults(); return $this->performDelete();
return $this->performDelete($model);
} }
} }
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Database\Eloquent\Relations\Relation;
use Jenssegers\Mongodb\Eloquent\Model;
abstract class EmbedsOneOrMany extends Relation abstract class EmbedsOneOrMany extends Relation
{ {
...@@ -31,9 +31,9 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -31,9 +31,9 @@ abstract class EmbedsOneOrMany extends Relation
/** /**
* Create a new embeds many relationship instance. * Create a new embeds many relationship instance.
* *
* @param \Illuminate\Database\Eloquent\Builder $query * @param Builder $query
* @param \Illuminate\Database\Eloquent\Model $parent * @param Model $parent
* @param \Illuminate\Database\Eloquent\Model $related * @param Model $related
* @param string $localKey * @param string $localKey
* @param string $foreignKey * @param string $foreignKey
* @param string $relation * @param string $relation
...@@ -47,7 +47,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -47,7 +47,7 @@ abstract class EmbedsOneOrMany extends Relation
$this->foreignKey = $foreignKey; $this->foreignKey = $foreignKey;
$this->relation = $relation; $this->relation = $relation;
// If this is a nested relation, we need to get the parent query instead. // If this is a nested relation, we need to get the parent query instead.
if ($parentRelation = $this->getParentRelation()) { if ($parentRelation = $this->getParentRelation()) {
$this->query = $parentRelation->getQuery(); $this->query = $parentRelation->getQuery();
} }
...@@ -56,7 +56,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -56,7 +56,7 @@ abstract class EmbedsOneOrMany extends Relation
} }
/** /**
* Set the base constraints on the relation query. * @inheritdoc
*/ */
public function addConstraints() public function addConstraints()
{ {
...@@ -66,9 +66,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -66,9 +66,7 @@ abstract class EmbedsOneOrMany extends Relation
} }
/** /**
* Set the constraints for an eager load of the relation. * @inheritdoc
*
* @param array $models
*/ */
public function addEagerConstraints(array $models) public function addEagerConstraints(array $models)
{ {
...@@ -76,12 +74,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -76,12 +74,7 @@ abstract class EmbedsOneOrMany extends Relation
} }
/** /**
* Match the eagerly loaded results to their parents. * @inheritdoc
*
* @param array $models
* @param \Illuminate\Database\Eloquent\Collection $results
* @param string $relation
* @return array
*/ */
public function match(array $models, Collection $results, $relation) public function match(array $models, Collection $results, $relation)
{ {
...@@ -99,7 +92,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -99,7 +92,7 @@ abstract class EmbedsOneOrMany extends Relation
/** /**
* Shorthand to get the results of the relationship. * Shorthand to get the results of the relationship.
* *
* @return \Illuminate\Database\Eloquent\Collection * @return Collection
*/ */
public function get() public function get()
{ {
...@@ -119,8 +112,8 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -119,8 +112,8 @@ abstract class EmbedsOneOrMany extends Relation
/** /**
* Attach a model instance to the parent model. * Attach a model instance to the parent model.
* *
* @param \Illuminate\Database\Eloquent\Model $model * @param Model $model
* @return \Illuminate\Database\Eloquent\Model * @return Model|bool
*/ */
public function save(Model $model) public function save(Model $model)
{ {
...@@ -132,8 +125,8 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -132,8 +125,8 @@ abstract class EmbedsOneOrMany extends Relation
/** /**
* Attach a collection of models to the parent instance. * Attach a collection of models to the parent instance.
* *
* @param \Illuminate\Database\Eloquent\Collection|array $models * @param Collection|array $models
* @return \Illuminate\Database\Eloquent\Collection|array * @return Collection|array
*/ */
public function saveMany($models) public function saveMany($models)
{ {
...@@ -147,8 +140,8 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -147,8 +140,8 @@ abstract class EmbedsOneOrMany extends Relation
/** /**
* Create a new instance of the related model. * Create a new instance of the related model.
* *
* @param array $attributes * @param array $attributes
* @return \Illuminate\Database\Eloquent\Model * @return Model
*/ */
public function create(array $attributes) public function create(array $attributes)
{ {
...@@ -167,7 +160,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -167,7 +160,7 @@ abstract class EmbedsOneOrMany extends Relation
/** /**
* Create an array of new instances of the related model. * Create an array of new instances of the related model.
* *
* @param array $records * @param array $records
* @return array * @return array
*/ */
public function createMany(array $records) public function createMany(array $records)
...@@ -184,7 +177,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -184,7 +177,7 @@ abstract class EmbedsOneOrMany extends Relation
/** /**
* Transform single ID, single Model or array of Models into an array of IDs. * Transform single ID, single Model or array of Models into an array of IDs.
* *
* @param mixed $ids * @param mixed $ids
* @return array * @return array
*/ */
protected function getIdsArrayFrom($ids) protected function getIdsArrayFrom($ids)
...@@ -207,9 +200,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -207,9 +200,7 @@ abstract class EmbedsOneOrMany extends Relation
} }
/** /**
* Get the embedded records array. * @inheritdoc
*
* @return array
*/ */
protected function getEmbedded() protected function getEmbedded()
{ {
...@@ -223,10 +214,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -223,10 +214,7 @@ abstract class EmbedsOneOrMany extends Relation
} }
/** /**
* Set the embedded records array. * @inheritdoc
*
* @param array $records
* @return \Illuminate\Database\Eloquent\Model
*/ */
protected function setEmbedded($records) protected function setEmbedded($records)
{ {
...@@ -244,7 +232,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -244,7 +232,7 @@ abstract class EmbedsOneOrMany extends Relation
/** /**
* Get the foreign key value for the relation. * Get the foreign key value for the relation.
* *
* @param mixed $id * @param mixed $id
* @return mixed * @return mixed
*/ */
protected function getForeignKeyValue($id) protected function getForeignKeyValue($id)
...@@ -260,8 +248,8 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -260,8 +248,8 @@ abstract class EmbedsOneOrMany extends Relation
/** /**
* Convert an array of records to a Collection. * Convert an array of records to a Collection.
* *
* @param array $records * @param array $records
* @return \Jenssegers\Mongodb\Eloquent\Collection * @return Collection
*/ */
protected function toCollection(array $records = []) protected function toCollection(array $records = [])
{ {
...@@ -281,8 +269,8 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -281,8 +269,8 @@ abstract class EmbedsOneOrMany extends Relation
/** /**
* Create a related model instanced. * Create a related model instanced.
* *
* @param array $attributes * @param array $attributes
* @return \Illuminate\Database\Eloquent\Model * @return Model
*/ */
protected function toModel($attributes = []) protected function toModel($attributes = [])
{ {
...@@ -305,7 +293,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -305,7 +293,7 @@ abstract class EmbedsOneOrMany extends Relation
/** /**
* Get the relation instance of the parent. * Get the relation instance of the parent.
* *
* @return \Illuminate\Database\Eloquent\Relations\Relation * @return Relation
*/ */
protected function getParentRelation() protected function getParentRelation()
{ {
...@@ -313,9 +301,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -313,9 +301,7 @@ abstract class EmbedsOneOrMany extends Relation
} }
/** /**
* Get the underlying query for the relation. * @inheritdoc
*
* @return \Illuminate\Database\Eloquent\Builder
*/ */
public function getQuery() public function getQuery()
{ {
...@@ -325,9 +311,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -325,9 +311,7 @@ abstract class EmbedsOneOrMany extends Relation
} }
/** /**
* Get the base query builder driving the Eloquent builder. * @inheritdoc
*
* @return \Illuminate\Database\Query\Builder
*/ */
public function getBaseQuery() public function getBaseQuery()
{ {
...@@ -349,27 +333,25 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -349,27 +333,25 @@ abstract class EmbedsOneOrMany extends Relation
/** /**
* Get the fully qualified local key name. * Get the fully qualified local key name.
* *
* @param string $glue * @param string $glue
* @return string * @return string
*/ */
protected function getPathHierarchy($glue = '.') protected function getPathHierarchy($glue = '.')
{ {
if ($parentRelation = $this->getParentRelation()) { if ($parentRelation = $this->getParentRelation()) {
return $parentRelation->getPathHierarchy($glue) . $glue . $this->localKey; return $parentRelation->getPathHierarchy($glue).$glue.$this->localKey;
} }
return $this->localKey; return $this->localKey;
} }
/** /**
* Get the parent's fully qualified key name. * @inheritdoc
*
* @return string
*/ */
public function getQualifiedParentKeyName() public function getQualifiedParentKeyName()
{ {
if ($parentRelation = $this->getParentRelation()) { if ($parentRelation = $this->getParentRelation()) {
return $parentRelation->getPathHierarchy() . '.' . $this->parent->getKeyName(); return $parentRelation->getPathHierarchy().'.'.$this->parent->getKeyName();
} }
return $this->parent->getKeyName(); return $this->parent->getKeyName();
......
...@@ -8,9 +8,9 @@ class HasMany extends EloquentHasMany ...@@ -8,9 +8,9 @@ class HasMany extends EloquentHasMany
/** /**
* Add the constraints for a relationship count query. * Add the constraints for a relationship count query.
* *
* @param \Illuminate\Database\Eloquent\Builder $query * @param Builder $query
* @param \Illuminate\Database\Eloquent\Builder $parent * @param Builder $parent
* @return \Illuminate\Database\Eloquent\Builder * @return Builder
*/ */
public function getRelationCountQuery(Builder $query, Builder $parent) public function getRelationCountQuery(Builder $query, Builder $parent)
{ {
...@@ -22,10 +22,10 @@ class HasMany extends EloquentHasMany ...@@ -22,10 +22,10 @@ class HasMany extends EloquentHasMany
/** /**
* Add the constraints for a relationship query. * Add the constraints for a relationship query.
* *
* @param \Illuminate\Database\Eloquent\Builder $query * @param Builder $query
* @param \Illuminate\Database\Eloquent\Builder $parent * @param Builder $parent
* @param array|mixed $columns * @param array|mixed $columns
* @return \Illuminate\Database\Eloquent\Builder * @return Builder
*/ */
public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*']) public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*'])
{ {
......
...@@ -8,9 +8,9 @@ class HasOne extends EloquentHasOne ...@@ -8,9 +8,9 @@ class HasOne extends EloquentHasOne
/** /**
* Add the constraints for a relationship count query. * Add the constraints for a relationship count query.
* *
* @param \Illuminate\Database\Eloquent\Builder $query * @param Builder $query
* @param \Illuminate\Database\Eloquent\Builder $parent * @param Builder $parent
* @return \Illuminate\Database\Eloquent\Builder * @return Builder
*/ */
public function getRelationCountQuery(Builder $query, Builder $parent) public function getRelationCountQuery(Builder $query, Builder $parent)
{ {
...@@ -22,10 +22,10 @@ class HasOne extends EloquentHasOne ...@@ -22,10 +22,10 @@ class HasOne extends EloquentHasOne
/** /**
* Add the constraints for a relationship query. * Add the constraints for a relationship query.
* *
* @param \Illuminate\Database\Eloquent\Builder $query * @param Builder $query
* @param \Illuminate\Database\Eloquent\Builder $parent * @param Builder $parent
* @param array|mixed $columns * @param array|mixed $columns
* @return \Illuminate\Database\Eloquent\Builder * @return Builder
*/ */
public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*']) public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*'])
{ {
......
...@@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Relations\MorphTo as EloquentMorphTo; ...@@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Relations\MorphTo as EloquentMorphTo;
class MorphTo extends EloquentMorphTo class MorphTo extends EloquentMorphTo
{ {
/** /**
* Set the base constraints on the relation query. * @inheritdoc
*/ */
public function addConstraints() public function addConstraints()
{ {
...@@ -18,10 +18,7 @@ class MorphTo extends EloquentMorphTo ...@@ -18,10 +18,7 @@ class MorphTo extends EloquentMorphTo
} }
/** /**
* Get all of the relation results for a type. * @inheritdoc
*
* @param string $type
* @return \Illuminate\Database\Eloquent\Collection
*/ */
protected function getResultsByType($type) protected function getResultsByType($type)
{ {
......
<?php namespace Jenssegers\Mongodb\Schema; <?php namespace Jenssegers\Mongodb\Schema;
use Closure;
use Illuminate\Database\Connection; use Illuminate\Database\Connection;
class Blueprint extends \Illuminate\Database\Schema\Blueprint class Blueprint extends \Illuminate\Database\Schema\Blueprint
...@@ -27,10 +26,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -27,10 +26,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
protected $columns = []; protected $columns = [];
/** /**
* Create a new schema blueprint. * @inheritdoc
*
* @param string $table
* @param Closure $callback
*/ */
public function __construct(Connection $connection, $collection) public function __construct(Connection $connection, $collection)
{ {
...@@ -40,13 +36,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -40,13 +36,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
} }
/** /**
* Specify an index for the collection. * @inheritdoc
*
* @param string|array $columns
* @param array $options
* @param string $name
* @param string|null $algorithm
* @return Blueprint
*/ */
public function index($columns = null, $name = null, $algorithm = null, $options = []) public function index($columns = null, $name = null, $algorithm = null, $options = [])
{ {
...@@ -70,13 +60,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -70,13 +60,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
} }
/** /**
* Specify the primary key(s) for the table. * @inheritdoc
*
* @param string|array $columns
* @param string $name
* @param string|null $algorithm
* @param array $options
* @return \Illuminate\Support\Fluent
*/ */
public function primary($columns = null, $name = null, $algorithm = null, $options = []) public function primary($columns = null, $name = null, $algorithm = null, $options = [])
{ {
...@@ -84,10 +68,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -84,10 +68,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
} }
/** /**
* Indicate that the given index should be dropped. * @inheritdoc
*
* @param string|array $columns
* @return Blueprint
*/ */
public function dropIndex($columns = null) public function dropIndex($columns = null)
{ {
...@@ -99,7 +80,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -99,7 +80,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
$transform = []; $transform = [];
foreach ($columns as $column) { foreach ($columns as $column) {
$transform[$column] = $column . '_1'; $transform[$column] = $column.'_1';
} }
$columns = $transform; $columns = $transform;
...@@ -113,13 +94,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -113,13 +94,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
} }
/** /**
* Specify a unique index for the collection. * @inheritdoc
*
* @param string|array $columns
* @param string $name
* @param string|null $algorithm
* @param array $options
* @return Blueprint
*/ */
public function unique($columns = null, $name = null, $algorithm = null, $options = []) public function unique($columns = null, $name = null, $algorithm = null, $options = [])
{ {
...@@ -135,7 +110,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -135,7 +110,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
/** /**
* Specify a non blocking index for the collection. * Specify a non blocking index for the collection.
* *
* @param string|array $columns * @param string|array $columns
* @return Blueprint * @return Blueprint
*/ */
public function background($columns = null) public function background($columns = null)
...@@ -150,8 +125,8 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -150,8 +125,8 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
/** /**
* Specify a sparse index for the collection. * Specify a sparse index for the collection.
* *
* @param string|array $columns * @param string|array $columns
* @param array $options * @param array $options
* @return Blueprint * @return Blueprint
*/ */
public function sparse($columns = null, $options = []) public function sparse($columns = null, $options = [])
...@@ -169,8 +144,8 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -169,8 +144,8 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
* Specify the number of seconds after wich a document should be considered expired based, * Specify the number of seconds after wich a document should be considered expired based,
* on the given single-field index containing a date. * on the given single-field index containing a date.
* *
* @param string|array $columns * @param string|array $columns
* @param int $seconds * @param int $seconds
* @return Blueprint * @return Blueprint
*/ */
public function expire($columns, $seconds) public function expire($columns, $seconds)
...@@ -183,9 +158,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -183,9 +158,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
} }
/** /**
* Indicate that the table needs to be created. * @inheritdoc
*
* @return bool
*/ */
public function create() public function create()
{ {
...@@ -198,9 +171,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -198,9 +171,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
} }
/** /**
* Indicate that the collection should be dropped. * @inheritdoc
*
* @return bool
*/ */
public function drop() public function drop()
{ {
...@@ -208,12 +179,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -208,12 +179,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
} }
/** /**
* Add a new column to the blueprint. * @inheritdoc
*
* @param string $type
* @param string $name
* @param array $parameters
* @return Blueprint
*/ */
public function addColumn($type, $name, array $parameters = []) public function addColumn($type, $name, array $parameters = [])
{ {
...@@ -225,8 +191,8 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -225,8 +191,8 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
/** /**
* Specify a sparse and unique index for the collection. * Specify a sparse and unique index for the collection.
* *
* @param string|array $columns * @param string|array $columns
* @param array $options * @param array $options
* @return Blueprint * @return Blueprint
*/ */
public function sparse_and_unique($columns = null, $options = []) public function sparse_and_unique($columns = null, $options = [])
...@@ -244,7 +210,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -244,7 +210,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
/** /**
* Allow fluent columns. * Allow fluent columns.
* *
* @param string|array $columns * @param string|array $columns
* @return string|array * @return string|array
*/ */
protected function fluent($columns = null) protected function fluent($columns = null)
...@@ -261,6 +227,8 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -261,6 +227,8 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
/** /**
* Allows the use of unsupported schema methods. * Allows the use of unsupported schema methods.
* *
* @param $method
* @param $args
* @return Blueprint * @return Blueprint
*/ */
public function __call($method, $args) public function __call($method, $args)
......
...@@ -6,9 +6,7 @@ use Jenssegers\Mongodb\Connection; ...@@ -6,9 +6,7 @@ use Jenssegers\Mongodb\Connection;
class Builder extends \Illuminate\Database\Schema\Builder class Builder extends \Illuminate\Database\Schema\Builder
{ {
/** /**
* Create a new database Schema manager. * @inheritdoc
*
* @param Connection $connection
*/ */
public function __construct(Connection $connection) public function __construct(Connection $connection)
{ {
...@@ -16,11 +14,7 @@ class Builder extends \Illuminate\Database\Schema\Builder ...@@ -16,11 +14,7 @@ class Builder extends \Illuminate\Database\Schema\Builder
} }
/** /**
* Determine if the given table has a given column. * @inheritdoc
*
* @param string $table
* @param string $column
* @return bool
*/ */
public function hasColumn($table, $column) public function hasColumn($table, $column)
{ {
...@@ -28,11 +22,7 @@ class Builder extends \Illuminate\Database\Schema\Builder ...@@ -28,11 +22,7 @@ class Builder extends \Illuminate\Database\Schema\Builder
} }
/** /**
* Determine if the given table has given columns. * @inheritdoc
*
* @param string $table
* @param array $columns
* @return bool
*/ */
public function hasColumns($table, array $columns) public function hasColumns($table, array $columns)
{ {
...@@ -42,7 +32,7 @@ class Builder extends \Illuminate\Database\Schema\Builder ...@@ -42,7 +32,7 @@ class Builder extends \Illuminate\Database\Schema\Builder
/** /**
* Determine if the given collection exists. * Determine if the given collection exists.
* *
* @param string $collection * @param string $collection
* @return bool * @return bool
*/ */
public function hasCollection($collection) public function hasCollection($collection)
...@@ -59,10 +49,7 @@ class Builder extends \Illuminate\Database\Schema\Builder ...@@ -59,10 +49,7 @@ class Builder extends \Illuminate\Database\Schema\Builder
} }
/** /**
* Determine if the given collection exists. * @inheritdoc
*
* @param string $collection
* @return bool
*/ */
public function hasTable($collection) public function hasTable($collection)
{ {
...@@ -72,8 +59,8 @@ class Builder extends \Illuminate\Database\Schema\Builder ...@@ -72,8 +59,8 @@ class Builder extends \Illuminate\Database\Schema\Builder
/** /**
* Modify a collection on the schema. * Modify a collection on the schema.
* *
* @param string $collection * @param string $collection
* @param Closure $callback * @param Closure $callback
* @return bool * @return bool
*/ */
public function collection($collection, Closure $callback) public function collection($collection, Closure $callback)
...@@ -86,11 +73,7 @@ class Builder extends \Illuminate\Database\Schema\Builder ...@@ -86,11 +73,7 @@ class Builder extends \Illuminate\Database\Schema\Builder
} }
/** /**
* Modify a collection on the schema. * @inheritdoc
*
* @param string $collection
* @param Closure $callback
* @return bool
*/ */
public function table($collection, Closure $callback) public function table($collection, Closure $callback)
{ {
...@@ -98,11 +81,7 @@ class Builder extends \Illuminate\Database\Schema\Builder ...@@ -98,11 +81,7 @@ class Builder extends \Illuminate\Database\Schema\Builder
} }
/** /**
* Create a new collection on the schema. * @inheritdoc
*
* @param string $collection
* @param Closure $callback
* @return bool
*/ */
public function create($collection, Closure $callback = null) public function create($collection, Closure $callback = null)
{ {
...@@ -116,10 +95,7 @@ class Builder extends \Illuminate\Database\Schema\Builder ...@@ -116,10 +95,7 @@ class Builder extends \Illuminate\Database\Schema\Builder
} }
/** /**
* Drop a collection from the schema. * @inheritdoc
*
* @param string $collection
* @return bool
*/ */
public function drop($collection) public function drop($collection)
{ {
...@@ -129,10 +105,7 @@ class Builder extends \Illuminate\Database\Schema\Builder ...@@ -129,10 +105,7 @@ class Builder extends \Illuminate\Database\Schema\Builder
} }
/** /**
* Create a new Blueprint. * @inheritdoc
*
* @param string $collection
* @return Schema\Blueprint
*/ */
protected function createBlueprint($collection, Closure $callback = null) protected function createBlueprint($collection, Closure $callback = null)
{ {
......
...@@ -18,9 +18,15 @@ class QueueTest extends TestCase ...@@ -18,9 +18,15 @@ class QueueTest extends TestCase
// Get and reserve the test job (next available) // Get and reserve the test job (next available)
$job = Queue::pop('test'); $job = Queue::pop('test');
$this->assertInstanceOf('Illuminate\Queue\Jobs\DatabaseJob', $job); $this->assertInstanceOf(Jenssegers\Mongodb\Queue\MongoJob::class, $job);
$this->assertEquals(1, $job->getDatabaseJob()->reserved); $this->assertEquals(1, $job->isReserved());
$this->assertEquals(json_encode(['job' => 'test', 'data' => ['action' => 'QueueJobLifeCycle']]), $job->getRawBody()); $this->assertEquals(json_encode([
'displayName' => 'test',
'job' => 'test',
'maxTries' => null,
'timeout' => null,
'data' => ['action' => 'QueueJobLifeCycle'],
]), $job->getRawBody());
// Remove reserved job // Remove reserved job
$job->delete(); $job->delete();
...@@ -34,12 +40,15 @@ class QueueTest extends TestCase ...@@ -34,12 +40,15 @@ class QueueTest extends TestCase
// Expire the test job // Expire the test job
$expiry = \Carbon\Carbon::now()->subSeconds(Config::get('queue.connections.database.expire'))->getTimestamp(); $expiry = \Carbon\Carbon::now()->subSeconds(Config::get('queue.connections.database.expire'))->getTimestamp();
Queue::getDatabase()->table(Config::get('queue.connections.database.table'))->where('_id', $id)->update(['reserved' => 1, 'reserved_at' => $expiry]); Queue::getDatabase()
->table(Config::get('queue.connections.database.table'))
->where('_id', $id)
->update(['reserved' => 1, 'reserved_at' => $expiry]);
// Expect an attempted older job in the queue // Expect an attempted older job in the queue
$job = Queue::pop('test'); $job = Queue::pop('test');
$this->assertEquals(1, $job->getDatabaseJob()->attempts); $this->assertEquals(1, $job->attempts());
$this->assertGreaterThan($expiry, $job->getDatabaseJob()->reserved_at); $this->assertGreaterThan($expiry, $job->reservedAt());
$job->delete(); $job->delete();
$this->assertEquals(0, Queue::getDatabase()->table(Config::get('queue.connections.database.table'))->count()); $this->assertEquals(0, Queue::getDatabase()->table(Config::get('queue.connections.database.table'))->count());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment