PHP code example of omegacode / jwt-secured-api-twig
1. Go to this page and download the library: Download omegacode/jwt-secured-api-twig 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/ */
omegacode / jwt-secured-api-twig example snippets
namespace Vendor\MyProject\Action;
use OmegaCode\JwtSecuredApiTwig\Action\AbstractTwigAction;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
class IndexAction extends AbstractTwigAction
{
public function __invoke(Request $request, Response $response): Response
{
return $this->render($response, [
'currentTime' => time(),
]);
}
protected function getTemplateFilePath(): string
{
return 'index.html'; // res/templates/index.html
}
}
namespace Vendor\MyProject\Subscriber;
use OmegaCode\JwtSecuredApiTwig\Event\Twig\CollectTemplatesEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class TwigTemplateSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
CollectTemplatesEvent::NAME => 'onCollectTemplates',
];
}
public function onCollectTemplates(CollectTemplatesEvent $event): void
{
$event->addTemplatePath(APP_ROOT_PATH . '/my/custom/templates');
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.