Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
mnphpexpert committed Apr 2, 2019
2 parents 9e3816b + 3f0609c commit 1ed9685
Show file tree
Hide file tree
Showing 32 changed files with 248 additions and 96 deletions.
26 changes: 17 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
sudo: required
dist: trusty
language: php
php:
- "7.2"
- "7.1"
language: minimal

matrix:
include:
- name: "7.1"
env: PHP_VERSION=7.1
- name: "7.2"
env: PHP_VERSION=7.2
- name: "7.3"
env: PHP_VERSION=7.3

services:
- docker

cache:
directories:
- $HOME/.composer/cache

install:
- docker version
- sudo pip install docker-compose
- docker-compose version
- cat Dockerfile
- docker-compose build --build-arg PHP_VERSION=${TRAVIS_PHP_VERSION}
- docker-compose build --build-arg PHP_VERSION=${PHP_VERSION}
- docker-compose run --rm tests composer install --no-interaction

script:
- docker-compose up --exit-code-from php
- docker-compose run --rm tests ./vendor/bin/phpunit --coverage-clover ./clover.xml
18 changes: 8 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
ARG PHP_VERSION=7.2
ARG COMPOSER_VERSION=1.8

FROM composer:${COMPOSER_VERSION}
FROM php:${PHP_VERSION}-cli

RUN pecl install xdebug

RUN apt-get update && \
apt-get install -y autoconf pkg-config libssl-dev git zlib1g-dev

RUN pecl install mongodb && docker-php-ext-enable mongodb && \
docker-php-ext-install -j$(nproc) pdo pdo_mysql zip && docker-php-ext-enable xdebug
apt-get install -y autoconf pkg-config libssl-dev git libzip-dev zlib1g-dev && \
pecl install mongodb && docker-php-ext-enable mongodb && \
pecl install xdebug && docker-php-ext-enable xdebug && \
docker-php-ext-install -j$(nproc) pdo_mysql zip

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

ENV PATH="~/.composer/vendor/bin:./vendor/bin:${PATH}"
WORKDIR /code
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ composer require jenssegers/mongodb
5.4.x | 3.2.x
5.5.x | 3.3.x
5.6.x | 3.4.x
5.7.x | 3.4.x
5.8.x | 3.5.x

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

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

```php
$capsule->getDatabaseManager()->extend('mongodb', function($config)
$capsule->getDatabaseManager()->extend('mongodb', function($config, $name)
{
$config['name'] = $name;

return new Jenssegers\Mongodb\Connection($config);
});
```
Expand Down Expand Up @@ -298,7 +302,7 @@ This service provider will slightly modify the internal DatabaseReminderReposito

### Queues

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

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

### Dates

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
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

Example:

Expand Down Expand Up @@ -787,7 +791,7 @@ class User extends Eloquent {
}
```

You access the embedded models through the dynamic property:
You can access the embedded models through the dynamic property:

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

### EmbedsOne Relations

The embedsOne relation is similar to the EmbedsMany relation, but only embeds a single model.
The embedsOne relation is similar to the embedsMany relation, but only embeds a single model.

```php
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
Expand All @@ -864,7 +868,7 @@ class Book extends Eloquent {
}
```

You access the embedded models through the dynamic property:
You can access the embedded models through the dynamic property:

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

**Push**

Add an items to an array.
Add items to an array.

```php
DB::collection('users')->where('name', 'John')->push('items', 'boots');
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
],
"license" : "MIT",
"require": {
"illuminate/support": "^5.6",
"illuminate/container": "^5.6",
"illuminate/database": "^5.6",
"illuminate/events": "^5.6",
"mongodb/mongodb": "^1.0.0"
"illuminate/support": "^5.8",
"illuminate/container": "^5.8",
"illuminate/database": "^5.8",
"illuminate/events": "^5.8",
"mongodb/mongodb": "^1.4"
},
"require-dev": {
"phpunit/phpunit": "^6.0|^7.0",
Expand Down
11 changes: 6 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
version: '3'

services:
php:
container_name: php
tests:
container_name: tests
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/code
working_dir: /code
command: bash -c "composer install --prefer-source --no-interaction && php ./vendor/bin/phpunit"
depends_on:
- mysql
- mongodb
- mysql

mysql:
container_name: mysql
image: mysql
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD:
MYSQL_DATABASE: unittest
Expand All @@ -27,5 +26,7 @@ services:
mongodb:
container_name: mongodb
image: mongo
ports:
- 27017:27017
logging:
driver: none
3 changes: 0 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
verbose="true"
>
<testsuites>
<testsuite name="all">
<directory>tests/</directory>
<exclude>tests/MysqlRelationsTest.php</exclude>
</testsuite>
<testsuite name="schema">
<directory>tests/SchemaTest.php</directory>
Expand All @@ -39,7 +37,6 @@
</testsuite>
<testsuite name="mysqlrelations">
<directory>tests/RelationsTest.php</directory>
<directory>tests/MysqlRelationsTest.php</directory>
</testsuite>
<testsuite name="validation">
<directory>tests/ValidationTest.php</directory>
Expand Down
8 changes: 0 additions & 8 deletions src/Jenssegers/Mongodb/Auth/PasswordBrokerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ class PasswordBrokerManager extends BasePasswordBrokerManager
*/
protected function createTokenRepository(array $config)
{
$key = $this->app['config']['app.key'];

if (\Illuminate\Support\Str::startsWith($key, 'base64:')) {
$key = base64_decode(substr($key, 7));
}

$connection = isset($config['connection']) ? $config['connection'] : null;

return new DatabaseTokenRepository(
$this->app['db']->connection(),
$this->app['hash'],
Expand Down
8 changes: 8 additions & 0 deletions src/Jenssegers/Mongodb/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ public function getMongoClient()
return $this->connection;
}

/**
* {@inheritdoc}
*/
public function getDatabaseName()
{
return $this->getMongoDB()->getDatabaseName();
}

/**
* Create a new MongoDB connection.
*
Expand Down
25 changes: 25 additions & 0 deletions src/Jenssegers/Mongodb/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,31 @@ public function raw($expression = null)
return $results;
}

/**
* Add the "updated at" column to an array of values.
* TODO Remove if https://github.com/laravel/framework/commit/6484744326531829341e1ff886cc9b628b20d73e
* wiil be reverted
* Issue in laravel frawework https://github.com/laravel/framework/issues/27791
*
* @param array $values
* @return array
*/
protected function addUpdatedAtColumn(array $values)
{
if (! $this->model->usesTimestamps() ||
is_null($this->model->getUpdatedAtColumn())) {
return $values;
}

$column = $this->model->getUpdatedAtColumn();
$values = array_merge(
[$column => $this->model->freshTimestampString()],
$values
);

return $values;
}

/**
* @return \Illuminate\Database\ConnectionInterface
*/
Expand Down
9 changes: 8 additions & 1 deletion src/Jenssegers/Mongodb/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ abstract class Model extends BaseModel
* @var string
*/
protected $primaryKey = '_id';

/**
* The primary key type.
*
* @var string
*/
protected $keyType = 'string';

/**
* The parent relation instance.
Expand Down Expand Up @@ -221,7 +228,7 @@ public function getCasts()
/**
* @inheritdoc
*/
protected function originalIsEquivalent($key, $current)
public function originalIsEquivalent($key, $current)
{
if (!array_key_exists($key, $this->original)) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/Jenssegers/Mongodb/Helpers/QueriesRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected function getRelatedConstraintKey($relation)
}

if ($relation instanceof BelongsTo) {
return $relation->getForeignKey();
return $relation->getForeignKeyName();
}

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

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

/**
Expand Down
13 changes: 13 additions & 0 deletions src/Jenssegers/Mongodb/Relations/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Jenssegers\Mongodb\Relations;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model as EloquentModel;

class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo
{
Expand Down Expand Up @@ -59,4 +60,16 @@ public function getOwnerKey()
{
return property_exists($this, 'ownerKey') ? $this->ownerKey : $this->otherKey;
}

/**
* Get the name of the "where in" method for eager loading.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @return string
*/
protected function whereInMethod(EloquentModel $model, $key)
{
return 'whereIn';
}
}
13 changes: 13 additions & 0 deletions src/Jenssegers/Mongodb/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany as EloquentBelongsToMany;
use Illuminate\Support\Arr;
use Illuminate\Database\Eloquent\Model as EloquentModel;

class BelongsToMany extends EloquentBelongsToMany
{
Expand Down Expand Up @@ -337,4 +338,16 @@ public function getRelatedKey()
{
return property_exists($this, 'relatedPivotKey') ? $this->relatedPivotKey : $this->relatedKey;
}

/**
* Get the name of the "where in" method for eager loading.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @return string
*/
protected function whereInMethod(EloquentModel $model, $key)
{
return 'whereIn';
}
}
13 changes: 13 additions & 0 deletions src/Jenssegers/Mongodb/Relations/EmbedsMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
use MongoDB\BSON\ObjectID;
use Illuminate\Database\Eloquent\Model as EloquentModel;

class EmbedsMany extends EmbedsOneOrMany
{
Expand Down Expand Up @@ -328,4 +329,16 @@ public function __call($method, $parameters)

return parent::__call($method, $parameters);
}

/**
* Get the name of the "where in" method for eager loading.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @return string
*/
protected function whereInMethod(EloquentModel $model, $key)
{
return 'whereIn';
}
}
Loading

0 comments on commit 1ed9685

Please sign in to comment.