<commit_before><?php

namespace AppBundle\Controller\Frontend;

use AppBundle\Entity\File;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Form\Type\CreateFileType;
use AppBundle\Form\Type\CreateFileAnonType;
use AppBundle\Event\FileEvent;
use AppBundle\FileEvents;

class FileController extends Controller
{
    /**
     * @Route("file/s/{shareCode}/{slug}", name="file_share")
     */
    public function ShareFileAction(File $file)
    {
        $user = $this->getUser();
        $session = $this->get('session');
        $em = $this->getDoctrine()->getManager();

        if (false === $this->get('security.authorization_checker')->isGranted('access', $file)) {
            if ($user) {
                $file->addUsersWithAccess($user);
                $em->persist($file);
                $em->flush();
            } else {
                $session->set($file->getSlug(), true);
            }
        }

        return $this->render(
            'Default/shareFile.html.twig',
            array(
                'file' => $file,
            )
        );
    }

    /**
     *@Route("/file/create" , name="file_create")
     */
    public function createFileAction(Request $request)
    {
        $file = new File();
        $user = $this->getUser();
        if (!$user) {
            $form = $this->createForm(new CreateFileAnonType(), $file);
        } else {
            $form = $this->createForm(new CreateFileType(), $file);
        }

        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            if ($user) {
                $file->setUser($user);

                // Dispatch Event
                $fileEvent = new FileEvent($file,$this->get('logger'));
                $fileEvent = $this->container->get('event_dispatcher')->dispatch(FileEvents::SUBMITTED, $fileEvent);

//                if ($fileEvent->isPropagationStopped()) {
//                    $this->get('logger')->addError('The file has not been scanned');
//                } else {
//                    $this->get('logger')->addInfo('The file has been scanned');
//                }
            }

            $em->persist($file);

            $uploadableManager = $this->get('stof_doctrine_extensions.uploadable.manager');
            $uploadableManager->markEntityToUpload($file, $file->getFilename());

            $em->flush();
<commit_msg>Lanzamos el evento 'submitted 'en el controlador<commit_after><?php

namespace AppBundle\Controller\Frontend;

use AppBundle\Entity\File;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Form\Type\CreateFileType;
use AppBundle\Form\Type\CreateFileAnonType;
use AppBundle\Event\FileEvent;
use AppBundle\FileEvents;

class FileController extends Controller
{
    /**
     * @Route("file/s/{shareCode}/{slug}", name="file_share")
     */
    public function ShareFileAction(File $file)
    {
        $user = $this->getUser();
        $session = $this->get('session');
        $em = $this->getDoctrine()->getManager();

        if (false === $this->get('security.authorization_checker')->isGranted('access', $file)) {
            if ($user) {
                $file->addUsersWithAccess($user);
                $em->persist($file);
                $em->flush();
            } else {
                $session->set($file->getSlug(), true);
            }
        }

        return $this->render(
            'Default/shareFile.html.twig',
            array(
                'file' => $file,
            )
        );
    }

    /**
     *@Route("/file/create" , name="file_create")
     */
    public function createFileAction(Request $request)
    {
        $file = new File();
        $user = $this->getUser();
        if (!$user) {
            $form = $this->createForm(new CreateFileAnonType(), $file);
        } else {
            $form = $this->createForm(new CreateFileType(), $file);
        }

        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            if ($user) {
                $file->setUser($user);
            }

            $em->persist($file);

            $uploadableManager = $this->get('stof_doctrine_extensions.uploadable.manager');
            $uploadableManager->markEntityToUpload($file, $file->getFilename());

            $em->flush();

            // Dispatch Event
            $fileEvent = new FileEvent($file);

            $this->container->get('event_dispatcher')->dispatch(FileEvents::SUBMITTED, $fileEvent);

{'fraction_non_alphanumeric': 0.1530472271213012, 'fraction_numerical': 0.0, 'mean_word_length': 2.2907801418439715, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, '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': '3866385', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1411, 'n_words': 225}