Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: symfony6 #128

Open
wants to merge 24 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9a447e5
Symfony 6.0, 6.1 added
Alexandre-T Jul 9, 2022
1ae903a
Symfony 6.1 upgraded
Alexandre-T Jul 10, 2022
aeb8adc
* Fixing PhpUnit deprecations
Alexandre-T Aug 4, 2022
d482977
Php7.4 is not compatible with PSR/cache 3.0
Alexandre-T Aug 4, 2022
8155ee4
Php7.4 is not compatible with PSR/cache 3.0 nor psr/cache 2.0
Alexandre-T Aug 4, 2022
5b25fdd
Php-cs-fixer updated
Alexandre-T Aug 4, 2022
7075186
Removing PHP7.4
Alexandre-T Aug 5, 2022
d1e558f
Issues detected by PhpStan fixed
Alexandre-T Aug 6, 2022
149eeeb
feat: changes for symfony 6
Chris8934 Feb 7, 2023
1149aae
feat: changes for symfony 6
Chris8934 Feb 7, 2023
00c0799
feat: changes for symfony 6
Chris8934 Feb 7, 2023
126e036
feat: changes for symfony 6
Chris8934 Feb 7, 2023
630dfb2
feat: changes for symfony 6
Chris8934 Feb 7, 2023
0639d7e
Merge branch 'master' into feature/symfony6-fix
Chris53897 Feb 7, 2023
dbef726
feat: changes for symfony 6
Chris8934 Feb 7, 2023
c84e442
Merge remote-tracking branch 'origin/feature/symfony6-fix' into featu…
Chris8934 Feb 7, 2023
05eb00d
feat: changes for symfony 6
Chris8934 Feb 7, 2023
f0a47aa
feat: changes for symfony 6
Chris8934 Feb 7, 2023
73cf8ce
feat: changes for symfony 6
Chris8934 Feb 7, 2023
2c7a672
feat: changes for symfony 6
Chris8934 Feb 7, 2023
9c6da91
feat: changes for symfony 6
Chris8934 Feb 7, 2023
0b534cd
feat: changes for symfony 6
Chris8934 Feb 7, 2023
99a3e07
feat: changes for symfony 6
Chris8934 Feb 7, 2023
f132479
feat: changes for symfony 6
Chris8934 Feb 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Tests

on: [ pull_request ]
on: ["push", "pull_request"]

jobs:
static-code-analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- name: Run PHPStan
uses: docker://jakzal/phpqa
with:
Expand All @@ -15,11 +15,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '7.2', '7.4', '8.0' ]
symfony: [ '4.4.*', '5.3.*' ]
php: [ '8.0', '8.1' ]
symfony: [ '5.4.*', '6.0.*' ]
name: Test on Symfony ${{ matrix.symfony }} with PHP ${{ matrix.php }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
Expand All @@ -28,15 +28,34 @@ jobs:
- run: composer require symfony/form:${{ matrix.symfony }} --no-update
- run: composer install
- run: make test

test-highest:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '8.2' ]
symfony: [ '6.2.*' ]
name: Test on Symfony ${{ matrix.symfony }} with PHP ${{ matrix.php }}
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none # disable xdebug, pcov
- run: composer require symfony/framework-bundle:${{ matrix.symfony }} --no-update
- run: composer require symfony/form:${{ matrix.symfony }} --no-update
- run: composer install
- run: make test

test-lowest:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '7.2', '7.3' ]
symfony: [ '3.4.*', '4.4.*' ]
php: [ '8.0' ]
symfony: [ '5.4.*']
name: Test lowest on Symfony ${{ matrix.symfony }} with PHP ${{ matrix.php }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
Expand All @@ -45,11 +64,15 @@ jobs:
- run: composer require symfony/form:${{ matrix.symfony }} --no-update
- run: composer install
- run: make test-lowest

php-cs-fixer:
# https://github.com/jakzal/phpqa php-cs-fixer is not supported for php 8.2 (checked on 07-02-2023)
# https://github.com/jakzal/phpqa/issues/398
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- name: Run PHP-CS-Fixer
uses: docker://jakzal/phpqa
#uses: docker://jakzal/phpqa
uses: docker://jakzal/phpqa:php8.1-alpine
with:
args: php-cs-fixer fix --dry-run
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
vendor/
composer.lock
phpunit.xml
.php_cs.cache
.php-cs-fixer.cache
.phpunit.result.cache
6 changes: 3 additions & 3 deletions .php_cs → .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

return PhpCsFixer\Config::create()
->setRules(array(
return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'no_superfluous_phpdoc_tags' => true,
))
])
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
Expand Down
49 changes: 10 additions & 39 deletions Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,21 @@

class SettingsController extends AbstractController
{
/**
* @var string|null
*/
private $securityRole;

/**
* @var bool
*/
private $securityManageOwnSettings;

/**
* @var TranslatorInterface
*/
private $translator;

/**
* @var SettingsManagerInterface
*/
private $settingsManager;

/**
* @var string
*/
private $template;

public function __construct(
TranslatorInterface $translator,
SettingsManagerInterface $settingsManager,
string $template,
bool $securityManageOwnSettings,
?string $securityRole
private TranslatorInterface $translator,
private SettingsManagerInterface $settingsManager,
private string $template,
private bool $securityManageOwnSettings,
private ?string $securityRole,
) {
$this->translator = $translator;
$this->settingsManager = $settingsManager;
$this->template = $template;
$this->securityManageOwnSettings = $securityManageOwnSettings;
$this->securityRole = $securityRole;
}

/**
* @throws AccessDeniedException
*/
public function manageGlobalAction(Request $request): Response
{
if (null !== $this->securityRole && !$this->get('security.authorization_checker')->isGranted($this->securityRole)) {
if (null !== $this->securityRole && !$this->isGranted($this->securityRole)) {
throw new AccessDeniedException($this->translator->trans('not_allowed_to_edit_global_settings', [], 'settings'));
}

Expand All @@ -69,17 +39,18 @@ public function manageGlobalAction(Request $request): Response
*/
public function manageOwnAction(Request $request): Response
{
if (null === $this->get('security.token_storage')->getToken()) {
$user = $this->getUser();

if (null === $user) {
throw new AccessDeniedException($this->translator->trans('must_be_logged_in_to_edit_own_settings', [], 'settings'));
}

if (!$this->securityManageOwnSettings) {
throw new AccessDeniedException($this->translator->trans('not_allowed_to_edit_own_settings', [], 'settings'));
}

$user = $this->get('security.token_storage')->getToken()->getUser();
if (!$user instanceof SettingsOwnerInterface) {
//For this to work the User entity must implement SettingsOwnerInterface
// For this to work the User entity must implement SettingsOwnerInterface
throw new AccessDeniedException();
}

Expand Down
13 changes: 4 additions & 9 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@ class Configuration implements ConfigurationInterface
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('dmishh_settings');
// Keep compatibility with symfony/config < 4.2
if (!method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->root('dmishh_settings');
} else {
$rootNode = $treeBuilder->getRootNode();
}
$rootNode = $treeBuilder->getRootNode();

$scopes = [
SettingsManagerInterface::SCOPE_ALL,
Expand All @@ -32,7 +27,7 @@ public function getConfigTreeBuilder()
$rootNode
->children()
->scalarNode('template')
->defaultValue('DmishhSettingsBundle:Settings:manage.html.twig')
->defaultValue('@DmishhSettings/Settings/manage.html.twig')
->end()
->scalarNode('cache_service')->defaultNull()->info('A service implementing Psr\Cache\CacheItemPoolInterface')->end()
->integerNode('cache_lifetime')->defaultValue(3600)->end()
Expand Down Expand Up @@ -74,7 +69,7 @@ public function getConfigTreeBuilder()
->end()
->end()
->variableNode('constraints')
->info('The constraints on this option. Example, use constraits found in Symfony\Component\Validator\Constraints')
->info('The constraints on this option. Example, use constraints found in Symfony\Component\Validator\Constraints')
->defaultValue([])
->validate()
->always(function ($v) {
Expand Down
4 changes: 3 additions & 1 deletion DependencyInjection/DmishhSettingsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ class DmishhSettingsExtension extends Extension
{
/**
* {@inheritdoc}
*
* @param array<array<mixed>> $configs
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
Expand Down
47 changes: 15 additions & 32 deletions Entity/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,31 @@

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Table(name="dmishh_settings", indexes={@ORM\Index(name="name_owner_id_idx", columns={"name", "owner_id"})})
* @ORM\Entity
*/
#[ORM\Table(name: 'dmishh_settings')]
#[ORM\Index(name: 'name_owner_id_idx', columns: ['name', 'owner_id'])]
#[ORM\Entity]
class Setting
{
/**
* @var int
*
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
#[ORM\Column(type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private ?int $id;

/**
* @var string|null
*
* @ORM\Column(type="string", length=255)
*/
private $name;
#[ORM\Column(type: 'string', length: 255)]
private ?string $name;

/**
* @var string|null
*
* @ORM\Column(type="text", nullable=true)
*/
private $value;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $value;

/**
* @var string|null
*
* @ORM\Column(name="owner_id", type="string", length=255, nullable=true)
*/
private $ownerId;
#[ORM\Column(name: 'owner_id', type: 'string', length: 255, nullable: true)]
private ?string $ownerId;

public function getId(): ?int
{
return $this->id;
}

public function setName(?string $name)
public function setName(?string $name): void
{
$this->name = $name;
}
Expand All @@ -70,7 +53,7 @@ public function getOwnerId(): ?string
return $this->ownerId;
}

public function setOwnerId(?string $ownerId)
public function setOwnerId(?string $ownerId): void
{
$this->ownerId = $ownerId;
}
Expand Down
7 changes: 7 additions & 0 deletions Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Dmishh\SettingsBundle\Exception;

class InvalidArgumentException extends \InvalidArgumentException implements SettingsException
{
}
11 changes: 11 additions & 0 deletions Exception/UnknownConstraintException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Dmishh\SettingsBundle\Exception;

class UnknownConstraintException extends \RuntimeException implements SettingsException
{
public function __construct(string $className)
{
parent::__construct(sprintf('Constraint class "%s" not found', $className));
}
}
2 changes: 1 addition & 1 deletion Exception/UnknownSerializerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class UnknownSerializerException extends \RuntimeException implements SettingsException
{
public function __construct($serializerClass)
public function __construct(string $serializerClass)
{
parent::__construct(sprintf('Unknown serializer class "%s"', $serializerClass));
}
Expand Down
2 changes: 1 addition & 1 deletion Exception/UnknownSettingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class UnknownSettingException extends \RuntimeException implements SettingsException
{
public function __construct($settingName)
public function __construct(string $settingName)
{
parent::__construct(sprintf('Unknown setting "%s"', $settingName));
}
Expand Down
2 changes: 1 addition & 1 deletion Exception/WrongScopeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class WrongScopeException extends \LogicException implements SettingsException
{
public function __construct($scope, $settingName)
public function __construct(string $scope, string $settingName)
{
if (SettingsManagerInterface::SCOPE_GLOBAL === $scope) {
$message = sprintf(
Expand Down
Loading