Игорь, а можете привести пример? Как может поменяться реализация удаления?
/**
* @param string $id
*
* @return JsonResponse
* @throws BadRequestException
*/
public function exec(string $id): JsonResponse
{
// Получить информацию о подписке.
// $subscription = $this->getUser()->getSubscription();
// Проверить наличие реализации.
if (!$this->locator->has($id)) {
return new JsonResponse([
"error_code" => null,
"error_message" => "Method not found",
"errors" => [],
]);
}
$service = $this->locator->get($id);
// Валидатор
if (method_exists($service, "validate")) {
$violations = $service->validate();
if (count($violations) > 0) {
$errors = [];
foreach ($violations as $violation) {
$errors[] = [
"property_name" => $violation->getPropertyPath(),
"value" => $violation->getInvalidValue(),
"message" => $violation->getMessage(),
"code" => $violation->getCode()
];
}
throw new BadRequestException("Bad Request","bad_request", $errors);
}
}
return $service->exec();
}
/**
* Удаление проекта.
*
* @Route(
* path="/{project_id}",
* methods={"DELETE"}
* )
* @param int $project_id
* @param VariantExecutor $executor
*
* @return Response
*/
public function delete(
int $project_id,
VariantExecutor $executor
): Response
{
return $executor->exec("project_delete");
}
/**
* Удаляет проект.
*/
class Delete extends AbstractDomain implements ExecutorInterface
{
/**
* @return JsonResponse
* @throws NotFoundException
*/
public function exec(): JsonResponse
{
$projectRepository = $this->getEntityManager()->getRepository(Project::class);
$project = $projectRepository->find($this->getRequest()->get("project_id"));
if (!$project instanceof Project) {
throw new NotFoundException("Project not found");
}
$project->setDeleted(true);
$this->getEntityManager()->flush();
return $this->json([
"message" => "ok"
]);
}
}
/{project_id}/users/{user_ids}/association
PUT: /projects/1/users/1/association
DELETE: /projects/1/users/1/association
PUT: /projects/1/users/1,2/association
DELETE: /projects/1/users/1,2/association
Не хочется писать бороду в контроллерах.