-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update:refactor the core code with resolver db and eloquent
- Loading branch information
1 parent
233fcb2
commit c163101
Showing
11 changed files
with
217 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/QueryFilter/Core/ResolverDetection/ResolverDetectionDb.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace eloquentFilter\QueryFilter\Core\ResolverDetection; | ||
|
||
use eloquentFilter\QueryFilter\Detection\Contract\DetectorDbFactoryContract; | ||
use eloquentFilter\QueryFilter\Detection\Contract\MainBuilderConditionsContract; | ||
use eloquentFilter\QueryFilter\Queries\BaseClause; | ||
use Illuminate\Contracts\Foundation\Application; | ||
use Illuminate\Support\Arr; | ||
|
||
class ResolverDetectionDb extends ResolverDetections | ||
{ | ||
|
||
/** | ||
* ResolverDetectionDb constructor. | ||
* @param $builder | ||
* @param array $request | ||
* @param \eloquentFilter\QueryFilter\Detection\Contract\DetectorDbFactoryContract $detector_db_factory | ||
* @param \eloquentFilter\QueryFilter\Detection\Contract\MainBuilderConditionsContract $main_builder_conditions_contract | ||
*/ | ||
public function __construct($builder, array $request, DetectorDbFactoryContract $detector_db_factory, MainBuilderConditionsContract $main_builder_conditions_contract) | ||
{ | ||
$this->builder = $builder; | ||
$this->request = $request; | ||
$this->detector_db_factory = $detector_db_factory; | ||
$this->main_builder_conditions = $main_builder_conditions_contract; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getFiltersDetection(): array | ||
{ | ||
$filter_detections = collect($this->request)->map(function ($values, $filter){ | ||
return $this->resolve($filter, $values); | ||
})->reverse()->filter(function ($item) { | ||
return $item instanceof BaseClause; | ||
})->toArray(); | ||
|
||
$out = Arr::isAssoc($filter_detections) ? $filter_detections : []; | ||
|
||
return $out; | ||
} | ||
|
||
/** | ||
* @param $filterName | ||
* @param $values | ||
* | ||
* @return Application|mixed | ||
* @throws ReflectionException | ||
* | ||
*/ | ||
protected function resolve($filterName, $values) | ||
{ | ||
$detectedConditions = $this->detector_db_factory->buildDetections($filterName, $values); | ||
|
||
$builderDriver = $this->main_builder_conditions->build($detectedConditions); | ||
|
||
return app($builderDriver, ['filter' => $filterName, 'values' => $values]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.