Skip to content

Commit

Permalink
refactor: Delete unused CompatBundle Controller methods
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Delete Controller::findTranslationForLocale, Controller::renderJson, Controller::denyResourceExceptForFormats, Controller::getHandlerFactory, Controller::getPreviewResolver methods
  • Loading branch information
ambroisemaupate committed Dec 2, 2024
1 parent e304ce2 commit a79d46b
Showing 1 changed file with 8 additions and 79 deletions.
87 changes: 8 additions & 79 deletions lib/RoadizCompatBundle/src/Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,25 @@
namespace RZ\Roadiz\CompatBundle\Controller;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Log\LoggerInterface;
use RZ\Roadiz\Core\AbstractEntities\PersistableInterface;
use RZ\Roadiz\Core\AbstractEntities\TranslationInterface;
use RZ\Roadiz\Core\Handlers\HandlerFactoryInterface;
use RZ\Roadiz\CoreBundle\Bag\NodeTypes;
use RZ\Roadiz\CoreBundle\Bag\Roles;
use RZ\Roadiz\CoreBundle\Bag\Settings;
use RZ\Roadiz\CoreBundle\Entity\NodesSources;
use RZ\Roadiz\CoreBundle\Entity\Translation;
use RZ\Roadiz\CoreBundle\EntityApi\NodeApi;
use RZ\Roadiz\CoreBundle\EntityApi\NodeSourceApi;
use RZ\Roadiz\CoreBundle\Exception\ForceResponseException;
use RZ\Roadiz\CoreBundle\Exception\NoTranslationAvailableException;
use RZ\Roadiz\CoreBundle\Form\Error\FormErrorSerializer;
use RZ\Roadiz\CoreBundle\ListManager\EntityListManager;
use RZ\Roadiz\CoreBundle\ListManager\EntityListManagerInterface;
use RZ\Roadiz\CoreBundle\Node\NodeFactory;
use RZ\Roadiz\CoreBundle\Preview\PreviewResolverInterface;
use RZ\Roadiz\CoreBundle\Repository\TranslationRepository;
use RZ\Roadiz\CoreBundle\SearchEngine\Indexer\NodeIndexer;
use RZ\Roadiz\CoreBundle\SearchEngine\NodeSourceSearchHandlerInterface;
use RZ\Roadiz\CoreBundle\Security\Authorization\Chroot\NodeChrootResolver;
Expand All @@ -40,7 +37,6 @@
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
Expand Down Expand Up @@ -180,19 +176,8 @@ protected function getStopwatch(): Stopwatch
}

/**
* @deprecated
*/
protected function getPreviewResolver(): PreviewResolverInterface
{
/** @var PreviewResolverInterface $previewResolver */
$previewResolver = $this->container->get(PreviewResolverInterface::class);

return $previewResolver;
}

/**
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*
* @deprecated
*/
Expand Down Expand Up @@ -225,17 +210,6 @@ protected function getSettingsBag(): Settings
return $settingsBag;
}

/**
* @deprecated
*/
protected function getHandlerFactory(): HandlerFactoryInterface
{
/** @var HandlerFactoryInterface $handlerFactory */ // php-stan hint
$handlerFactory = $this->container->get(HandlerFactoryInterface::class);

return $handlerFactory;
}

/**
* @deprecated
*/
Expand All @@ -251,6 +225,9 @@ protected function getLogger(): LoggerInterface
* Wrap `$this->get('urlGenerator')->generate`.
*
* @param string|NodesSources $route
*
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
protected function generateUrl($route, array $parameters = [], int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string
{
Expand Down Expand Up @@ -295,35 +272,6 @@ public function removeTrailingSlashAction(Request $request): RedirectResponse
return $this->redirect($url, Response::HTTP_MOVED_PERMANENTLY);
}

/**
* @throws NonUniqueResultException
*/
protected function findTranslationForLocale(?string $_locale = null): TranslationInterface
{
if (null === $_locale) {
$defaultTranslation = $this->getDoctrine()->getRepository(Translation::class)->findDefault();
if (null === $defaultTranslation) {
throw new NoTranslationAvailableException();
}

return $defaultTranslation;
}
/** @var TranslationRepository $repository */
$repository = $this->getDoctrine()->getRepository(Translation::class);

if ($this->getPreviewResolver()->isPreview()) {
$translation = $repository->findOneByLocaleOrOverrideLocale($_locale);
} else {
$translation = $repository->findOneAvailableByLocaleOrOverrideLocale($_locale);
}

if (null !== $translation) {
return $translation;
}

throw new NoTranslationAvailableException();
}

/**
* Return a Response from a template string with its rendering assignation.
*
Expand Down Expand Up @@ -358,35 +306,16 @@ protected function getNamespacedView(string $view, string $namespace = ''): stri
return $view;
}

public function renderJson(array $data = [], int $httpStatus = Response::HTTP_OK): JsonResponse
{
return $this->json($data, $httpStatus);
}

/**
* Throw a NotFoundException if request format is not accepted.
*
* @return void
*/
protected function denyResourceExceptForFormats(Request $request, array $acceptableFormats = ['html'])
{
if (!in_array($request->get('_format', 'html'), $acceptableFormats)) {
throw $this->createNotFoundException(sprintf('Resource not found for %s format', $request->get('_format', 'html')));
}
}

/**
* Creates and returns a form builder instance.
*
* @param string $name Form name
* @param mixed $data The initial data for the form
* @param array $options Options for the form
*
* @return FormBuilderInterface
*
* @deprecated Use constructor service injection
*/
protected function createNamedFormBuilder(string $name = 'form', $data = null, array $options = [])
protected function createNamedFormBuilder(string $name = 'form', mixed $data = null, array $options = []): FormBuilderInterface
{
/** @var FormFactoryInterface $formFactory */
$formFactory = $this->container->get(FormFactoryInterface::class);
Expand Down

0 comments on commit a79d46b

Please sign in to comment.