Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 21 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,25 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '7.2', '7.4', '8.0' ]
symfony: [ '4.4.*', '5.3.*' ]
php: [ '8.0' ]
symfony: [ '5.4.*', '6.0.*' ]
name: Test on Symfony ${{ matrix.symfony }} with PHP ${{ matrix.php }}
steps:
- uses: actions/checkout@v2
- 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-hightest:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '8.1' ]
symfony: [ '6.1.*' ]
name: Test on Symfony ${{ matrix.symfony }} with PHP ${{ matrix.php }}
steps:
- uses: actions/checkout@v2
Expand All @@ -32,8 +49,8 @@ jobs:
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
Expand Down
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
34 changes: 10 additions & 24 deletions Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,15 @@

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

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

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

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

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

public function __construct(
TranslatorInterface $translator,
Expand All @@ -57,7 +42,7 @@ public function __construct(
*/
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 +54,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
9 changes: 2 additions & 7 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$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 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
2 changes: 1 addition & 1 deletion DependencyInjection/DmishhSettingsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DmishhSettingsExtension extends Extension
/**
* {@inheritdoc}
*/
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
20 changes: 6 additions & 14 deletions Entity/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,33 @@
class Setting
{
/**
* @var int
*
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
private ?int $id;

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

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

/**
* @var string|null
*
* @ORM\Column(name="owner_id", type="string", length=255, nullable=true)
*/
private $ownerId;
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 +62,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
12 changes: 6 additions & 6 deletions Form/Type/SettingsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Dmishh\SettingsBundle\Form\Type;

use Dmishh\SettingsBundle\Exception\SettingsException;
use Dmishh\SettingsBundle\Exception\UnknownConstraintException;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
Expand All @@ -15,7 +15,7 @@
*/
class SettingsType extends AbstractType
{
protected $settingsConfiguration;
protected array $settingsConfiguration;

public function __construct(array $settingsConfiguration)
{
Expand All @@ -25,7 +25,7 @@ public function __construct(array $settingsConfiguration)
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
foreach ($this->settingsConfiguration as $name => $configuration) {
// If setting's value exists in data and setting isn't disabled
Expand All @@ -41,7 +41,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
if (class_exists($class)) {
$constraints[] = new $class($constraintOptions);
} else {
throw new SettingsException(sprintf('Constraint class "%s" not found', $class));
throw new UnknownConstraintException($class);
}
}

Expand All @@ -68,7 +68,7 @@ function ($label) use ($fieldOptions) {
}
}

public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults(
[
Expand All @@ -77,7 +77,7 @@ public function configureOptions(OptionsResolver $resolver)
);
}

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