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)
{ {
...@@ -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);
} }
......
...@@ -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()
{ {
...@@ -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()
{ {
...@@ -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()
{ {
...@@ -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()
{ {
......
...@@ -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);
}
}
...@@ -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;
...@@ -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.
...@@ -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)
{ {
...@@ -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()
{ {
...@@ -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()
{ {
...@@ -500,10 +389,7 @@ abstract class Model extends BaseModel ...@@ -500,10 +389,7 @@ abstract class Model extends BaseModel
} }
/** /**
* 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()
{ {
......
This diff is collapsed.
<?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
); );
} }
} }
...@@ -49,13 +46,12 @@ class MongoQueue extends DatabaseQueue ...@@ -49,13 +46,12 @@ class MongoQueue extends DatabaseQueue
[ [
'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(),
], ],
], ],
[ [
...@@ -79,7 +75,7 @@ class MongoQueue extends DatabaseQueue ...@@ -79,7 +75,7 @@ class MongoQueue extends DatabaseQueue
*/ */
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)
...@@ -118,11 +114,7 @@ class MongoQueue extends DatabaseQueue ...@@ -118,11 +114,7 @@ class MongoQueue extends DatabaseQueue
} }
/** /**
* 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)
{ {
...@@ -20,7 +18,7 @@ class BelongsToMany extends EloquentBelongsToMany ...@@ -20,7 +18,7 @@ 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()
{ {
......
<?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,10 +77,10 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -82,10 +77,10 @@ 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.
...@@ -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)
{ {
...@@ -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)
{ {
...@@ -282,7 +277,7 @@ class EmbedsMany extends EmbedsOneOrMany ...@@ -282,7 +277,7 @@ 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
...@@ -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)
{ {
...@@ -148,7 +141,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -148,7 +141,7 @@ 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)
{ {
...@@ -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)
{ {
...@@ -261,7 +249,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -261,7 +249,7 @@ 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 = [])
{ {
...@@ -282,7 +270,7 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -282,7 +270,7 @@ 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()
{ {
...@@ -355,21 +339,19 @@ abstract class EmbedsOneOrMany extends Relation ...@@ -355,21 +339,19 @@ abstract class EmbedsOneOrMany extends Relation
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 = [])
{ {
...@@ -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 = [])
{ {
...@@ -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)
{ {
...@@ -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)
{ {
...@@ -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