symfony-bundle easy-annotation-bundle
Easy annotation for Symfony2
mayeco/easy-annotation-bundle
Easy annotation for Symfony2
- Monday, November 3, 2014
- by mayeco
- Repository
- 1 Watchers
- 2 Stars
- 7 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 1 Versions
- 0 % Grown
EasyAnnotationBundle
Prerequisites
SensioFrameworkExtraBundle, (*1)
Example
A sample anotation that validate only ajax request., (*2)
<?php
namespace Acme\AcmeBundle\Configuration;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationAnnotation;
use Mayeco\EasyAnnotationBundle\Configuration\ExecutableAnnotationControllerInterface;
/**
* @Annotation
*/
class OnlyAjax extends ConfigurationAnnotation implements ExecutableAnnotationControllerInterface
{
public function executeOnController(FilterControllerEvent $event)
{
if(!$event->getRequest()->isXmlHttpRequest()) {
throw new AccessDeniedHttpException("No valid");
}
}
public function getAliasName()
{
return 'onlyajax';
}
public function allowArray()
{
return false;
}
}
Use in your controller, (*3)
...
use Acme\AcmeBundle\Configuration\OnlyAjax;
...
...
/**
*
* OnlyAjax()
*/
public function myAjaxFoo(Request $request)
{