-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from multividas/FIXING
fixing
- Loading branch information
Showing
7 changed files
with
167 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.{js,ts,vue,json,lock}] | ||
indent_size = 2 | ||
|
||
[*.md] | ||
indent_size = 2 | ||
trim_trailing_whitespace = false | ||
|
||
[*.{yml,yaml}] | ||
indent_size = 2 | ||
|
||
[docker-compose.yml] | ||
indent_size = 4 |
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,6 @@ | ||
* text=auto eol=lf | ||
|
||
*.md diff=markdown | ||
*.php diff=php | ||
|
||
/.github export-ignore |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,60 @@ | ||
{ | ||
"name": "multividas/query-filters", | ||
"type": "package", | ||
"license": "MIT", | ||
"description": "Composer package to simplify the process of filtering and sorting queries", | ||
"keywords": [ | ||
"query-filters" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Multividas", | ||
"email": "multividasdotcom@gmail.com" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"Multividas\\QueryFilters\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Multividas\\QueryFilters\\Tests\\": "tests/" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "vendor/bin/phpunit tests/Feature", | ||
"php-psr": [ | ||
"find src -type f -name \"*.php\" -print0 | xargs -0 -n1 php -lf", | ||
"vendor/bin/php-cs-fixer fix --allow-risky=yes src --rules=declare_strict_types,@PSR12", | ||
"./vendor/bin/phpcs --standard=PSR2 --encoding=utf-8 --extensions=php src/*" | ||
] | ||
}, | ||
"require": { | ||
"php": "^8.2" | ||
}, | ||
"require-dev": { | ||
"squizlabs/php_codesniffer": "4.0.x-dev", | ||
"phpunit/phpunit": "9.6.x-dev", | ||
"orchestra/testbench": "8.x-dev", | ||
"friendsofphp/php-cs-fixer": "dev-master" | ||
}, | ||
"minimum-stability": "stable", | ||
"config": { | ||
"optimize-autoloader": true | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Multividas\\QueryFilters\\Providers\\QueryFiltersServiceProvider" | ||
], | ||
"aliases": { | ||
"QueryFilters": "Multividas\\QueryFilters\\Facades\\QueryFilters" | ||
} | ||
} | ||
}, | ||
"support": { | ||
"issues": "https://github.com/multividas/query-filters/issues", | ||
"source": "https://github.com/multividas/query-filters" | ||
"name": "multividas/query-filters", | ||
"type": "package", | ||
"license": "MIT", | ||
"description": "Composer package to simplify the process of filtering and sorting queries", | ||
"keywords": [ | ||
"query-filters" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Multividas", | ||
"email": "multividasdotcom@gmail.com" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"Multividas\\QueryFilters\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Multividas\\QueryFilters\\Tests\\": "tests/" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "vendor/bin/phpunit tests/Feature", | ||
"php-psr": [ | ||
"find src -type f -name \"*.php\" -print0 | xargs -0 -n1 php -lf", | ||
"vendor/bin/php-cs-fixer fix --allow-risky=yes src --rules=declare_strict_types,@PSR12", | ||
"./vendor/bin/phpcs --standard=PSR2 --encoding=utf-8 --extensions=php src/*" | ||
] | ||
}, | ||
"require": { | ||
"php": "^8.2" | ||
}, | ||
"require-dev": { | ||
"squizlabs/php_codesniffer": "4.0.x-dev", | ||
"phpunit/phpunit": "9.6.x-dev", | ||
"orchestra/testbench": "8.x-dev", | ||
"friendsofphp/php-cs-fixer": "dev-master" | ||
}, | ||
"minimum-stability": "stable", | ||
"config": { | ||
"optimize-autoloader": true | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Multividas\\QueryFilters\\Providers\\QueryFiltersServiceProvider" | ||
], | ||
"aliases": { | ||
"QueryFilters": "Multividas\\QueryFilters\\Facades\\QueryFilters" | ||
} | ||
} | ||
}, | ||
"support": { | ||
"issues": "https://github.com/multividas/query-filters/issues", | ||
"source": "https://github.com/multividas/query-filters" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* (c) 2024 Multividas. All rights reserved. | ||
* Unauthorized use prohibited. | ||
* Website: https://www.multividas.com | ||
*/ | ||
|
||
namespace Multividas\QueryFilters\Services; | ||
|
||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
use Illuminate\Database\Eloquent\Collection as EloquentCollection; | ||
|
||
class CachingService | ||
{ | ||
private string $url; | ||
private string $fullUrl; | ||
private string $queryString; | ||
private string|array|null $queryParams; | ||
|
||
/** | ||
* Method __construct | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->url = request()->url(); | ||
|
||
$this->queryParams = request()->query(); | ||
ksort($this->queryParams); | ||
|
||
$this->queryString = http_build_query($this->queryParams); | ||
|
||
$this->fullUrl = "{$this->url}?{$this->queryString}"; | ||
} | ||
|
||
/** | ||
* Method cacheData | ||
* | ||
* @param Collection|EloquentCollection|JsonResource $collection | ||
* | ||
* @return Collection|EloquentCollection|JsonResource | ||
*/ | ||
public function cacheData( | ||
Collection|EloquentCollection|JsonResource $collection | ||
): Collection|EloquentCollection|JsonResource { | ||
return Cache::remember($this->fullUrl, now()->addSeconds(60), function () use ($collection) { | ||
return $collection; | ||
}); | ||
} | ||
} |