Skip to content

Commit 315b84e

Browse files
committed
Merge pull request #704 from WillSkates/pecl-mongodb
[Ready] Fixing incompatabilities and upgrading to work with php7.
2 parents 1b32d02 + aa2ef6f commit 315b84e

File tree

16 files changed

+85
-23
lines changed

16 files changed

+85
-23
lines changed

.travis.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ language: php
33
php:
44
- 5.5
55
- 5.6
6-
- 7.0
6+
- 7
77
- hhvm
88

99
matrix:
@@ -13,7 +13,16 @@ matrix:
1313

1414
sudo: false
1515

16-
services: mongodb
16+
services:
17+
- mongodb
18+
- mysql
19+
20+
addons:
21+
apt:
22+
sources:
23+
- mongodb-3.0-precise
24+
packages:
25+
- mongodb-org-server
1726

1827
before_script:
1928
- pecl install mongodb
@@ -23,7 +32,7 @@ before_script:
2332

2433
script:
2534
- mkdir -p build/logs
26-
- phpunit --coverage-clover build/logs/clover.xml
35+
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
2736

2837
after_success:
2938
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php vendor/bin/coveralls -v; fi;'

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
"illuminate/container": "^5.1",
1616
"illuminate/database": "^5.1",
1717
"illuminate/events": "^5.1",
18-
"mongodb/mongodb": "^1.0.0@beta"
18+
"mongodb/mongodb": "^1.0.0"
1919

2020
},
2121
"require-dev": {
2222
"phpunit/phpunit": "^4.0|^5.0",
23-
"orchestra/testbench": "^3.2",
23+
"orchestra/testbench": "^3.1",
2424
"mockery/mockery": "^0.9",
2525
"satooshi/php-coveralls": "^0.6"
2626
},

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
processIsolation="false"
1010
stopOnFailure="false"
1111
syntaxCheck="false"
12+
verbose="true"
1213
>
1314
<testsuites>
1415
<testsuite name="all">

src/Jenssegers/Mongodb/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __call($method, $parameters)
3939
{
4040
$start = microtime(true);
4141
$result = call_user_func_array([$this->collection, $method], $parameters);
42-
42+
4343
if ($this->connection->logging())
4444
{
4545
// Once we have run the query we will calculate the time that it took to run and

src/Jenssegers/Mongodb/Eloquent/Builder.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
44
use Illuminate\Database\Eloquent\Relations\Relation;
55
use MongoDB\Driver\Cursor;
6+
use MongoDB\Model\BSONDocument;
67

78
class Builder extends EloquentBuilder {
89

@@ -221,18 +222,20 @@ public function raw($expression = null)
221222
if ($results instanceof Cursor)
222223
{
223224
$results = iterator_to_array($results, false);
224-
225225
return $this->model->hydrate($results);
226226
}
227227

228+
// Convert Mongo BSONDocument to a single object.
229+
elseif ($results instanceof BSONDocument)
230+
{
231+
$results = $results->getArrayCopy();
232+
return $this->model->newFromBuilder((array) $results);
233+
}
234+
228235
// The result is a single object.
229236
elseif (is_array($results) and array_key_exists('_id', $results))
230237
{
231-
$model = $this->model->newFromBuilder((array) $results);
232-
233-
$model->setConnection($this->model->getConnection());
234-
235-
return $model;
238+
return $this->model->newFromBuilder((array) $results);
236239
}
237240

238241
return $results;

src/Jenssegers/Mongodb/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ public function attributesToArray()
360360
*
361361
* @return array
362362
*/
363-
protected function getCasts()
363+
public function getCasts()
364364
{
365365
return $this->casts;
366366
}

src/Jenssegers/Mongodb/Query/Builder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class Builder extends BaseBuilder {
8585
*/
8686
public function __construct(Connection $connection, Processor $processor)
8787
{
88+
$this->grammar = new Grammar;
8889
$this->connection = $connection;
8990
$this->processor = $processor;
9091
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php namespace Jenssegers\Mongodb\Query;
2+
3+
use Illuminate\Database\Query\Grammars\Grammar as BaseGrammar;
4+
5+
class Grammar extends BaseGrammar {
6+
7+
}

src/Jenssegers/Mongodb/Relations/HasMany.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ public function getRelationCountQuery(Builder $query, Builder $parent)
1919
return $query->select($this->getHasCompareKey())->where($this->getHasCompareKey(), 'exists', true);
2020
}
2121

22+
/**
23+
* Add the constraints for a relationship query.
24+
*
25+
* @param \Illuminate\Database\Eloquent\Builder $query
26+
* @param \Illuminate\Database\Eloquent\Builder $parent
27+
* @param array|mixed $columns
28+
* @return \Illuminate\Database\Eloquent\Builder
29+
*/
30+
public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*'])
31+
{
32+
$query->select($columns);
33+
$key = $this->wrap($this->getQualifiedParentKeyName());
34+
return $query->where($this->getHasCompareKey(), 'exists', true);
35+
}
36+
2237
/**
2338
* Get the plain foreign key.
2439
*

src/Jenssegers/Mongodb/Relations/HasOne.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ public function getRelationCountQuery(Builder $query, Builder $parent)
1919
return $query->select($this->getHasCompareKey())->where($this->getHasCompareKey(), 'exists', true);
2020
}
2121

22+
/**
23+
* Add the constraints for a relationship query.
24+
*
25+
* @param \Illuminate\Database\Eloquent\Builder $query
26+
* @param \Illuminate\Database\Eloquent\Builder $parent
27+
* @param array|mixed $columns
28+
* @return \Illuminate\Database\Eloquent\Builder
29+
*/
30+
public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*'])
31+
{
32+
$query->select($columns);
33+
$key = $this->wrap($this->getQualifiedParentKeyName());
34+
return $query->where($this->getHasCompareKey(), 'exists', true);
35+
}
36+
2237
/**
2338
* Get the plain foreign key.
2439
*

0 commit comments

Comments
 (0)