From 37a0aa7f700e4dc257ee6fb7147254d68ca1a937 Mon Sep 17 00:00:00 2001 From: Ditty Date: Wed, 4 Mar 2020 14:22:40 +0300 Subject: [PATCH] Remove shouldUseCollections function Remove shouldUseCollections function which checks Laravel version > 5.3, it was introduced to support version 5.3 in https://github.com/jenssegers/laravel-mongodb/pull/925 --- CHANGELOG.md | 1 + src/Jenssegers/Mongodb/Query/Builder.php | 32 ++++-------------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 160b0b927..0b687a010 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,3 +4,4 @@ All notable changes to this project will be documented in this file. ## [Unreleased] ### Removed - EmbedsOne and EmbedsMany relations by [@divine](https://github.com/divine). +- shouldUseCollections function by [@divine](https://github.com/divine). diff --git a/src/Jenssegers/Mongodb/Query/Builder.php b/src/Jenssegers/Mongodb/Query/Builder.php index 7c5c973ba..09860c74f 100644 --- a/src/Jenssegers/Mongodb/Query/Builder.php +++ b/src/Jenssegers/Mongodb/Query/Builder.php @@ -115,12 +115,6 @@ class Builder extends BaseBuilder '>=' => '$gte', ]; - /** - * Check if we need to return Collections instead of plain arrays (laravel >= 5.3 ) - * @var boolean - */ - protected $useCollections; - /** * @inheritdoc */ @@ -129,22 +123,6 @@ public function __construct(Connection $connection, Processor $processor) $this->grammar = new Grammar; $this->connection = $connection; $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 @@ public function getFresh($columns = []) 'aggregate' => $totalResults ] ]; - return $this->useCollections ? new Collection($results) : $results; + return new Collection($results); } elseif ($function == 'count') { // Translate count into sum. $group['aggregate'] = ['$sum' => 1]; @@ -342,7 +320,7 @@ public function getFresh($columns = []) $results = iterator_to_array($this->collection->aggregate($pipeline, $options)); // Return results - return $this->useCollections ? new Collection($results) : $results; + return new Collection($results); } // Distinct query elseif ($this->distinct) { // Return distinct results directly @@ -355,7 +333,7 @@ public function getFresh($columns = []) $result = $this->collection->distinct($column); } - return $this->useCollections ? new Collection($result) : $result; + return new Collection($result); } // Normal query else { $columns = []; @@ -404,7 +382,7 @@ public function getFresh($columns = []) // Return results as an array with numeric keys $results = iterator_to_array($cursor, false); - return $this->useCollections ? new Collection($results) : $results; + return new Collection($results); } } @@ -659,7 +637,7 @@ public function pluck($column, $key = null) } $p = Arr::pluck($results, $column, $key); - return $this->useCollections ? new Collection($p) : $p; + return new Collection($p); } /**