Skip to content

Commit

Permalink
Symfony 6
Browse files Browse the repository at this point in the history
  • Loading branch information
7ochem committed Dec 1, 2023
1 parent 0eb1ba7 commit 2dfb974
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 82 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- Support for Symfony 6
### Removed
- Support for PHP 7.4
### Changed
- Made PageController final (natively instead of by annotation)
- Using attributes instead of annotations for routes
### Added|Changed|Deprecated|Removed|Fixed|Security
Nothing so far

Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
"type": "symfony-bundle",
"license": "MIT",
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.0",
"sonata-project/admin-bundle": "^4.21.0",
"symfony/config": "^5.4",
"symfony/console": "^5.4",
"symfony/security-core": "^5.4",
"symfony/config": "^5.4 || ^6",
"symfony/console": "^5.4 || ^6",
"symfony/security-core": "^5.4 || ^6",
"twig/twig": "^2.7 || ^3",
"zicht/admin-bundle": "^8",
"zicht/framework-extra-bundle": "^10",
"zicht/menu-bundle": "^6",
"zicht/url-bundle": "^7",
"zicht/admin-bundle": "^8 || dev-feature-symfony-6 as 9.0.0",
"zicht/framework-extra-bundle": "^10 || dev-feature-symfony-6 as 11.0.0",
"zicht/menu-bundle": "^6 || dev-feature-symfony-6 as 7.0.0",
"zicht/url-bundle": "^7 || dev-feature-symfony-6 as 8.0.0",
"zicht/util": "^2"
},
"require-dev": {
Expand Down
15 changes: 6 additions & 9 deletions src/Command/AliasCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Zicht\Bundle\PageBundle\Command;

use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -19,18 +20,14 @@
/**
* Generates URL aliases for all pages.
*/
#[AsCommand('zicht:page:alias')]
class AliasCommand extends Command
{
protected static $defaultName = 'zicht:page:alias';
private ManagerRegistry $doctrine;

/** @var ManagerRegistry */
private $doctrine;
private Aliaser $aliaser;

/** @var Aliaser */
private $aliaser;

/** @var PageManager */
private $pageManager;
private PageManager $pageManager;

public function __construct(ManagerRegistry $doctrine, Aliaser $aliaser, PageManager $pageManager, string $name = null)
{
Expand Down Expand Up @@ -94,6 +91,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$progress->finish();
call_user_func($onDone);

return 0;
return Command::SUCCESS;
}
}
20 changes: 9 additions & 11 deletions src/Command/CheckContentItemsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,27 @@
namespace Zicht\Bundle\PageBundle\Command;

use Doctrine\Persistence\ManagerRegistry;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;
use Zicht\Bundle\PageBundle\Entity\Page;

#[AsCommand('zicht:page:contentitems:check')]
class CheckContentItemsCommand extends Command
{
/** @var bool */
protected $isVeryVerbose;
private ManagerRegistry $doctrine;

/** @var bool */
protected $force;
/** @psalm-suppress PropertyNotSetInConstructor */
protected LoggerInterface $logger;

/** @var ConsoleLogger */
protected $logger;
protected bool $isVeryVerbose = false;

/** @var ManagerRegistry */
private $doctrine;

protected static $defaultName = 'zicht:page:contentitems:check';
protected bool $force = false;

public function __construct(ManagerRegistry $doctrine, string $name = null)
{
Expand Down Expand Up @@ -118,7 +116,7 @@ function ($name) use ($matrix) {
}
}

return 0;
return Command::SUCCESS;
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/Command/CleanAliasCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Doctrine\DBAL\Connection;
use Symfony\Bridge\Doctrine\ManagerRegistry;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -17,12 +18,10 @@
/**
* Remove aliases referencing pages that do not exist anymore.
*/
#[AsCommand('zicht:page:clean:alias')]
class CleanAliasCommand extends Command
{
protected static $defaultName = 'zicht:page:clean:alias';

/** @var ManagerRegistry */
private $doctrine;
private ManagerRegistry $doctrine;

public function __construct(ManagerRegistry $doctrine, string $name = null)
{
Expand Down Expand Up @@ -103,6 +102,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$connection->query(sprintf('DELETE FROM url_alias WHERE id IN (%s)', implode(', ', $aliasIds)));
$output->writeln(sprintf('Removed %d aliases', count($records)));

return 0;
return Command::SUCCESS;
}
}
22 changes: 9 additions & 13 deletions src/Command/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,29 @@

namespace Zicht\Bundle\PageBundle\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Zicht\Bundle\PageBundle\Manager\PageManager;
use Zicht\Bundle\UrlBundle\Url\Provider;
use Zicht\Bundle\UrlBundle\Url\Provider as UrlProvider;

/**
* List all page urls. Useful for testing.
*/
#[AsCommand('zicht:page:list')]
class ListCommand extends Command
{
protected static $defaultName = 'zicht:page:list';
private PageManager $pageManager;

/** @var PageManager */
private $pageManager;
private UrlProvider $urlProvider;

/** @var Provider */
private $provider;

public function __construct(PageManager $pageManager, Provider $provider, string $name = null)
public function __construct(PageManager $pageManager, UrlProvider $urlProvider, string $name = null)
{
parent::__construct($name);
$this->pageManager = $pageManager;
$this->provider = $provider;
$this->urlProvider = $urlProvider;
}

protected function configure()
Expand All @@ -40,14 +38,12 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output): int
{
$pages = $this->pageManager->getBaseRepository()->findAll();
$urlProvider = $this->provider;

$baseUrl = rtrim($input->getOption('base-url'), '/');

foreach ($pages as $page) {
$output->writeln($baseUrl . $urlProvider->url($page));
$output->writeln($baseUrl . $this->urlProvider->url($page));
}

return 0;
return Command::SUCCESS;
}
}
46 changes: 13 additions & 33 deletions src/Controller/PageController.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
<?php

Check warning on line 1 in src/Controller/PageController.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

Found violation(s) of type: no_superfluous_phpdoc_tags

Check warning on line 1 in src/Controller/PageController.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

Found violation(s) of type: phpdoc_trim
/**
* @copyright Zicht Online <https://zicht.nl>
*/

namespace Zicht\Bundle\PageBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Attribute\Route;
use Zicht\Bundle\PageBundle\Manager\PageManager;
use Zicht\Bundle\PageBundle\Security\PageViewValidation;
use Zicht\Bundle\UrlBundle\Url\Provider as UrlProvider;

/**
* Controller for public page actions
*
* @final in the future. You should not extend this PageController as this will result in duplication of
* @final You should not extend this PageController as this will result in duplication of
* its routes and will cause unexpected behaviour. Use the {@see PageControllerTrait} to use handy functionalities
* that were formerly available only in this PageController.
* that were previously available only in this PageController.
*/
class PageController extends AbstractController
final class PageController extends AbstractController
{
use PageControllerTrait;

Expand Down Expand Up @@ -51,40 +48,23 @@ public static function getSubscribedServices(): array
);
}

/**
* Redirects to the page identified by the passed id.
*
* @param string $id
* @Route("page/{id}/redirect", name="page_redirect")
*/
public function redirectAction($id): RedirectResponse
/** Redirects to the page identified by the passed id. */
#[Route('page/{id}/redirect', name: 'page_redirect')]
public function redirectAction(int $id): RedirectResponse
{
return new RedirectResponse($this->generateUrl('zicht_page_page_view', ['id' => $id]));
}

/**
* Redirects to the specified page. This is useful for posting an autocomplete ID, which in turn redirects to
* the specified page.
*
* @Route("/goto")
*/
public function gotoAction(Request $r): RedirectResponse
/** Redirects to the specified page. This is useful for posting an autocomplete ID, which in turn redirects to the specified page. */
#[Route('/goto', name: 'page_goto')]
public function gotoAction(Request $request): RedirectResponse
{
return $this->redirect(
$this->urlProvider->url($this->getPageManager()->findForView($r->get('id')))
);
return $this->redirect($this->urlProvider->url($this->getPageManager()->findForView($request->get('id'))));
}

/**
* @param string $id
* @Route("page/{id}")
*/
public function viewAction(Request $request, $id): Response
#[Route('page/{id}', name: 'page_view')]
public function viewAction(Request $request, int $id): Response
{
if (get_class($this) !== __CLASS__) {
trigger_deprecation('zicht/page-bundle', '8.2', 'Extending the "%s" controller is deprecated as it will be final in the future. Implement your own "viewAction()" and/or use "%s" functionalities.', __CLASS__, PageControllerTrait::class);
}

$page = $this->pageManager->findForView($id);

$this->isViewActionAllowed($page);
Expand Down
2 changes: 1 addition & 1 deletion src/Type/ContentItemRegionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function finishView(FormView $view, FormInterface $form, array $options)
$view->vars['matrix'] = json_encode($matrix);
}

public function getBlockPrefix()
public function getBlockPrefix(): string
{
return 'zicht_content_item_region';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Type/ContentItemTypeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
}
}

public function getBlockPrefix()
public function getBlockPrefix(): string
{
return 'zicht_content_item_type';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Type/DiscriminatorMapType.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function getParent()
return ChoiceType::class;
}

public function getBlockPrefix()
public function getBlockPrefix(): string
{
return 'zicht_discriminator_map';
}
Expand Down

0 comments on commit 2dfb974

Please sign in to comment.