PHP code example of laulamanapps / tokenable-symfony

1. Go to this page and download the library: Download laulamanapps/tokenable-symfony 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/ */

    

laulamanapps / tokenable-symfony example snippets


// config/bundles.php
return [
    // ...
    LauLamanApps\Tokenable\TokenableBundle::class => ['all' => true],
];

use LauLamanApps\Tokenable\Attribute\Tokenable;

#[ORM\Entity]
#[Tokenable(prefix: 'per', prime: 2062703171, inverse: 392512107, random: 628259887)]
class Person
{
    public function getId(): PersonId { /* ... */ }
}

#[ORM\Entity]
#[ORM\InheritanceType('JOINED')]
#[ORM\DiscriminatorColumn(name: 'type', type: 'string')]
#[ORM\DiscriminatorMap(['direct_debit' => DirectDebitMandate::class, 'credit_card' => CreditCardMandate::class])]
#[Tokenable(prefix: 'mnd', prime: 1580030173, inverse: 59260789, random: 1163945558)]
abstract class AbstractMandate { /* ... */ }

#[Route('/people/{person}', name: 'person_show')]
public function __invoke(Person $person): Response
{
    // $person is already loaded from the token in the URL.
}

use LauLamanApps\Tokenable\Tokenizer;

public function __construct(private readonly Tokenizer $tokenizer) {}

$token       = $this->tokenizer->encode($person);      // 'per_3f9k2'
[$class, $id] = $this->tokenizer->decode('per_3f9k2');  // [Person::class, 42]