<commit_before><?php

namespace Oro\Bundle\FormBundle\Controller;

use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

use Oro\Bundle\FormBundle\Autocomplete\Security;
use Oro\Bundle\FormBundle\Autocomplete\SearchRegistry;
use Oro\Bundle\FormBundle\Autocomplete\SearchHandlerInterface;

/**
 * @Route("/autocomplete")
 * @Acl(
 *      id="oro_form_autocomplete",
 *      name="Autocomplete functionality",
 *      description="Actions from autocomplete controller",
 *      parent="root"
 * )
 */
class AutocompleteController extends Controller
{
    /**
     * @Route("/search", name="oro_form_autocomplete_search")
     * @Acl(
     *      id="oro_form_autocomplete_search",
     *      name="Autocomplete search request",
     *      description="Autocomplete search request",
     *      parent="oro_form_autocomplete"
     * )
     */
    public function searchAction(Request $request)
    {
        $name = $request->get('name');
        $query = $request->get('query');
        $page = intval($request->get('page', 1));
        $perPage = intval($request->get('per_page', 50));

        if (!$name) {
            throw new HttpException(400, 'Parameter "name" is required');
        }

        if ($page <= 0) {
            throw new HttpException(400, 'Parameter "page" must be greater than 0');
        }

        if ($perPage <= 0) {
            throw new HttpException(400, 'Parameter "per_page" must be greater than 0');
        }

        if (!$this->get('oro_form.autocomplete.security')->isAutocompleteGranted($name)) {
            throw new AccessDeniedHttpException('Access denied.');
        }

        /** @var SearchHandlerInterface $searchHandler */
        $searchHandler = $this->get('oro_form.autocomplete.search_registry')->getSearchHandler($name);

        return new JsonResponse($searchHandler->search($query, $page, $perPage));
    }
}
<commit_msg>CRM-99: Create autocomplete/combobox form type - add use of Acl annotation<commit_after><?php

namespace Oro\Bundle\FormBundle\Controller;

use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

use Oro\Bundle\UserBundle\Annotation\Acl;

use Oro\Bundle\FormBundle\Autocomplete\Security;
use Oro\Bundle\FormBundle\Autocomplete\SearchRegistry;
use Oro\Bundle\FormBundle\Autocomplete\SearchHandlerInterface;

/**
 * @Route("/autocomplete")
 * @Acl(
 *      id="oro_form_autocomplete",
 *      name="Autocomplete functionality",
 *      description="Actions from autocomplete controller",
 *      parent="root"
 * )
 */
class AutocompleteController extends Controller
{
    /**
     * @Route("/search", name="oro_form_autocomplete_search")
     * @Acl(
     *      id="oro_form_autocomplete_search",
     *      name="Autocomplete search request",
     *      description="Autocomplete search request",
     *      parent="oro_form_autocomplete"
     * )
     */
    public function searchAction(Request $request)
    {
        $name = $request->get('name');
        $query = $request->get('query');
        $page = intval($request->get('page', 1));
        $perPage = intval($request->get('per_page', 50));

        if (!$name) {
            throw new HttpException(400, 'Parameter "name" is required');
        }

        if ($page <= 0) {
            throw new HttpException(400, 'Parameter "page" must be greater than 0');
        }

        if ($perPage <= 0) {
            throw new HttpException(400, 'Parameter "per_page" must be greater than 0');
        }

        if (!$this->get('oro_form.autocomplete.security')->isAutocompleteGranted($name)) {
            throw new AccessDeniedHttpException('Access denied.');
        }

        /** @var SearchHandlerInterface $searchHandler */
        $searchHandler = $this->get('oro_form.autocomplete.search_registry')->getSearchHandler($name);

        return new JsonResponse($searchHandler->search($query, $page, $perPage));
    }
}

{'fraction_non_alphanumeric': 0.13023358307624505, 'fraction_numerical': 0.00749228735125606, 'mean_word_length': 3.4543670264965654, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4554603', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1253, 'n_words': 237}