Skip to content

Commit

Permalink
Merge branch 'master' into 'renovate/phpunit-phpunit-10.x'
Browse files Browse the repository at this point in the history
# Conflicts:
#   composer.json
  • Loading branch information
craigAtCD committed Jul 20, 2023
2 parents 4ac5015 + 17212f1 commit ff9a327
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v2
uses: cycjimmy/semantic-release-action@v3
id: semantic
with:
extra_plugins: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

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

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
Expand Down
49 changes: 49 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
## [1.2.6](https://github.com/customd/hashed-search/compare/v1.2.5...v1.2.6) (2022-11-08)


### Bug Fixes

* missing ; in contract ([a6ecf6a](https://github.com/customd/hashed-search/commit/a6ecf6ab16f9e03dce4e615ce166be8e334ac7d4))

## [1.2.5](https://github.com/customd/hashed-search/compare/v1.2.4...v1.2.5) (2022-10-13)


### Bug Fixes

* add ability to forcebly hash a record ([4cdd650](https://github.com/customd/hashed-search/commit/4cdd65080f9332be1cefa9cf3470cee28f2da11a))

## [1.2.4](https://github.com/customd/hashed-search/compare/v1.2.3...v1.2.4) (2022-08-31)


### Bug Fixes

* add or where search ([5ab83c6](https://github.com/customd/hashed-search/commit/5ab83c6e56a38aee1586ea6092998a759e23e402))

## [1.2.3](https://github.com/customd/hashed-search/compare/v1.2.2...v1.2.3) (2022-07-12)


### Bug Fixes

* filter null values before creating hashes ([79169a6](https://github.com/customd/hashed-search/commit/79169a6490266cbd2e558c453cf1f5ce5d208b14))

## [1.2.2](https://github.com/customd/hashed-search/compare/v1.2.1...v1.2.2) (2022-07-12)


### Bug Fixes

* nullable searchable values ([87d8062](https://github.com/customd/hashed-search/commit/87d8062d8012837196877b25356b91db00c7eaf5))

## [1.2.1](https://github.com/customd/hashed-search/compare/v1.2.0...v1.2.1) (2022-06-16)


### Bug Fixes

* nullable create ([a1b6950](https://github.com/customd/hashed-search/commit/a1b69505db3dea0b722795515f6c5859f97c38e9))

# [1.2.0](https://github.com/customd/hashed-search/compare/v1.1.0...v1.2.0) (2022-05-31)


### Features

* laravel 9 ([5569ddc](https://github.com/customd/hashed-search/commit/5569ddc55c148c632947960ee6744e0521c66905))

# [1.1.0](https://github.com/customd/hashed-search/compare/v1.0.1...v1.1.0) (2021-05-04)


Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
}
],
"require": {
"php": ">=7.2",
"php": "^8.0",
"ext-intl": "*",
"illuminate/support": "^6.0|^7.0|^8.0"
"illuminate/support": "^8.0|^9.0|^9.0|^10.0"
},
"require-dev": {
"orchestra/testbench": "^4.0|^5.0|^6.0",
"phpunit/phpunit": "10.2.6"
"orchestra/testbench": "^6.0|^7.0|^8.0",
"phpunit/phpunit": "^9.0|^10.0"
},
"autoload": {
"psr-4": {
Expand Down
46 changes: 33 additions & 13 deletions src/Contracts/HasSearchableHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,35 @@ public static function bootHasSearchableHash(): void
{
//We need to setup hashes for this
static::saved(function ($model) {
$model->generateSearchHashes()->each(function ($hash, $field) use ($model) {
ModelsHashedSearch::updateOrCreate([
'hash_field' => $field,
'hash_id' => $model->getKey(),
'hash_type' => $model->getMorphClass()
], [
'hash' => $hash,
]);
});
$model->buildSearchHash();
});
}

protected function generateSearchHashes(): Collection
public function buildSearchHash(): void
{
return collect($this->searchableHash ?? [])->filter()->mapWithKeys(function ($field) {
return [$field => HashedSearch::create($this->getAttribute($field))];
$this->generateSearchHashes()->each(function ($hash, $field) {
ModelsHashedSearch::updateOrCreate([
'hash_field' => $field,
'hash_id' => $this->getKey(),
'hash_type' => $this->getMorphClass()
], [
'hash' => $hash,
]);
});
}

public function scopeSearchHashedField(Builder $builder, string $field, string $clearText)
protected function generateSearchHashes(): Collection
{
return collect($this->searchableHash ?? [])
->filter(
fn($field) => ! blank($this->getAttribute($field))
)
->mapWithKeys(
fn ($field) => [$field => HashedSearch::create($this->getAttribute($field))]
);
}

public function scopeSearchHashedField(Builder $builder, string $field, string $clearText): void
{
$builder->whereHas('searchHashRelation', function (Builder $builder) use ($field, $clearText) {
$builder->where('hash_field', $field);
Expand All @@ -46,6 +55,17 @@ public function scopeSearchHashedField(Builder $builder, string $field, string $
});
}

public function scopeOrSearchHashedField(Builder $builder, string $field, string $clearText): void
{
$builder->orWhereHas('searchHashRelation', function (Builder $builder) use ($field, $clearText) {
$builder->where('hash_field', $field);
$builder->where(
'hash',
HashedSearch::create($clearText)
);
});
}

public function searchHashRelation()
{
return $this->hasMany(ModelsHashedSearch::class, 'hash_id')->where('hash_type', $this->getMorphClass());
Expand Down
2 changes: 1 addition & 1 deletion src/HashedSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(array $config)
}


public function create(string $value, string $saltModifier = ""): ?string
public function create(?string $value, string $saltModifier = ""): ?string
{
//Nothing to hash here!
if (strlen($value) === 0 || $value === null) {
Expand Down

0 comments on commit ff9a327

Please sign in to comment.