PHP code example of ivanstan / symfony-extend-request
1. Go to this page and download the library: Download ivanstan/symfony-extend-request 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/ */
ivanstan / symfony-extend-request example snippets
use App\Request\ExtendedRequest;
class ProductsController extends AbstractController {
#[Route('product/search')]
public function search(SearchProductsRequest $request): JsonResponse
{
return new JsonResponse([
'name' => $request->getName(),
]);
}
}
namespace App\Request;
use Symfony\Component\HttpFoundation\Request;
class SearchProductsRequest extends Request
{
public function getName(): string
{
return $this->get('name');
}
}
namespace App\Request;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\Service\Attribute\Required;
class ExtendedRequest extends Request
{
protected LoggerInterface $logger;
#[Required]
public function setLogger(LoggerInterface $logger):void
{
$this->logger = $logger;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.