<commit_before><?php

namespace Liip\ImagineBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Liip\ImagineBundle\Imagine\CachePathResolver;
use Liip\ImagineBundle\Imagine\DataLoader\LoaderInterface;
use Liip\ImagineBundle\Imagine\Filter\FilterManager;

class ImagineController
{
    /**
     * @var Liip\ImagineBundle\Imagine\DataLoader\LoaderInterface
     */
    private $dataLoader;

    /**
     * @var Liip\ImagineBundle\Imagine\Filter\FilterManager
     */
    private $filterManager;

    /**
     * @var Liip\ImagineBundle\Imagine\CachePathResolver
     */
    private $cachePathResolver;

    /**
     * Constructor
     *
     * @param Liip\ImagineBundle\Imagine\DataLoader\LoaderInterface $dataLoader
     * @param Liip\ImagineBundle\Imagine\Filter\FilterManager       $filterManager
     * @param Liip\ImagineBundle\Imagine\CachePathResolver          $cachePathResolver
     */
    public function __construct(LoaderInterface $dataLoader, FilterManager $filterManager, CachePathResolver $cachePathResolver = null)
    {
        $this->dataLoader        = $dataLoader;
        $this->filterManager     = $filterManager;
        $this->cachePathResolver = $cachePathResolver;
    }

    /**
     * This action applies a given filter to a given image,
     * optionally saves the image and
     * outputs it to the browser at the same time
     *
     * @param Symfony\Component\HttpFoundation\Request $request
     * @param string $path
     * @param string $filter
     *
     * @return Response
     */
    public function filterAction(Request $request, $path, $filter)
    {
        list($actualPath, $image, $targetFormat) = $this->dataLoader->find($path);

        if ($this->cachePathResolver) {
            $targetPath = $this->cachePathResolver->resolve($request, $actualPath, $targetFormat, $filter);
            if ($targetPath instanceof Response) {
                return $targetPath;
            }
        }

        $image = $this->filterManager->get($filter, $image, $targetFormat);

        if ($this->cachePathResolver) {
            $this->cachePathResolver->store($targetPath, $image);
            $statusCode = 201;
        } else {
            $statusCode = 200;
        }

        $contentType = $request->getMimeType($targetFormat);

        return new Response($image, $statusCode, array('Content-Type' => $contentType));
    }
}
<commit_msg>be more graceful if a given target format has not been registered in the Request<commit_after><?php

namespace Liip\ImagineBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Liip\ImagineBundle\Imagine\CachePathResolver;
use Liip\ImagineBundle\Imagine\DataLoader\LoaderInterface;
use Liip\ImagineBundle\Imagine\Filter\FilterManager;

class ImagineController
{
    /**
     * @var Liip\ImagineBundle\Imagine\DataLoader\LoaderInterface
     */
    private $dataLoader;

    /**
     * @var Liip\ImagineBundle\Imagine\Filter\FilterManager
     */
    private $filterManager;

    /**
     * @var Liip\ImagineBundle\Imagine\CachePathResolver
     */
    private $cachePathResolver;

    /**
     * Constructor
     *
     * @param Liip\ImagineBundle\Imagine\DataLoader\LoaderInterface $dataLoader
     * @param Liip\ImagineBundle\Imagine\Filter\FilterManager       $filterManager
     * @param Liip\ImagineBundle\Imagine\CachePathResolver          $cachePathResolver
     */
    public function __construct(LoaderInterface $dataLoader, FilterManager $filterManager, CachePathResolver $cachePathResolver = null)
    {
        $this->dataLoader        = $dataLoader;
        $this->filterManager     = $filterManager;
        $this->cachePathResolver = $cachePathResolver;
    }

    /**
     * This action applies a given filter to a given image,
     * optionally saves the image and
     * outputs it to the browser at the same time
     *
     * @param Symfony\Component\HttpFoundation\Request $request
     * @param string $path
     * @param string $filter
     *
     * @return Response
     */
    public function filterAction(Request $request, $path, $filter)
    {
        list($actualPath, $image, $targetFormat) = $this->dataLoader->find($path);

        if ($this->cachePathResolver) {
            $targetPath = $this->cachePathResolver->resolve($request, $actualPath, $targetFormat, $filter);
            if ($targetPath instanceof Response) {
                return $targetPath;
            }
        }

        $image = $this->filterManager->get($filter, $image, $targetFormat);

        if ($this->cachePathResolver) {
            $this->cachePathResolver->store($targetPath, $image);
            $statusCode = 201;
        } else {
            $statusCode = 200;
        }

        $contentType = $request->getMimeType($targetFormat);
        if (empty($contentType)) {
            $contentType = 'image/'.$targetFormat;
        }

        return new Response($image, $statusCode, array('Content-Type' => $contentType));
    }
}

{'fraction_non_alphanumeric': 0.11071499306793424, 'fraction_numerical': 0.0023767082590612004, 'mean_word_length': 2.7912912912912913, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '1663247', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1345, 'n_words': 280}