-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5eecbc
commit 42d9500
Showing
7 changed files
with
53 additions
and
89 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
24 changes: 0 additions & 24 deletions
24
src/Foundation/Providers/CollectionMacroServiceProvider.php
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,35 @@ | ||
<?php | ||
|
||
namespace Apiato\Foundation\Providers; | ||
|
||
use Apiato\Abstract\Providers\AggregateServiceProvider; | ||
use Illuminate\Config\Repository; | ||
use Illuminate\Support\Arr; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\Config; | ||
use Vinkla\Hashids\Facades\Hashids; | ||
|
||
final class MacroServiceProvider extends AggregateServiceProvider | ||
{ | ||
public function boot(): void | ||
{ | ||
if (!Collection::hasMacro('containsDecodedHash')) { | ||
Collection::macro('containsDecodedHash', | ||
/** | ||
* Decodes a hashed value and checks if the decoded value exists in the collection under the specified key. | ||
*/ | ||
function (string $hashedValue, string $key = 'id'): bool { | ||
/* @var Collection $this */ | ||
return $this->contains($key, Hashids::decode($hashedValue)[0]); | ||
}); | ||
} | ||
|
||
if (!Config::hasMacro('unset')) { | ||
Config::macro('unset', | ||
function (array|string|int|float $key): void { | ||
/* @var Repository $this */ | ||
Arr::forget($this->items, $key); | ||
}); | ||
} | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
src/Foundation/Support/Macros/Collection/ContainsDecodedHash.php
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
tests/Unit/Foundation/Support/Providers/MacroServiceProviderTest.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,17 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Foundation\Support\Providers; | ||
|
||
use Apiato\Foundation\Providers\MacroServiceProvider; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\Config; | ||
|
||
describe(class_basename(MacroServiceProvider::class), function (): void { | ||
it('register Collection macros', function (): void { | ||
expect(Collection::hasMacro('containsDecodedHash'))->toBeTrue(); | ||
}); | ||
|
||
it('register Config macros', function (): void { | ||
expect(Config::hasMacro('unset'))->toBeTrue(); | ||
}); | ||
})->covers(MacroServiceProvider::class); |