WIP: Symfony 6 project remake #2

Draft
skobkin wants to merge 103 commits from symfony6_remake into master
3 changed files with 16 additions and 16 deletions
Showing only changes of commit 430632c8e4 - Show all commits

View file

@ -20,6 +20,8 @@ services:
$pointApiDelay: 5000 $pointApiDelay: 5000
$pointAppUserId: '' $pointAppUserId: ''
$pointApiClient: '@app.point.http_client' $pointApiClient: '@app.point.http_client'
# Crawler API
$crawlerToken: ''
# makes classes in src/ available to be used as services # makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name # this creates a service per class whose id is the fully-qualified class name

View file

@ -1,6 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace src\PointToolsBundle\Controller\Api; namespace App\Controller\Api;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@ -15,9 +16,6 @@ class AbstractApiController extends AbstractController
], $code); ], $code);
} }
/**
*
*/
protected function createErrorResponse(string $message, int $code = 400): Response protected function createErrorResponse(string $message, int $code = 400): Response
{ {
return $this->json([ return $this->json([

View file

@ -1,22 +1,19 @@
<?php <?php
declare(strict_types=1);
namespace src\PointToolsBundle\Controller\Api; namespace App\Controller\Api;
use App\DTO\Api\PostsPage;
use App\Factory\Blog\PostFactory;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use JMS\Serializer\SerializerInterface; use JMS\Serializer\SerializerInterface;
use src\PointToolsBundle\DTO\Api\PostsPage;
use src\PointToolsBundle\Service\Factory\Blogs\PostFactory;
use Symfony\Component\HttpFoundation\{Request, Response}; use Symfony\Component\HttpFoundation\{Request, Response};
use src\PointToolsBundle\Controller\Api\AbstractApiController;
class CrawlerController extends AbstractApiController class CrawlerController extends AbstractApiController
{ {
/** @var string */ public function __construct(
private $crawlerToken; private readonly string $crawlerToken,
) {
public function __construct(string $crawlerToken)
{
$this->crawlerToken = $crawlerToken;
} }
public function receiveAllPageAction(Request $request, SerializerInterface $serializer, PostFactory $postFactory, EntityManagerInterface $em): Response public function receiveAllPageAction(Request $request, SerializerInterface $serializer, PostFactory $postFactory, EntityManagerInterface $em): Response
@ -24,7 +21,10 @@ class CrawlerController extends AbstractApiController
$remoteToken = $request->request->get('token'); $remoteToken = $request->request->get('token');
if (!$this->crawlerToken || ($this->crawlerToken !== $remoteToken)) { if (!$this->crawlerToken || ($this->crawlerToken !== $remoteToken)) {
return $this->createErrorResponse('Token error. Please check it in crawler and API parameters.', Response::HTTP_FORBIDDEN); return $this->createErrorResponse(
'Token error. Please check it in crawler and API parameters.',
Response::HTTP_FORBIDDEN,
);
} }
$json = $request->request->get('json'); $json = $request->request->get('json');