Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
huangbule committed Mar 13, 2024
1 parent 42d8d8b commit 8bd093f
Show file tree
Hide file tree
Showing 17 changed files with 456 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false

[*.{vue,js,scss}]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* text=auto

/tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.scrutinizer.yml export-ignore
.travis.yml export-ignore
phpunit.php export-ignore
phpunit.xml.dist export-ignore
phpunit.xml export-ignore
.php_cs export-ignore
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.idea
*.DS_Store
/vendor
/coverage
sftp-config.json
composer.lock
.subsplit
.php_cs.cache
27 changes: 27 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
$header = <<<EOF
This file is part of the huangbule/laravel-eloquent-filter.
(c) huangbule <[email protected]>
This source file is subject to the MIT license that is bundled.
EOF;

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules(array(
'@Symfony' => true,
'header_comment' => array('header' => $header),
'array_syntax' => array('syntax' => 'short'),
'ordered_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'php_unit_construct' => true,
'php_unit_strict' => true,
))
->setFinder(
PhpCsFixer\Finder::create()
->exclude('vendor')
->in(__DIR__)
)
;
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<h1 align="center"> laravel-eloquent-filter </h1>

<p align="center"> An Eloquent way to filter Eloquent Models.</p>


## Installing

```shell
$ composer require huangbule/laravel-eloquent-filter -vvv
```

## Usage

TODO

## Contributing

You can contribute in one of three ways:

1. File bug reports using the [issue tracker](https://github.com/huangbule/laravel-eloquent-filter/issues).
2. Answer questions or fix bugs on the [issue tracker](https://github.com/huangbule/laravel-eloquent-filter/issues).
3. Contribute new features or update the wiki.

_The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable._

## License

MIT
27 changes: 27 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "huangbule/laravel-eloquent-filter",
"description": "An Eloquent way to filter Eloquent Models",
"license": "MIT",
"authors": [
{
"name": "huangbule",
"email": "[email protected]"
}
],
"require": {},
"autoload": {
"psr-4": {
"Huangbule\\LaravelEloquentFilter\\": "src"
}
},
"extra": {
"laravel": {
"providers": [
"Huangbule\\LaravelEloquentFilter\\EloquentFilterProvider"
],
"aliases": {

}
}
}
}
11 changes: 11 additions & 0 deletions config/filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'default' => '$like',

'rule' => [
'uuid' => 'uuid|$eq',
'department_name' => '#department',
]

];
21 changes: 21 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
Empty file added src/.gitkeep
Empty file.
7 changes: 7 additions & 0 deletions src/Contracts/Ipreprocess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace Huangbule\LaravelEloquentFilter\Contracts;

interface Ipreprocess {

public function handle($column, &$param);
}
30 changes: 30 additions & 0 deletions src/EloquentFilterProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
namespace Huangbule\LaravelEloquentFilter;

use Illuminate\Support\ServiceProvider;

class EloquentFilterProvider extends ServiceProvider {


/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/filter.php', 'filter');
}

public function boot()
{
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../config/filter.php' => config_path('filter.php'),
], 'filter');

}
}


}
8 changes: 8 additions & 0 deletions src/Exceptions/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Huangbule\LaravelEloquentFilter\Exceptions;

class InvalidArgumentException extends \Exception
{

}
8 changes: 8 additions & 0 deletions src/Exceptions/NotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Huangbule\LaravelEloquentFilter\Exceptions;

class NotFoundException extends \Exception
{

}
8 changes: 8 additions & 0 deletions src/Exceptions/NotInstanceOfInterfaceException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Huangbule\LaravelEloquentFilter\Exceptions;

class NotInstanceOfInterfaceException extends \Exception
{

}
21 changes: 21 additions & 0 deletions src/Preprocess/HalfOpenDatePreprocess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Huangbule\LaravelEloquentFilter\Preprocess;

use Huangbule\LaravelEloquentFilter\Contracts\Ipreprocess;

class HalfOpenDatePreprocess implements Ipreprocess {

public function handle($column, &$param) {
if (! empty($param[$column])) {
if (is_array($param[$column])) {
$start_at = $param[$column][0];
$end_at = date('Y-m-d', strtotime('+1 day', strtotime($param[$column][1])));
} else {
$start_at = $param[$column];
$end_at = date('Y-m-d', strtotime('+1 day', strtotime($param[$column])));
}
$param[$column] = [$start_at, $end_at];
}
}
}
Loading

0 comments on commit 8bd093f

Please sign in to comment.