Created
November 23, 2012 15:02
-
-
Save tristanbes/4136029 to your computer and use it in GitHub Desktop.
Controller Example of Monitor your Symfony2 application via Stats.d and Graphite (2/2)
This file contains 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 SeekTeam\PremiumBundle\Controller; | |
use SeekTeam\HomeBundle\Controller\Controller; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | |
use JMS\SecurityExtraBundle\Annotation\Secure; | |
use Symfony\Component\EventDispatcher\EventDispatcher; | |
use Symfony\Component\EventDispatcher\GenericEvent; | |
use SeekTeam\PremiumBundle\Entity\Premium\Order; | |
use SeekTeam\PremiumBundle\Event\Events; | |
/** | |
* Default Controller of the PremiumBundle | |
*/ | |
class DefaultController extends Controller | |
{ | |
/** | |
* @Route("/{_locale}/payment/{id}/cancel", name="payment_cancel", requirements={"_locale" = "en|fr"}) | |
* @Template() | |
* @Secure(roles="ROLE_USER") | |
*/ | |
public function cancelAction(Order $order) | |
{ | |
$order->setStatus(Order::STATUS_CANCEL); | |
$this->getEntityManager()->persist($order); | |
$this->getEntityManager()->flush($order); | |
$this->get('event_dispatcher')->dispatch(Events::PREMIUM_CANCEL, new GenericEvent($order)); | |
$this->setFlash('error', 'premium.order.cancel'); | |
return $this->redirect($this->generateUrl('user_profile') . '#premium'); | |
} | |
/** | |
* @Route("/{_locale}/payment/{id}/complete", name="payment_complete", requirements={"_locale" = "en|fr"}) | |
* @Template() | |
* @Secure(roles="ROLE_USER") | |
*/ | |
public function completeAction(Order $order) | |
{ | |
// Lot of business logic I removed for the tutorial purpose | |
$order->setStatus(Order::STATUS_VALID); | |
$this->getEntityManager()->persist($order); | |
$this->getEntityManager()->flush($order); | |
$this->getRepository('SeekTeamPremiumBundle:Premium')->updatePremium($order); | |
$this->get('event_dispatcher')->dispatch(Events::PREMIUM_SUCCESS, new GenericEvent($order)); | |
$this->setFlash('success', 'premium.order.success'); | |
return $this->redirect($this->generateUrl('homepage')); | |
} | |
/** | |
* Returns the EntityManger | |
* | |
* @return EntityManager | |
*/ | |
protected function getEntityManager() | |
{ | |
return $this->getDoctrine()->getEntityManager(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment