<commit_before><?php
/*
 * This file is part of RestAdminBundle.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Nours\RestAdminBundle\Domain;

use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;

/**
 * A ResourceHandler
 * 
 * @author <NAME> <<EMAIL>>
 */
class ResourceHandler
{
    private $resolver;

    public function __construct(ControllerResolverInterface $resolver)
    {
        $this->resolver = $resolver;
    }


    public function handleSuccess($data, Request $request, FormInterface $form, Resource $resource, Action $action)
    {
        // Init a request for resolver
        $request = new Request(array(), array(), array_replace($request->attributes->all(), array(
            'resource' => $resource,
            'action'   => $action,
            'form'     => $form,
            'data'     => $data
        )));

        foreach ($action->getHandlers() as $handler) {
            $request->attributes->set('_controller', $handler);

            $controller = $this->resolver->getController($request);

            if ($controller === false) {
                throw new \DomainException(sprintf(
                    "Handler %s for resource %s and action %s could not be resolved",
                    $handler, $resource->getFullName(), $action->getName()
                ));
            }

            $arguments  = $this->resolver->getArguments($request, $controller);

            $response = call_user_func_array($controller, $arguments);

//            var_dump($response);die;

            if (!empty($response)) {
                return $response;
            }
        }

        return $form;
    }
}<commit_msg>Fix handlers<commit_after><?php
/*
 * This file is part of RestAdminBundle.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Nours\RestAdminBundle\Domain;

use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;

/**
 * A ResourceHandler
 * 
 * @author <NAME> <<EMAIL>>
 */
class ResourceHandler
{
    private $resolver;

    public function __construct(ControllerResolverInterface $resolver)
    {
        $this->resolver = $resolver;
    }


    public function handleSuccess($data, Request $request, FormInterface $form, Resource $resource, Action $action)
    {
        // Init a request for resolver
        $request = $request->duplicate(array(), array(), array_replace($request->attributes->all(), array(
            'resource' => $resource,
            'action'   => $action,
            'form'     => $form,
            'data'     => $data
        )));

        foreach ($action->getHandlers() as $handler) {
            $request->attributes->set('_controller', $handler);

            $controller = $this->resolver->getController($request);

            if ($controller === false) {
                throw new \DomainException(sprintf(
                    "Handler %s for resource %s and action %s could not be resolved",
                    $handler, $resource->getFullName(), $action->getName()
                ));
            }

            $arguments  = $this->resolver->getArguments($request, $controller);

            $response = call_user_func_array($controller, $arguments);

//            var_dump($response);die;

            if (!empty($response)) {
                return $response;
            }
        }

        return $form;
    }
}
{'fraction_non_alphanumeric': 0.1276878152375896, 'fraction_numerical': 0.0, 'mean_word_length': 2.3523131672597866, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 48, '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': '5800192', 'n_tokens_mistral': 992, 'n_tokens_neox': 963, 'n_words': 248}