Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
soulaimaneyahya committed May 25, 2024
0 parents commit 7df4e01
Show file tree
Hide file tree
Showing 13 changed files with 457 additions and 0 deletions.
Empty file added .github/.gitkeep
Empty file.
36 changes: 36 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Set up PHP
uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
with:
php-version: "8.2"

- name: Checkout code
uses: actions/checkout@v3

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-progress

- name: Validate PHP PSR
run: composer run-script php-psr

- name: Run test suite
run: composer run-script test
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/vendor/
/.phpunit.result.cache
/phpunit.xml
/composer.lock
.idea/
.vscode/*
.githooks/*
.TODO
.php-cs-fixer.cache
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Multividas

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<div align="center">

<img width="150" height="150" src="./assets/query-filters.svg" alt="Query Option package logo"/>

# Query Filters

[![Tests](https://github.com/multividas/query-filters/actions/workflows/tests.yml/badge.svg)](https://github.com/multividas/query-filters/actions/workflows/tests.yml)
[![Total Downloads](https://img.shields.io/packagist/dt/multividas/query-filters.svg?style=flat-square)](https://packagist.org/packages/multividas/query-filters)
[![License](https://img.shields.io/github/license/multividas/query-filters?style=flat-square)](https://github.com/multividas/query-filters/blob/main/LICENSE)

</div>

Composer package to simplify the process of filtering and sorting queries

---

## Installation
Require this package with composer.

```shell
composer require multividas/query-filters
```

Learn more: [Multividas Query Filters](https://developers.multividas.com/rest/introduction/query-filters)


### Run PHPUnit tests

```sh
composer test
```

## 🤝 Contributing

Please read the [contributing guide](https://github.com/multividas/.github/blob/main/CONTRIBUTING.md).

## 🛡️ Security Issues

If you discover a security vulnerability within Multividas, we would appreciate your help in disclosing it to us responsibly, please check out our [security issues guidelines](https://github.com/multividas/.github/blob/main/SECURITY.md).

## 🛡️ License

Licensed under the [MIT license](https://github.com/multividas/.github/blob/main/LICENSE).

---

> Email: multividasdotcom@gmail.com
1 change: 1 addition & 0 deletions assets/query-filters.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +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"
}
}
20 changes: 20 additions & 0 deletions src/Facades/QueryFilters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* (c) 2024 Multividas. All rights reserved.
* Unauthorized use prohibited.
* Website: https://www.multividas.com
*/

namespace Multividas\QueryFilters\Facades;

use Illuminate\Support\Facades\Facade;
use Multividas\QueryFilters\Interfaces\QueryFiltersRepositoryInterface;

class QueryFilters extends Facade
{
protected static function getFacadeAccessor(): string
{
return QueryFiltersRepositoryInterface::class;
}
}
35 changes: 35 additions & 0 deletions src/Interfaces/QueryFiltersRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* (c) 2024 Multividas. All rights reserved.
* Unauthorized use prohibited.
* Website: https://www.multividas.com
*/

namespace Multividas\QueryFilters\Interfaces;

use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;

interface QueryFiltersRepositoryInterface
{
public function applyFilters(Collection|EloquentCollection|JsonResource $collection): array|JsonResponse;

public function filterData(
Collection|EloquentCollection|JsonResource $collection,
?string $transformer
): Collection|EloquentCollection|JsonResource;

public function sortData(
Collection|EloquentCollection|JsonResource $collection,
?string $transformer
): Collection|EloquentCollection|JsonResource;

public function cacheData(
Collection|EloquentCollection|JsonResource $collection
): Collection|EloquentCollection|JsonResource;

public function paginateData(Collection|EloquentCollection|JsonResource $collection): array;
}
23 changes: 23 additions & 0 deletions src/Providers/QueryFiltersServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/**
* (c) 2024 Multividas. All rights reserved.
* Unauthorized use prohibited.
* Website: https://www.multividas.com
*/

namespace Multividas\QueryFilters\Providers;

use Illuminate\Support\ServiceProvider;
use Multividas\QueryFilters\Repositories\QueryFiltersRepository;
use Multividas\QueryFilters\Interfaces\QueryFiltersRepositoryInterface;

class QueryFiltersServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->bind(QueryFiltersRepositoryInterface::class, function () {
return new QueryFiltersRepository();
});
}
}
Loading

0 comments on commit 7df4e01

Please sign in to comment.