-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
669 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Contract; | ||
|
||
interface SearchStepInterface | ||
{ | ||
public function isDangerous(): bool; | ||
|
||
public function executeStep(string|array $query, array $parameters): SearchStepResultInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Contract; | ||
|
||
interface SearchStepResultInterface | ||
{ | ||
public function getResults(): array; | ||
|
||
public function setResults(array $results): self; | ||
|
||
public function getDebugData(): array; | ||
|
||
public function setDebugData(array $debugData): self; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Search; | ||
|
||
use App\EventSystem\SearchQuery\Event\SearchQueryEvent; | ||
use App\Factory\Exception\Client400BadContentExceptionFactory; | ||
use App\Factory\Exception\Client400MissingPropertyExceptionFactory; | ||
use App\Factory\Exception\Server500InternalServerErrorExceptionFactory; | ||
use App\Response\JsonResponse; | ||
use App\Security\AccessChecker; | ||
use App\Security\AuthProvider; | ||
use App\Type\SearchQueryType; | ||
use Psr\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||
* @SuppressWarnings(PHPMD.NPathComplexity) | ||
*/ | ||
class PostSearch3Controller extends AbstractController | ||
{ | ||
public function __construct( | ||
private AuthProvider $authProvider, | ||
private AccessChecker $accessChecker, | ||
private EventDispatcherInterface $eventDispatcher, | ||
private Client400BadContentExceptionFactory $client400BadContentExceptionFactory, | ||
private Client400MissingPropertyExceptionFactory $client400MissingPropertyExceptionFactory, | ||
private Server500InternalServerErrorExceptionFactory $server500InternalServerErrorExceptionFactory | ||
) { | ||
} | ||
|
||
#[Route( | ||
'/search3', | ||
name: 'post-search3', | ||
methods: ['POST'] | ||
)] | ||
public function postSearch3(Request $request): Response | ||
{ | ||
$body = \Safe\json_decode($request->getContent(), true); | ||
|
||
if (!array_key_exists('queries', $body)) { | ||
throw $this->client400MissingPropertyExceptionFactory->createFromTemplate('queries', 'list with at least one query object'); | ||
} | ||
$queries = $body['queries']; | ||
|
||
$previousResult = []; | ||
foreach ($queries as $query) { | ||
if (!array_key_exists('type', $query)) { | ||
throw $this->client400MissingPropertyExceptionFactory->createFromTemplate('queries[].type', 'valid query type'); | ||
} | ||
$type = $query['type']; | ||
if (!is_string($type)) { | ||
throw $this->client400BadContentExceptionFactory->createFromTemplate('queries[].type', 'string', $type); | ||
} | ||
$type = SearchQueryType::from($type); | ||
if (!array_key_exists('query', $query)) { | ||
throw $this->client400MissingPropertyExceptionFactory->createFromTemplate('queries[].query', 'valid query'); | ||
} | ||
$searchQuery = $query['query']; | ||
$searchQueryEvent = new SearchQueryEvent($type, $searchQuery, $previousResult); | ||
$this->eventDispatcher->dispatch($searchQueryEvent); | ||
$previousResult = $searchQueryEvent->getResult(); | ||
} | ||
$result = $previousResult; | ||
|
||
// if () {} | ||
|
||
return new JsonResponse($result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.