Add CryptographyContract and its implementation
Added a new CryptographyContract interface and CryptographyString class that implements this contract. The CryptographyContract encapsulates the encryption and decryption of strings, enforcing these operations to be standardized across the application. The CryptographyString class uses Laravel's native crypt facades to perform these actions. In the AppServiceProvider, CryptographyContract is now bound to CryptographyString class, allowing the container to automatically resolve the dependencies wherever the interface is type hinted.
This commit is contained in:
parent
27046e6674
commit
c3e4c68a41
9
app/Contracts/CryptographyContract.php
Normal file
9
app/Contracts/CryptographyContract.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Contracts;
|
||||||
|
|
||||||
|
interface CryptographyContract
|
||||||
|
{
|
||||||
|
public function encrypt(string $text): string;
|
||||||
|
public function decrypt(string $encryptedText): string;
|
||||||
|
}
|
@ -10,8 +10,10 @@ use App\Captcha\Images\Body;
|
|||||||
use App\Captcha\Images\Head;
|
use App\Captcha\Images\Head;
|
||||||
use App\Captcha\Images\ImageManager;
|
use App\Captcha\Images\ImageManager;
|
||||||
use App\Captcha\Images\Lines;
|
use App\Captcha\Images\Lines;
|
||||||
|
use App\Contracts\CryptographyContract;
|
||||||
use App\Services\Api\V1\CaptchaGenerateService;
|
use App\Services\Api\V1\CaptchaGenerateService;
|
||||||
use App\Services\CaptchaToken\CaptchaTokenHandler;
|
use App\Services\CaptchaToken\CaptchaTokenHandler;
|
||||||
|
use App\Services\CryptographyString;
|
||||||
use App\Services\GenerateTokenCommand\GenerateTokenUlidCommand;
|
use App\Services\GenerateTokenCommand\GenerateTokenUlidCommand;
|
||||||
use App\Services\GenerateTokenCommand\GenerateTokenUuidCommand;
|
use App\Services\GenerateTokenCommand\GenerateTokenUuidCommand;
|
||||||
use App\Services\Search\CreateSearchInstanceCommand;
|
use App\Services\Search\CreateSearchInstanceCommand;
|
||||||
@ -35,6 +37,8 @@ final class AppServiceProvider extends ServiceProvider
|
|||||||
$this->app->bind(ImageBody::class, Body::class);
|
$this->app->bind(ImageBody::class, Body::class);
|
||||||
$this->app->bind(ImageLines::class, Lines::class);
|
$this->app->bind(ImageLines::class, Lines::class);
|
||||||
|
|
||||||
|
$this->app->bind(CryptographyContract::class, CryptographyString::class);
|
||||||
|
|
||||||
$this->app->bind(CreateSearchInstanceCommand::class, function () {
|
$this->app->bind(CreateSearchInstanceCommand::class, function () {
|
||||||
return new CreateSearchInstanceCommand(Search::class);
|
return new CreateSearchInstanceCommand(Search::class);
|
||||||
});
|
});
|
||||||
|
19
app/Services/CryptographyString.php
Normal file
19
app/Services/CryptographyString.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Contracts\CryptographyContract;
|
||||||
|
use Illuminate\Support\Facades\Crypt;
|
||||||
|
|
||||||
|
final class CryptographyString implements CryptographyContract
|
||||||
|
{
|
||||||
|
public function encrypt(string $text): string
|
||||||
|
{
|
||||||
|
return Crypt::encryptString($text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function decrypt(string $encryptedText): string
|
||||||
|
{
|
||||||
|
return Crypt::decryptString($encryptedText);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user