Unverified Commit 444e90df authored by Divine's avatar Divine Committed by GitHub

Merge pull request #1983 from divine/remove_should_use_collections

[4.x] Remove shouldUseCollections function
parents 20754f16 37a0aa7f
...@@ -4,3 +4,4 @@ All notable changes to this project will be documented in this file. ...@@ -4,3 +4,4 @@ All notable changes to this project will be documented in this file.
## [Unreleased] ## [Unreleased]
### Removed ### Removed
- EmbedsOne and EmbedsMany relations by [@divine](https://github.com/divine). - EmbedsOne and EmbedsMany relations by [@divine](https://github.com/divine).
- shouldUseCollections function by [@divine](https://github.com/divine).
...@@ -115,12 +115,6 @@ class Builder extends BaseBuilder ...@@ -115,12 +115,6 @@ class Builder extends BaseBuilder
'>=' => '$gte', '>=' => '$gte',
]; ];
/**
* Check if we need to return Collections instead of plain arrays (laravel >= 5.3 )
* @var boolean
*/
protected $useCollections;
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -129,22 +123,6 @@ class Builder extends BaseBuilder ...@@ -129,22 +123,6 @@ class Builder extends BaseBuilder
$this->grammar = new Grammar; $this->grammar = new Grammar;
$this->connection = $connection; $this->connection = $connection;
$this->processor = $processor; $this->processor = $processor;
$this->useCollections = $this->shouldUseCollections();
}
/**
* Returns true if Laravel or Lumen >= 5.3
* @return bool
*/
protected function shouldUseCollections()
{
if (function_exists('app')) {
$version = app()->version();
$version = filter_var(explode(')', $version)[0], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); // lumen
return version_compare($version, '5.3', '>=');
}
return true;
} }
/** /**
...@@ -285,7 +263,7 @@ class Builder extends BaseBuilder ...@@ -285,7 +263,7 @@ class Builder extends BaseBuilder
'aggregate' => $totalResults 'aggregate' => $totalResults
] ]
]; ];
return $this->useCollections ? new Collection($results) : $results; return new Collection($results);
} elseif ($function == 'count') { } elseif ($function == 'count') {
// Translate count into sum. // Translate count into sum.
$group['aggregate'] = ['$sum' => 1]; $group['aggregate'] = ['$sum' => 1];
...@@ -342,7 +320,7 @@ class Builder extends BaseBuilder ...@@ -342,7 +320,7 @@ class Builder extends BaseBuilder
$results = iterator_to_array($this->collection->aggregate($pipeline, $options)); $results = iterator_to_array($this->collection->aggregate($pipeline, $options));
// Return results // Return results
return $this->useCollections ? new Collection($results) : $results; return new Collection($results);
} // Distinct query } // Distinct query
elseif ($this->distinct) { elseif ($this->distinct) {
// Return distinct results directly // Return distinct results directly
...@@ -355,7 +333,7 @@ class Builder extends BaseBuilder ...@@ -355,7 +333,7 @@ class Builder extends BaseBuilder
$result = $this->collection->distinct($column); $result = $this->collection->distinct($column);
} }
return $this->useCollections ? new Collection($result) : $result; return new Collection($result);
} // Normal query } // Normal query
else { else {
$columns = []; $columns = [];
...@@ -404,7 +382,7 @@ class Builder extends BaseBuilder ...@@ -404,7 +382,7 @@ class Builder extends BaseBuilder
// Return results as an array with numeric keys // Return results as an array with numeric keys
$results = iterator_to_array($cursor, false); $results = iterator_to_array($cursor, false);
return $this->useCollections ? new Collection($results) : $results; return new Collection($results);
} }
} }
...@@ -659,7 +637,7 @@ class Builder extends BaseBuilder ...@@ -659,7 +637,7 @@ class Builder extends BaseBuilder
} }
$p = Arr::pluck($results, $column, $key); $p = Arr::pluck($results, $column, $key);
return $this->useCollections ? new Collection($p) : $p; return new Collection($p);
} }
/** /**
......
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