mayeco/easy-annotation-bundle

Easy annotation for Symfony2

dev-master / 1.0.x-dev 2014-11-03 06:03 UTC

This package is not auto-updated.

Last update: 2024-12-21 16:10:28 UTC


README

Prerequisites

SensioFrameworkExtraBundle

Example

A sample anotation that validate only ajax request.

<?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

...
use Acme\AcmeBundle\Configuration\OnlyAjax;
...

...
    /**
     *
     * OnlyAjax()
     */
    public function myAjaxFoo(Request $request)
    {