Skip to content

Commit 4676e05

Browse files
authored
Merge pull request #271 from Inventis/symfony5
Add support for symfony 5
2 parents 6efb102 + 4ba439a commit 4676e05

File tree

17 files changed

+145
-158
lines changed

17 files changed

+145
-158
lines changed

.github/workflows/test-application.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ jobs:
2727
- php-version: '7.4'
2828
symfony-version: 4.4.*
2929
test-installation: true
30+
- php-version: '7.4'
31+
symfony-version: 5.0.*
32+
test-installation: true
3033

3134
steps:
3235
- name: Checkout project

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
tests/Fixtures/App/var/
22
composer.lock
33
vendor
4+
.phpunit.result.cache

composer.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,36 @@
1515
],
1616
"require": {
1717
"php": "^7.4",
18-
"symfony/framework-bundle": "^4.4",
19-
"symfony/security-core": "^4.4"
18+
"symfony/framework-bundle": "^4.4 || ^5.0",
19+
"symfony/security-core": "^4.4 || ^5.0"
2020
},
2121
"require-dev": {
2222
"jackalope/jackalope-doctrine-dbal": "^1.3",
23-
"symfony/security-bundle": "^4.4",
24-
"symfony/phpunit-bridge": "^4.4.34",
23+
"symfony/security-bundle": "^4.4 || ^5.0",
24+
"symfony/phpunit-bridge": "^4.4.34 || ^5.0",
2525
"mockery/mockery": "^0.9.4",
2626
"symfony-cmf/routing-bundle": "^2.1.0",
2727
"symfony-cmf/testing": "^4.0.0",
2828
"doctrine/dbal": "^2.5",
2929
"doctrine/doctrine-bundle": "^2.0",
3030
"doctrine/phpcr-odm": "^1.4|^2.0 ",
3131
"doctrine/phpcr-bundle": "^2.3.0",
32-
"symfony/browser-kit": "^4.4",
33-
"symfony/form": "^4.4",
34-
"symfony/monolog-bridge": "^4.4",
32+
"symfony/browser-kit": "^4.4 || ^5.0",
33+
"symfony/form": "^4.4 || ^5.0",
34+
"symfony/monolog-bridge": "^4.4 || ^5.0",
3535
"symfony/monolog-bundle": "^3.0",
36-
"symfony/templating": "^4.4",
37-
"symfony/translation": "^4.4",
38-
"symfony/twig-bundle": "^4.4",
39-
"symfony/validator": "^4.4",
40-
"symfony/yaml": "^4.4",
41-
"symfony/asset": "^4.4"
36+
"symfony/templating": "^4.4 || ^5.0",
37+
"symfony/translation": "^4.4 || ^5.0",
38+
"symfony/twig-bundle": "^4.4 || ^5.0",
39+
"symfony/validator": "^4.4 || ^5.0",
40+
"symfony/yaml": "^4.4 || ^5.0",
41+
"symfony/asset": "^4.4 || ^5.0"
4242
},
4343
"suggest": {
44-
"symfony/twig-bundle": "To get access to the CMF twig extension (^3.3 || ^4.4)",
44+
"symfony/twig-bundle": "To get access to the CMF twig extension (^4.4 || ^5.0)",
4545
"doctrine/phpcr-bundle": "To be able to use the CMF twig extension (^1.0)",
4646
"doctrine/phpcr-odm": "To be able to use the CMF twig extension (^1.0)",
47-
"symfony/security-bundle": "To be able to use the publish workflow system (^3.3 || ^4.4)",
47+
"symfony/security-bundle": "To be able to use the publish workflow system (^4.4 || ^5.0)",
4848
"symfony-cmf/routing": "To be able to use the CMF twig extension functions cmf_prev_linkable/cmf_next_linkable (^2.1)",
4949
"symfony-cmf/routing-bundle": "To be able to enable the publish_workflow_listener (^2.1)",
5050
"symfony-cmf/sonata-admin-integration-bundle": "To provide an admin interface for the PHPCR ODM documents."

src/DependencyInjection/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class Configuration implements ConfigurationInterface
2121
*/
2222
public function getConfigTreeBuilder()
2323
{
24-
$treeBuilder = new TreeBuilder();
25-
$rootNode = $treeBuilder->root('cmf_core');
24+
$treeBuilder = new TreeBuilder('cmf_core');
25+
$rootNode = $treeBuilder->getRootNode();
2626

2727
$rootNode
2828
->children()

src/EventListener/PublishWorkflowListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowChecker;
1515
use Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter;
1616
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
17-
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
17+
use Symfony\Component\HttpKernel\Event\RequestEvent;
1818
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1919
use Symfony\Component\HttpKernel\KernelEvents;
2020

@@ -66,7 +66,7 @@ public function setPublishWorkflowPermission($attribute)
6666
/**
6767
* Handling the request event.
6868
*/
69-
public function onKernelRequest(GetResponseEvent $event)
69+
public function onKernelRequest(RequestEvent $event)
7070
{
7171
$request = $event->getRequest();
7272

src/Form/Type/CheckboxUrlLabelFormType.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Symfony\Component\Form\FormInterface;
1717
use Symfony\Component\Form\FormView;
1818
use Symfony\Component\OptionsResolver\OptionsResolver;
19-
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
2019
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2120
use Symfony\Component\Routing\RouterInterface;
2221

@@ -53,7 +52,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
5352
$routes = $options['routes'];
5453
$paths = [];
5554
foreach ($routes as $key => $route) {
56-
$name = isset($route['name']) ? $route['name'] : null;
55+
$name = isset($route['name']) ? $route['name'] : '';
5756
$parameters = isset($route['parameters']) ? $route['parameters'] : [];
5857
$referenceType = isset($route['referenceType']) ? $route['referenceType'] : UrlGeneratorInterface::ABSOLUTE_PATH;
5958
$paths[$key] = $this->router->generate($name, $parameters, $referenceType);
@@ -62,14 +61,6 @@ public function buildView(FormView $view, FormInterface $form, array $options)
6261
parent::buildView($view, $form, $options);
6362
}
6463

65-
/**
66-
* {@inheritdoc}
67-
*/
68-
public function setDefaultOptions(OptionsResolverInterface $resolver)
69-
{
70-
$this->configureOptions($resolver);
71-
}
72-
7364
public function configureOptions(OptionsResolver $resolver)
7465
{
7566
$resolver->setDefaults([

src/PublishWorkflow/PublishWorkflowChecker.php

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,29 +92,12 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthorizationCh
9292
$this->bypassingRole = $bypassingRole;
9393
}
9494

95-
/**
96-
* Checks if the access decision manager supports the given class.
97-
*
98-
* @param string $class A class name
99-
*
100-
* @return bool true if this decision manager can process the class
101-
*/
102-
public function supportsClass($class)
103-
{
104-
return $this->accessDecisionManager->supportsClass($class);
105-
}
106-
10795
/**
10896
* {@inheritdoc}
10997
*/
110-
public function isGranted($attributes, $object = null)
98+
public function isGranted($attribute, $object = null)
11199
{
112-
if (!\is_array($attributes)) {
113-
$attributes = [$attributes];
114-
}
115-
116-
if (1 === \count($attributes)
117-
&& self::VIEW_ATTRIBUTE === reset($attributes)
100+
if (self::VIEW_ATTRIBUTE === $attribute
118101
&& null !== $this->tokenStorage->getToken()
119102
&& $this->authorizationChecker->isGranted($this->bypassingRole)
120103
) {
@@ -128,6 +111,6 @@ public function isGranted($attributes, $object = null)
128111
$token = new AnonymousToken('', '');
129112
}
130113

131-
return $this->accessDecisionManager->decide($token, $attributes, $object);
114+
return $this->accessDecisionManager->decide($token, [$attribute], $object);
132115
}
133116
}

src/PublishWorkflow/Voter/PublishTimePeriodVoter.php

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@
1111

1212
namespace Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\Voter;
1313

14+
use function is_subclass_of;
1415
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishTimePeriodReadInterface;
1516
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowChecker;
1617
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
17-
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
18+
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
1819

1920
/**
2021
* Workflow voter for the PublishTimePeriodReadInterface.
2122
*
2223
* @author David Buchmann <[email protected]>
2324
*/
24-
class PublishTimePeriodVoter implements VoterInterface
25+
class PublishTimePeriodVoter extends Voter
2526
{
2627
/**
2728
* @var \DateTime
@@ -43,61 +44,36 @@ public function setCurrentTime(\DateTime $currentTime)
4344
$this->currentTime = $currentTime;
4445
}
4546

46-
/**
47-
* {@inheritdoc}
48-
*
49-
* @deprecated To be removed when Symfony 2 support is dropped
50-
*/
51-
public function supportsAttribute($attribute)
47+
protected function supports($attribute, $subject)
5248
{
53-
return PublishWorkflowChecker::VIEW_ATTRIBUTE === $attribute
54-
|| PublishWorkflowChecker::VIEW_ANONYMOUS_ATTRIBUTE === $attribute
55-
;
49+
return $subject instanceof PublishTimePeriodReadInterface
50+
&& $this->supportsAttribute($attribute);
5651
}
5752

5853
/**
59-
* {@inheritdoc}
60-
*
61-
* @deprecated To be removed when Symfony 2 support is dropped
62-
*/
63-
public function supportsClass($class)
64-
{
65-
return is_subclass_of($class, PublishTimePeriodReadInterface::class);
66-
}
67-
68-
/**
69-
* {@inheritdoc}
54+
* {@inheritDoc}
7055
*
7156
* @param PublishTimePeriodReadInterface $subject
7257
*/
73-
public function vote(TokenInterface $token, $subject, array $attributes)
58+
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
7459
{
75-
if (!\is_object($subject) || !$this->supportsClass(\get_class($subject))) {
76-
return self::ACCESS_ABSTAIN;
77-
}
78-
7960
$startDate = $subject->getPublishStartDate();
8061
$endDate = $subject->getPublishEndDate();
8162

82-
$decision = self::ACCESS_GRANTED;
83-
foreach ($attributes as $attribute) {
84-
if (!$this->supportsAttribute($attribute)) {
85-
// there was an unsupported attribute in the request.
86-
// now we only abstain or deny if we find a supported attribute
87-
// and the content is not publishable
88-
$decision = self::ACCESS_ABSTAIN;
89-
90-
continue;
91-
}
63+
return (null === $startDate || $this->currentTime >= $startDate)
64+
&& (null === $endDate || $this->currentTime <= $endDate);
65+
}
9266

93-
if (
94-
(null !== $startDate && $this->currentTime < $startDate)
95-
|| (null !== $endDate && $this->currentTime > $endDate)
96-
) {
97-
return self::ACCESS_DENIED;
98-
}
99-
}
67+
public function supportsAttribute(string $attribute): bool
68+
{
69+
return
70+
PublishWorkflowChecker::VIEW_ATTRIBUTE === $attribute
71+
|| PublishWorkflowChecker::VIEW_ANONYMOUS_ATTRIBUTE === $attribute
72+
;
73+
}
10074

101-
return $decision;
75+
public function supportsType(string $subjectType): bool
76+
{
77+
return is_subclass_of($subjectType, PublishTimePeriodReadInterface::class);
10278
}
10379
}

src/PublishWorkflow/Voter/PublishableVoter.php

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,67 +11,45 @@
1111

1212
namespace Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\Voter;
1313

14+
use function is_subclass_of;
1415
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishableReadInterface;
1516
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowChecker;
1617
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
17-
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
18+
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
1819

1920
/**
2021
* Workflow voter for the PublishableReadInterface.
2122
*
2223
* @author David Buchmann <[email protected]>
2324
*/
24-
class PublishableVoter implements VoterInterface
25+
class PublishableVoter extends Voter
2526
{
26-
/**
27-
* {@inheritdoc}
28-
*
29-
* @deprecated To be removed when Symfony 2 support is dropped
30-
*/
31-
public function supportsAttribute($attribute)
27+
protected function supports($attribute, $subject)
3228
{
33-
return PublishWorkflowChecker::VIEW_ATTRIBUTE === $attribute
34-
|| PublishWorkflowChecker::VIEW_ANONYMOUS_ATTRIBUTE === $attribute
35-
;
29+
return $subject instanceof PublishableReadInterface
30+
&& $this->supportsAttribute($attribute);
3631
}
3732

3833
/**
39-
* {@inheritdoc}
34+
* {@inheritDoc}
4035
*
41-
* @deprecated To be removed when Symfony 2 support is dropped
36+
* @param PublishableReadInterface $subject
4237
*/
43-
public function supportsClass($class)
38+
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
4439
{
45-
return is_subclass_of($class, PublishableReadInterface::class);
40+
return $subject->isPublishable();
4641
}
4742

48-
/**
49-
* {@inheritdoc}
50-
*
51-
* @param PublishableReadInterface $subject
52-
*/
53-
public function vote(TokenInterface $token, $subject, array $attributes)
43+
public function supportsAttribute(string $attribute): bool
5444
{
55-
if (!\is_object($subject) || !$this->supportsClass(\get_class($subject))) {
56-
return self::ACCESS_ABSTAIN;
57-
}
58-
59-
$decision = self::ACCESS_GRANTED;
60-
foreach ($attributes as $attribute) {
61-
if (!$this->supportsAttribute($attribute)) {
62-
// there was an unsupported attribute in the request.
63-
// now we only abstain or deny if we find a supported attribute
64-
// and the content is not publishable
65-
$decision = self::ACCESS_ABSTAIN;
66-
67-
continue;
68-
}
69-
70-
if (!$subject->isPublishable()) {
71-
return self::ACCESS_DENIED;
72-
}
73-
}
45+
return
46+
PublishWorkflowChecker::VIEW_ATTRIBUTE === $attribute
47+
|| PublishWorkflowChecker::VIEW_ANONYMOUS_ATTRIBUTE === $attribute
48+
;
49+
}
7450

75-
return $decision;
51+
public function supportsType(string $subjectType): bool
52+
{
53+
return is_subclass_of($subjectType, PublishableReadInterface::class);
7654
}
7755
}

src/Resources/config/publish-workflow.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
<!-- integration with core security service -->
3737

3838
<service id="cmf_core.security.published_voter" class="Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\Voter\PublishableVoter" public="false">
39-
<argument type="service" id="service_container" on-invalid="ignore"/>
4039
<tag name="security.voter"/>
4140
</service>
4241

0 commit comments

Comments
 (0)