<?php
 declare(strict_types=1); namespace Base64Url; use function base64_decode; use function base64_encode; use InvalidArgumentException; use function rtrim; use function strtr; final class Base64Url { public static function encode(string $data, bool $usePadding = false): string { $encoded = strtr(base64_encode($data), '+/', '-_'); return true === $usePadding ? $encoded : rtrim($encoded, '='); } public static function decode(string $data): string { $decoded = base64_decode(strtr($data, '-_', '+/'), true); if (false === $decoded) { throw new InvalidArgumentException('Invalid data provided'); } return $decoded; } } 