1. Go to this page and download the library: Download nzo/url-encryptor-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Nzo\UrlEncryptorBundle\Annotations\ParamDecryptor;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
class InvoiceController
{
#[Route('/invoice/{id}', name: 'invoice_show')]
#[ParamDecryptor(['id'])]
public function show(string $id): Response
{
// $id is "42"
}
}
use Nzo\UrlEncryptorBundle\Encryptor\Encryptor;
use Nzo\UrlEncryptorBundle\Exception\DecryptionException;
class InvoiceLinks
{
public function __construct(private Encryptor $encryptor)
{
}
public function example(): void
{
$encrypted = $this->encryptor->encrypt('42');
try {
$id = $this->encryptor->decrypt($encrypted);
} catch (DecryptionException $e) {
// not a value this application encrypted
}
}
}
#[ParamDecryptor(['id'], context: 'invoice')]
public function show(string $id): Response