Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Symfony 6
Browse files Browse the repository at this point in the history
7ochem committed Mar 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 0eb1ba7 commit a36dc43
Showing 18 changed files with 83 additions and 101 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/.github export-ignore
/.php-cs-fixer.dist.php export-ignore
/phpunit.xml.dist export-ignore
/psalm.xml export-ignore
/tests/ export-ignore
2 changes: 1 addition & 1 deletion .github/workflows/qa.yml
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
php: [ '7.4', '8.1' ]
php: ['8.1', '8.3']
name: PHP ${{ matrix.php }}
steps:
- uses: actions/checkout@v3
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

21 changes: 13 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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 || ^9.x-dev",
"zicht/framework-extra-bundle": "^10 || ^11.x-dev",
"zicht/menu-bundle": "^6 || ^7.x-dev",
"zicht/url-bundle": "^7 || ^8.x-dev",
"zicht/util": "^2"
},
"require-dev": {
@@ -38,5 +38,10 @@
"lint": "php-cs-fixer fix --dry-run --diff -vvv",
"lint-fix": "php-cs-fixer fix",
"test": "phpunit"
},
"extra": {
"branch-alias": {
"dev-feature-symfony-6": "9.x-dev"
}
}
}
8 changes: 4 additions & 4 deletions src/AdminMenu/TranslatePageEventPropagationBuilder.php
Original file line number Diff line number Diff line change
@@ -52,8 +52,8 @@ public function buildAndForwardEvent(Event $e): void
$this->router->generate(
'zicht_page_page_view',
[
'id' => $page->getId(),
'_locale' => 'zz',
'id' => $page->getId(),
'_locale' => 'zz',
]
),
'Vertalingen'
@@ -66,8 +66,8 @@ public function buildAndForwardEvent(Event $e): void
$this->router->generate(
'zicht_page_page_view',
[
'id' => $page->getId(),
'_locale' => $page->getLanguage(),
'id' => $page->getId(),
'_locale' => $page->getLanguage(),
]
),
'Pagina herladen'
15 changes: 6 additions & 9 deletions src/Command/AliasCommand.php
Original file line number Diff line number Diff line change
@@ -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;
@@ -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)
{
@@ -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
@@ -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)
{
@@ -118,7 +116,7 @@ function ($name) use ($matrix) {
}
}

return 0;
return Command::SUCCESS;
}

/**
9 changes: 4 additions & 5 deletions src/Command/CleanAliasCommand.php
Original file line number Diff line number Diff line change
@@ -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;
@@ -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)
{
@@ -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
@@ -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()
@@ -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;
}
}
2 changes: 1 addition & 1 deletion src/Controller/AbstractController.php
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
use Zicht\Bundle\PageBundle\Manager\PageManager;

/**
* @deprecated extend {@see \Symfony\Bundle\FrameworkBundle\Controller\AbstractController} directly.
* @deprecated extend {@see BaseAbstractController} directly.
*/
abstract class AbstractController extends BaseAbstractController
{
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
/**
* @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;

@@ -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')]
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}')]
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);
2 changes: 1 addition & 1 deletion src/Event/PageViewEvent.php
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ public function __construct(PageInterface $page)
/**
* Return the page attached to this event
*
* @return \Zicht\Bundle\PageBundle\Model\PageInterface
* @return PageInterface
*/
public function getPage()
{
2 changes: 1 addition & 1 deletion src/Type/ContentItemRegionType.php
Original file line number Diff line number Diff line change
@@ -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';
}
2 changes: 1 addition & 1 deletion src/Type/ContentItemTypeType.php
Original file line number Diff line number Diff line change
@@ -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';
}
2 changes: 1 addition & 1 deletion src/Type/DiscriminatorMapType.php
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ public function getParent()
return ChoiceType::class;
}

public function getBlockPrefix()
public function getBlockPrefix(): string
{
return 'zicht_discriminator_map';
}
2 changes: 1 addition & 1 deletion src/ZichtPageBundle.php
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
*/
class ZichtPageBundle extends Bundle
{
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);

Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ public function testBareConfig()

public function testValidConfig()
{
$c = new \Symfony\Component\DependencyInjection\ContainerBuilder();
$c = new ContainerBuilder();

$defs = [
'zicht_page.page_manager' => new \Symfony\Component\DependencyInjection\Definition(),
@@ -64,15 +64,15 @@ public function testValidConfig()
$c->setParameter(
'zicht_page.config',
[
'admin' => [
'base' => [
'page' => 'page.admin',
'contentItem' => 'ci.admin',
'admin' => [
'base' => [
'page' => 'page.admin',
'contentItem' => 'ci.admin',
],
],
],
]
);
$pass = new \Zicht\Bundle\PageBundle\DependencyInjection\CompilerPass\GenerateAdminServicesCompilerPass();
$pass = new GenerateAdminServicesCompilerPass();
$pass->process($c);
$this->expectNotToPerformAssertions();
}
4 changes: 0 additions & 4 deletions z2.yml

This file was deleted.

0 comments on commit a36dc43

Please sign in to comment.