Last active
December 17, 2015 00:59
-
-
Save EuphoryX1/5525265 to your computer and use it in GitHub Desktop.
Symfony2 event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
euphory_storebundle.listener.comment: | |
class: Euphory\StoreBundle\Event\CommentListener | |
arguments: [@logger] | |
tags: | |
- { name: kernel.event_listener, event: euphory_storebundle.post.comment, method: onCommentEvent } | |
- { name: kernel.event_listener, event: euphory_storebundle.post.remove, method: onRemoveEvent } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Euphory\StoreBundle\Event; | |
class CommentListener | |
{ | |
protected $logger; | |
public function __construct($logger) | |
{ | |
$this->logger = $logger; | |
} | |
public function onCommentEvent(CommentEvent $event) | |
{ | |
$this->logger->info("onCommentEvent"); | |
} | |
public function onRemoveEvent(CommentEvent $event) | |
{ | |
$this->logger->info("onRemoveEent"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Euphory\StoreBundle\Event; | |
use Symfony\Component\EventDispatcher\Event; | |
class CommentEvent extends Event | |
{ | |
protected $post; | |
protected $comment; | |
public function __construct($post, $comment) | |
{ | |
$this->post = $post; | |
$this->comment = $comment; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DefeultController extends Symfony\Bundle\FrameworkBundle\Controller\Controller | |
{ | |
public function dispatchAction() | |
{ | |
$dispatcher = $this->get('event_dispatcher'); | |
$dispatcher->dispatch('euphory_storebundle.post.comment', new \Euphory\StoreBundle\Event\CommentEvent($post, $comment)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment