Skip to content

Commit 1150811

Browse files
Merge pull request #17 from emulienfou/master
Update to be compatible with SF3 and SF4
2 parents b379d6b + 63fab49 commit 1150811

File tree

6 files changed

+46
-27
lines changed

6 files changed

+46
-27
lines changed

Controller/RatingController.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
class RatingController extends Controller
1212
{
13-
public function showRateAction($id, Request $request)
13+
public function showRateAction($id)
1414
{
15-
$ratingManager = $this->container->get('dcs_rating.manager.rating');
15+
$ratingManager = $this->container->get('dcs_rating.manager.rating.default');
1616

1717
if (null === $rating = $ratingManager->findOneById($id)) {
1818
$rating = $ratingManager->createRating($id);
@@ -26,17 +26,17 @@ public function showRateAction($id, Request $request)
2626
));
2727
}
2828

29-
public function controlAction($id, Request $request)
29+
public function controlAction(Request $request, $id)
3030
{
31-
$ratingManager = $this->container->get('dcs_rating.manager.rating');
31+
$ratingManager = $this->container->get('dcs_rating.manager.rating.default');
3232

3333
if (null === $rating = $ratingManager->findOneById($id)) {
3434
$rating = $ratingManager->createRating($id);
3535
$ratingManager->saveRating($rating);
3636
}
3737

3838
// check if the user has permission to express the vote on entity Rating
39-
if (!$this->container->get('security.context')->isGranted($rating->getSecurityRole())) {
39+
if (!$this->container->get('security.authorization_checker')->isGranted($rating->getSecurityRole())) {
4040
$viewName = 'star';
4141
} else {
4242
// check if the voting system allows multiple votes. Otherwise
@@ -59,13 +59,13 @@ public function controlAction($id, Request $request)
5959
));
6060
}
6161

62-
public function addVoteAction($id, $value, Request $request)
62+
public function addVoteAction(Request $request, $id, $value)
6363
{
64-
if (null === $rating = $this->container->get('dcs_rating.manager.rating')->findOneById($id)) {
64+
if (null === $rating = $this->container->get('dcs_rating.manager.rating.default')->findOneById($id)) {
6565
throw new NotFoundHttpException('Rating not found');
6666
}
6767

68-
if (null === $rating->getSecurityRole() || !$this->container->get('security.context')->isGranted($rating->getSecurityRole())) {
68+
if (null === $rating->getSecurityRole() || !$this->container->get('security.authorization_checker')->isGranted($rating->getSecurityRole())) {
6969
throw new AccessDeniedHttpException('You can not perform the evaluation');
7070
}
7171

DependencyInjection/Configuration.php

+24-11
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@ class Configuration implements ConfigurationInterface
1212
*/
1313
public function getConfigTreeBuilder()
1414
{
15-
$treeBuilder = new TreeBuilder();
16-
$rootNode = $treeBuilder->root('dcs_rating');
15+
$treeBuilder = new TreeBuilder('dcs_rating');
16+
if (\method_exists($treeBuilder, 'getRootNode')) {
17+
$rootNode = $treeBuilder->getRootNode();
18+
} else {
19+
// BC layer for symfony/config 4.1 and older
20+
$rootNode = $treeBuilder->root('dcs_rating');
21+
}
1722

1823
$rootNode
1924
->children()
2025
->scalarNode('db_driver')->isRequired()->end()
2126
->scalarNode('base_security_role')->defaultValue('IS_AUTHENTICATED_FULLY')->end()
2227
->scalarNode('base_path_to_redirect')->defaultValue('/')->end()
2328
->booleanNode('unique_vote')->defaultTrue()->end()
24-
->integerNode('max_value')->cannotBeEmpty()->defaultValue(5)->end()
29+
->integerNode('max_value')->defaultValue(5)->end()
2530
->end()
2631
->append($this->buildModelConfiguration())
2732
->append($this->buildServiceConfiguration())
@@ -32,19 +37,22 @@ public function getConfigTreeBuilder()
3237

3338
private function buildModelConfiguration()
3439
{
35-
$builder = new TreeBuilder();
36-
$node = $builder->root('model');
40+
$builder = new TreeBuilder('model');
41+
if (\method_exists($builder, 'getRootNode')) {
42+
$node = $builder->getRootNode();
43+
} else {
44+
// BC layer for symfony/config 4.1 and older
45+
$node = $builder->root('model');
46+
}
3747

3848
$node
3949
->isRequired()
4050
->children()
4151
->scalarNode('rating')
4252
->isRequired()
43-
->cannotBeEmpty()
4453
->end()
4554
->scalarNode('vote')
4655
->isRequired()
47-
->cannotBeEmpty()
4856
->end()
4957
->end()
5058
;
@@ -54,16 +62,21 @@ private function buildModelConfiguration()
5462

5563
private function buildServiceConfiguration()
5664
{
57-
$builder = new TreeBuilder();
58-
$node = $builder->root('service');
65+
$builder = new TreeBuilder('service');
66+
if (\method_exists($builder, 'getRootNode')) {
67+
$node = $builder->getRootNode();
68+
} else {
69+
// BC layer for symfony/config 4.1 and older
70+
$node = $builder->root('service');
71+
}
5972

6073
$node
6174
->addDefaultsIfNotSet()
6275
->children()
6376
->arrayNode('manager')->addDefaultsIfNotSet()
6477
->children()
65-
->scalarNode('rating')->cannotBeEmpty()->defaultValue('dcs_rating.manager.rating.default')->end()
66-
->scalarNode('vote')->cannotBeEmpty()->defaultValue('dcs_rating.manager.vote.default')->end()
78+
->scalarNode('rating')->defaultValue('dcs_rating.manager.rating.default')->end()
79+
->scalarNode('vote')->defaultValue('dcs_rating.manager.vote.default')->end()
6780
->end()
6881
->end()
6982
->end()

Resources/config/event.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<services>
1313
<service id="dcs_rating.listener.rating_update_info" class="%dcs_rating.listener.rating_update_info.class%">
1414
<call method="setRequest">
15-
<argument type="service" id="request" on-invalid="null" strict="false" />
15+
<argument type="service" id="request" on-invalid="null" />
1616
</call>
1717
<tag name="kernel.event_subscriber" />
1818
</service>

Resources/config/orm.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
</parameters>
1414

1515
<services>
16-
<service id="dcs_rating.manager.rating.default" class="%dcs_rating.manager.rating.default.class%">
16+
<service id="dcs_rating.manager.rating.default" class="%dcs_rating.manager.rating.default.class%" public="true">
1717
<argument type="service" id="event_dispatcher" />
1818
<argument type="service" id="doctrine.orm.entity_manager" />
1919
<argument>%dcs_rating.model.rating.class%</argument>
2020
</service>
21-
<service id="dcs_rating.manager.vote.default" class="%dcs_rating.manager.vote.default.class%">
21+
<service id="dcs_rating.manager.vote.default" class="%dcs_rating.manager.vote.default.class%" public="true">
2222
<argument type="service" id="event_dispatcher" />
2323
<argument type="service" id="doctrine.orm.entity_manager" />
2424
<argument>%dcs_rating.model.vote.class%</argument>

Resources/config/routing.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
66

7-
<route id="dcs_rating_add_vote" pattern="/vote/add/{id}/{value}">
8-
<default key="_controller">DCSRatingBundle:Rating:addVote</default>
7+
<route id="dcs_rating_add_vote" path="/vote/add/{id}/{value}">
8+
<default key="_controller">DCS\RatingBundle\Controller\RatingController::addVoteAction</default>
99
</route>
1010

1111
</routes>

composer.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "damianociarla/rating-bundle",
3-
"description": "This Bundle provides functionality for a rating system for Symfony2 applications",
3+
"description": "This Bundle provides functionality for a rating system for Symfony applications",
44
"type": "library",
55
"keywords": [
66
"symfony2","rating","star","twig","fos","fosuserbundle"
@@ -15,8 +15,14 @@
1515
}
1616
],
1717
"require": {
18-
"php": ">=5.3.2",
19-
"symfony/symfony": "~2.3"
18+
"php": "^7.1",
19+
"symfony/framework-bundle": "^2.8 || ^3.0 || ^4.0",
20+
"symfony/security-bundle": "^2.8 || ^3.0 || ^4.0",
21+
"symfony/twig-bundle": "^2.8 || ^3.0 || ^4.0",
22+
"twig/twig": "^1.28 || ^2.0 || ^3.0",
23+
"symfony/templating": "^2.8 || ^3.0 || ^4.0",
24+
"doctrine/orm": "^2.6",
25+
"doctrine/doctrine-bundle": "^1.3"
2026
},
2127
"autoload": {
2228
"psr-4": { "DCS\\RatingBundle\\": "" }

0 commit comments

Comments
 (0)