Skip to content

Commit 1ed9685

Browse files
committed
Merge remote-tracking branch 'origin/master' into patch-2
2 parents 9e3816b + 3f0609c commit 1ed9685

32 files changed

+248
-96
lines changed

.travis.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1-
sudo: required
2-
dist: trusty
3-
language: php
4-
php:
5-
- "7.2"
6-
- "7.1"
1+
language: minimal
2+
3+
matrix:
4+
include:
5+
- name: "7.1"
6+
env: PHP_VERSION=7.1
7+
- name: "7.2"
8+
env: PHP_VERSION=7.2
9+
- name: "7.3"
10+
env: PHP_VERSION=7.3
711

812
services:
913
- docker
1014

15+
cache:
16+
directories:
17+
- $HOME/.composer/cache
18+
1119
install:
1220
- docker version
1321
- sudo pip install docker-compose
1422
- docker-compose version
15-
- cat Dockerfile
16-
- docker-compose build --build-arg PHP_VERSION=${TRAVIS_PHP_VERSION}
23+
- docker-compose build --build-arg PHP_VERSION=${PHP_VERSION}
24+
- docker-compose run --rm tests composer install --no-interaction
1725

1826
script:
19-
- docker-compose up --exit-code-from php
27+
- docker-compose run --rm tests ./vendor/bin/phpunit --coverage-clover ./clover.xml

Dockerfile

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
ARG PHP_VERSION=7.2
2+
ARG COMPOSER_VERSION=1.8
23

4+
FROM composer:${COMPOSER_VERSION}
35
FROM php:${PHP_VERSION}-cli
46

5-
RUN pecl install xdebug
6-
77
RUN apt-get update && \
8-
apt-get install -y autoconf pkg-config libssl-dev git zlib1g-dev
9-
10-
RUN pecl install mongodb && docker-php-ext-enable mongodb && \
11-
docker-php-ext-install -j$(nproc) pdo pdo_mysql zip && docker-php-ext-enable xdebug
8+
apt-get install -y autoconf pkg-config libssl-dev git libzip-dev zlib1g-dev && \
9+
pecl install mongodb && docker-php-ext-enable mongodb && \
10+
pecl install xdebug && docker-php-ext-enable xdebug && \
11+
docker-php-ext-install -j$(nproc) pdo_mysql zip
1212

13-
RUN curl -sS https://getcomposer.org/installer | php \
14-
&& mv composer.phar /usr/local/bin/ \
15-
&& ln -s /usr/local/bin/composer.phar /usr/local/bin/composer
13+
COPY --from=composer /usr/bin/composer /usr/local/bin/composer
1614

17-
ENV PATH="~/.composer/vendor/bin:./vendor/bin:${PATH}"
15+
WORKDIR /code

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ composer require jenssegers/mongodb
4343
5.4.x | 3.2.x
4444
5.5.x | 3.3.x
4545
5.6.x | 3.4.x
46+
5.7.x | 3.4.x
47+
5.8.x | 3.5.x
4648

4749
And add the service provider in `config/app.php`:
4850

@@ -63,8 +65,10 @@ The service provider will register a mongodb database extension with the origina
6365
For usage outside Laravel, check out the [Capsule manager](https://github.com/illuminate/database/blob/master/README.md) and add:
6466

6567
```php
66-
$capsule->getDatabaseManager()->extend('mongodb', function($config)
68+
$capsule->getDatabaseManager()->extend('mongodb', function($config, $name)
6769
{
70+
$config['name'] = $name;
71+
6872
return new Jenssegers\Mongodb\Connection($config);
6973
});
7074
```
@@ -298,7 +302,7 @@ This service provider will slightly modify the internal DatabaseReminderReposito
298302

299303
### Queues
300304

301-
If you want to use MongoDB as your database backend, change the the driver in `config/queue.php`:
305+
If you want to use MongoDB as your database backend, change the driver in `config/queue.php`:
302306

303307
```php
304308
'connections' => [
@@ -689,7 +693,7 @@ For more information about model manipulation, check http://laravel.com/docs/elo
689693

690694
### Dates
691695

692-
Eloquent allows you to work with Carbon/DateTime objects instead of MongoDate objects. Internally, these dates will be converted to MongoDate objects when saved to the database. If you wish to use this functionality on non-default date fields you will need to manually specify them as described here: http://laravel.com/docs/eloquent#date-mutators
696+
Eloquent allows you to work with Carbon/DateTime objects instead of MongoDate objects. Internally, these dates will be converted to MongoDate objects when saved to the database. If you wish to use this functionality on non-default date fields, you will need to manually specify them as described here: http://laravel.com/docs/eloquent#date-mutators
693697

694698
Example:
695699

@@ -787,7 +791,7 @@ class User extends Eloquent {
787791
}
788792
```
789793

790-
You access the embedded models through the dynamic property:
794+
You can access the embedded models through the dynamic property:
791795

792796
```php
793797
$books = User::first()->books;
@@ -849,7 +853,7 @@ Embedded relations will return a Collection of embedded items instead of a query
849853

850854
### EmbedsOne Relations
851855

852-
The embedsOne relation is similar to the EmbedsMany relation, but only embeds a single model.
856+
The embedsOne relation is similar to the embedsMany relation, but only embeds a single model.
853857

854858
```php
855859
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
@@ -864,7 +868,7 @@ class Book extends Eloquent {
864868
}
865869
```
866870

867-
You access the embedded models through the dynamic property:
871+
You can access the embedded models through the dynamic property:
868872

869873
```php
870874
$author = Book::first()->author;
@@ -1014,7 +1018,7 @@ DB::collection('items')->paginate($limit, $projections);
10141018

10151019
**Push**
10161020

1017-
Add an items to an array.
1021+
Add items to an array.
10181022

10191023
```php
10201024
DB::collection('users')->where('name', 'John')->push('items', 'boots');

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
],
1212
"license" : "MIT",
1313
"require": {
14-
"illuminate/support": "^5.6",
15-
"illuminate/container": "^5.6",
16-
"illuminate/database": "^5.6",
17-
"illuminate/events": "^5.6",
18-
"mongodb/mongodb": "^1.0.0"
14+
"illuminate/support": "^5.8",
15+
"illuminate/container": "^5.8",
16+
"illuminate/database": "^5.8",
17+
"illuminate/events": "^5.8",
18+
"mongodb/mongodb": "^1.4"
1919
},
2020
"require-dev": {
2121
"phpunit/phpunit": "^6.0|^7.0",

docker-compose.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
version: '3'
22

33
services:
4-
php:
5-
container_name: php
4+
tests:
5+
container_name: tests
66
build:
77
context: .
88
dockerfile: Dockerfile
99
volumes:
1010
- .:/code
1111
working_dir: /code
12-
command: bash -c "composer install --prefer-source --no-interaction && php ./vendor/bin/phpunit"
1312
depends_on:
14-
- mysql
1513
- mongodb
14+
- mysql
1615

1716
mysql:
1817
container_name: mysql
19-
image: mysql
18+
image: mysql:5.7
2019
environment:
2120
MYSQL_ROOT_PASSWORD:
2221
MYSQL_DATABASE: unittest
@@ -27,5 +26,7 @@ services:
2726
mongodb:
2827
container_name: mongodb
2928
image: mongo
29+
ports:
30+
- 27017:27017
3031
logging:
3132
driver: none

phpunit.xml.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false"
11-
syntaxCheck="false"
1211
verbose="true"
1312
>
1413
<testsuites>
1514
<testsuite name="all">
1615
<directory>tests/</directory>
17-
<exclude>tests/MysqlRelationsTest.php</exclude>
1816
</testsuite>
1917
<testsuite name="schema">
2018
<directory>tests/SchemaTest.php</directory>
@@ -39,7 +37,6 @@
3937
</testsuite>
4038
<testsuite name="mysqlrelations">
4139
<directory>tests/RelationsTest.php</directory>
42-
<directory>tests/MysqlRelationsTest.php</directory>
4340
</testsuite>
4441
<testsuite name="validation">
4542
<directory>tests/ValidationTest.php</directory>

src/Jenssegers/Mongodb/Auth/PasswordBrokerManager.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ class PasswordBrokerManager extends BasePasswordBrokerManager
1111
*/
1212
protected function createTokenRepository(array $config)
1313
{
14-
$key = $this->app['config']['app.key'];
15-
16-
if (\Illuminate\Support\Str::startsWith($key, 'base64:')) {
17-
$key = base64_decode(substr($key, 7));
18-
}
19-
20-
$connection = isset($config['connection']) ? $config['connection'] : null;
21-
2214
return new DatabaseTokenRepository(
2315
$this->app['db']->connection(),
2416
$this->app['hash'],

src/Jenssegers/Mongodb/Connection.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ public function getMongoClient()
113113
return $this->connection;
114114
}
115115

116+
/**
117+
* {@inheritdoc}
118+
*/
119+
public function getDatabaseName()
120+
{
121+
return $this->getMongoDB()->getDatabaseName();
122+
}
123+
116124
/**
117125
* Create a new MongoDB connection.
118126
*

src/Jenssegers/Mongodb/Eloquent/Builder.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,31 @@ public function raw($expression = null)
177177
return $results;
178178
}
179179

180+
/**
181+
* Add the "updated at" column to an array of values.
182+
* TODO Remove if https://github.com/laravel/framework/commit/6484744326531829341e1ff886cc9b628b20d73e
183+
* wiil be reverted
184+
* Issue in laravel frawework https://github.com/laravel/framework/issues/27791
185+
*
186+
* @param array $values
187+
* @return array
188+
*/
189+
protected function addUpdatedAtColumn(array $values)
190+
{
191+
if (! $this->model->usesTimestamps() ||
192+
is_null($this->model->getUpdatedAtColumn())) {
193+
return $values;
194+
}
195+
196+
$column = $this->model->getUpdatedAtColumn();
197+
$values = array_merge(
198+
[$column => $this->model->freshTimestampString()],
199+
$values
200+
);
201+
202+
return $values;
203+
}
204+
180205
/**
181206
* @return \Illuminate\Database\ConnectionInterface
182207
*/

src/Jenssegers/Mongodb/Eloquent/Model.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ abstract class Model extends BaseModel
3131
* @var string
3232
*/
3333
protected $primaryKey = '_id';
34+
35+
/**
36+
* The primary key type.
37+
*
38+
* @var string
39+
*/
40+
protected $keyType = 'string';
3441

3542
/**
3643
* The parent relation instance.
@@ -221,7 +228,7 @@ public function getCasts()
221228
/**
222229
* @inheritdoc
223230
*/
224-
protected function originalIsEquivalent($key, $current)
231+
public function originalIsEquivalent($key, $current)
225232
{
226233
if (!array_key_exists($key, $this->original)) {
227234
return false;

src/Jenssegers/Mongodb/Helpers/QueriesRelationships.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected function getRelatedConstraintKey($relation)
110110
}
111111

112112
if ($relation instanceof BelongsTo) {
113-
return $relation->getForeignKey();
113+
return $relation->getForeignKeyName();
114114
}
115115

116116
if ($relation instanceof BelongsToMany && ! $this->isAcrossConnections($relation)) {
@@ -130,7 +130,7 @@ protected function getHasCompareKey($relation)
130130
return $relation->getHasCompareKey();
131131
}
132132

133-
return $relation instanceof HasOneOrMany ? $relation->getForeignKeyName() : $relation->getOwnerKey();
133+
return $relation instanceof HasOneOrMany ? $relation->getForeignKeyName() : $relation->getOwnerKeyName();
134134
}
135135

136136
/**

src/Jenssegers/Mongodb/Relations/BelongsTo.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Jenssegers\Mongodb\Relations;
44

55
use Illuminate\Database\Eloquent\Builder;
6+
use Illuminate\Database\Eloquent\Model as EloquentModel;
67

78
class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo
89
{
@@ -59,4 +60,16 @@ public function getOwnerKey()
5960
{
6061
return property_exists($this, 'ownerKey') ? $this->ownerKey : $this->otherKey;
6162
}
63+
64+
/**
65+
* Get the name of the "where in" method for eager loading.
66+
*
67+
* @param \Illuminate\Database\Eloquent\Model $model
68+
* @param string $key
69+
* @return string
70+
*/
71+
protected function whereInMethod(EloquentModel $model, $key)
72+
{
73+
return 'whereIn';
74+
}
6275
}

src/Jenssegers/Mongodb/Relations/BelongsToMany.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Database\Eloquent\Model;
88
use Illuminate\Database\Eloquent\Relations\BelongsToMany as EloquentBelongsToMany;
99
use Illuminate\Support\Arr;
10+
use Illuminate\Database\Eloquent\Model as EloquentModel;
1011

1112
class BelongsToMany extends EloquentBelongsToMany
1213
{
@@ -337,4 +338,16 @@ public function getRelatedKey()
337338
{
338339
return property_exists($this, 'relatedPivotKey') ? $this->relatedPivotKey : $this->relatedKey;
339340
}
341+
342+
/**
343+
* Get the name of the "where in" method for eager loading.
344+
*
345+
* @param \Illuminate\Database\Eloquent\Model $model
346+
* @param string $key
347+
* @return string
348+
*/
349+
protected function whereInMethod(EloquentModel $model, $key)
350+
{
351+
return 'whereIn';
352+
}
340353
}

src/Jenssegers/Mongodb/Relations/EmbedsMany.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Pagination\LengthAwarePaginator;
88
use Illuminate\Pagination\Paginator;
99
use MongoDB\BSON\ObjectID;
10+
use Illuminate\Database\Eloquent\Model as EloquentModel;
1011

1112
class EmbedsMany extends EmbedsOneOrMany
1213
{
@@ -328,4 +329,16 @@ public function __call($method, $parameters)
328329

329330
return parent::__call($method, $parameters);
330331
}
332+
333+
/**
334+
* Get the name of the "where in" method for eager loading.
335+
*
336+
* @param \Illuminate\Database\Eloquent\Model $model
337+
* @param string $key
338+
* @return string
339+
*/
340+
protected function whereInMethod(EloquentModel $model, $key)
341+
{
342+
return 'whereIn';
343+
}
331344
}

0 commit comments

Comments
 (0)