i try to fix the Cookiegenerator.php file for generate a tokken with my JWT key but i have somes errors :
<?php
declare(strict_types=1);
namespace App\Services\Mercure;
use App\Entity\Channel;
use Lcobucci\JWT\Token\Builder;
use Lcobucci\JWT\Signer\Hmac\Sha256;
use Lcobucci\JWT\Signer\Key;
class CookieGenerator
{
private string $key;
public function __construct(string $key)
{
$this->key = $key;
}
public function __invoke(Channel $channel): string
{
$signer = new Sha256();
return (new Builder())
->withClaim('mercure', ['subscribe' => [sprintf('http://astrochat.com/channel/%s', $channel->getId())]])
->getToken($signer, new Key($this->key))
->__toString()
;
}
}
Errors :
Expected 2 arguments. Found 0. (L 24) Undefined method '__toString'. (L 27)
I tried to redo the file and pass some parameters to Builder but nothing to do... Basically the file uses the use use Lcobucci\JWT\Builder; I thought I understood that it was no longer used so I use use Lcobucci\JWT\Token\Builder; Someone would have any idea ? Thanks a lot
As discussed in the comments above, the token class no longer implements the
Stringableinterface and also has no__toString()method (which would implicitly implement it as of PHP 8.0), so the call to the magic string method:now needs to be updated to this:
Also the
Builderinstance now requires 2 parameters (docs), an encoder and a formatter, example: