Skip to content

Commit

Permalink
Fix Request in scope non request
Browse files Browse the repository at this point in the history
  • Loading branch information
damianociarla committed Dec 10, 2014
1 parent 8b0cc82 commit 79410eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 12 additions & 5 deletions EventListener/RatingUpdateInfoEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@
class RatingUpdateInfoEventListener implements EventSubscriberInterface
{
/**
* @var \Symfony\Component\HttpFoundation\Request
* @var Request
*/
private $request;

public function __construct(Container $container)
/**
* Set request
*
* @param Request $request
*/
public function setRequest(Request $request = null)
{
$container->enterScope('request');
$container->set('request', new Request(), 'request');
$this->request = $container->get('request');
$this->request = $request;
}

public static function getSubscribedEvents()
Expand All @@ -31,6 +34,10 @@ public static function getSubscribedEvents()

public function updatePermalink(RatingEvent $event)
{
if (null === $this->request) {
return;
}

$rating = $event->getRating();

if (null === $rating->getPermalink()) {
Expand Down
4 changes: 3 additions & 1 deletion Resources/config/event.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
<tag name="kernel.event_listener" event="kernel.exception" method="onKernelException" />
</service>
<service id="dcs_rating.listener.rating_update_info" class="%dcs_rating.listener.rating_update_info.class%">
<argument type="service" id="service_container" />
<call method="setRequest">
<argument type="service" id="request" on-invalid="null" strict="false" />
</call>
<tag name="kernel.event_subscriber" />
</service>
<service id="dcs_rating.listener.rating_update_rate" class="%dcs_rating.listener.rating_update_rate.class%">
Expand Down

0 comments on commit 79410eb

Please sign in to comment.