PHP code example of fundraisingbox / symfony-precognition
1. Go to this page and download the library: Download fundraisingbox/symfony-precognition 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/ */
fundraisingbox / symfony-precognition example snippets
return [
// ...
FundraisingBox\Precognition\PrecognitionBundle::class => ['all' => true],
];
use FundraisingBox\Precognition\Attribute\Precognitive;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Validator\Constraints as Assert;
final class UserDto
{
public function __construct(
#[Assert\NotBlank]
public string $name = '',
) {
}
}
final class UserController
{
#[Route('/users', methods: ['POST'])]
#[Precognitive]
public function create(#[MapRequestPayload] UserDto $user): Response
{
// Never runs for a precognitive request.
}
}