<commit_before><?php namespace Orchestra\Facile\Template;

use InvalidArgumentException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response as IlluminateResponse;
use Illuminate\Support\Contracts\ArrayableInterface;
use Illuminate\View\View;
use Orchestra\Support\Collection;

class Base extends Driver
{
    /**
     * List of supported format.
     *
     * @var array
     */
    protected $formats = array('html', 'json', 'csv');

    /**
     * Default format.
     *
     * @var string
     */
    protected $defaultFormat = 'html';

    /**
     * Compose HTML.
     *
     * @param  mixed    $view
     * @param  array    $data
     * @param  integer  $status
     * @param  array    $config
     * @return \Illuminate\Http\Response
     */
    public function composeHtml($view = null, array $data = array(), $status = 200, array $config = array())
    {
        if (! isset($view)) {
            throw new InvalidArgumentException("Missing [\$view].");
        }

        if (! $view instanceof View) {
            $view = $this->view->make($view);
        }

        return new IlluminateResponse($view->with($data), $status);
    }

    /**
     * Compose JSON.
     *
     * @param  mixed    $view
     * @param  array    $data
     * @param  integer  $status
     * @param  array    $config
     * @return \Illuminate\Http\JsonResponse
     */
    public function composeJson($view, array $data = array(), $status = 200, array $config = array())
    {
        unset($view);

        $data = array_map(array($this, 'transformToArray'), $data);

        return new JsonResponse($data, $status);
    }

    /**
     * Compose CSV.
     *
     * @param  mixed    $view
     * @param  array    $data
     * @param  integer  $status
     * @param  array    $config
     * @return \Illuminate\Http\Response
     */
    public function composeCsv($view = null,
        array $data = array(), $status = 200, array $config = array())
    {
        $filename = array_get($config, 'filename', 'export');
        $uses     = array_get($config, 'uses', 'data');
        $content  = array_get($data, $uses, array());

        if (! $content instanceof CsvableInterface) {
            if ($content instanceof ArrayableInterface) {
                $content = $content->toArray();
            }

            $content = with(new Collection(array_map(array($this, 'transformToArray'), $content)));
        }

        return new IlluminateResponse($content->toCsv(), $status, array(
            'Content-Type'        => 'text/csv',
            'Content-Disposition' => 'attachment; filename="'.$filename.'.csv"',
            'Cache-Control'       => 'private',
            'pragma'              => 'cache',
        ));
    }
}<commit_msg>Small tweak.<commit_after><?php namespace Orchestra\Facile\Template;

use InvalidArgumentException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response as IlluminateResponse;
use Illuminate\Support\Contracts\ArrayableInterface;
use Illuminate\View\View;
use Orchestra\Support\Collection;

class Base extends Driver
{
    /**
     * List of supported format.
     *
     * @var array
     */
    protected $formats = array('html', 'json', 'csv');

    /**
     * Default format.
     *
     * @var string
     */
    protected $defaultFormat = 'html';

    /**
     * Compose HTML.
     *
     * @param  mixed    $view
     * @param  array    $data
     * @param  integer  $status
     * @param  array    $config
     * @return \Illuminate\Http\Response
     */
    public function composeHtml($view = null, array $data = array(), $status = 200, array $config = array())
    {
        if (! isset($view)) {
            throw new InvalidArgumentException("Missing [\$view].");
        }

        if (! $view instanceof View) {
            $view = $this->view->make($view);
        }

        return new IlluminateResponse($view->with($data), $status);
    }

    /**
     * Compose JSON.
     *
     * @param  mixed    $view
     * @param  array    $data
     * @param  integer  $status
     * @param  array    $config
     * @return \Illuminate\Http\JsonResponse
     */
    public function composeJson($view, array $data = array(), $status = 200, array $config = array())
    {
        unset($view);

        $data = array_map(array($this, 'transformToArray'), $data);

        return new JsonResponse($data, $status);
    }

    /**
     * Compose CSV.
     *
     * @param  mixed    $view
     * @param  array    $data
     * @param  integer  $status
     * @param  array    $config
     * @return \Illuminate\Http\Response
     */
    public function composeCsv($view = null, array $data = array(), $status = 200, array $config = array())
    {
        unset($view);

        $filename = array_get($config, 'filename', 'export');
        $uses     = array_get($config, 'uses', 'data');
        $content  = array_get($data, $uses, array());

        if (! $content instanceof CsvableInterface) {
            if ($content instanceof ArrayableInterface) {
                $content = $content->toArray();
            }

            $content = with(new Collection(array_map(array($this, 'transformToArray'), $content)));
        }

        return new IlluminateResponse($content->toCsv(), $status, array(
            'Content-Type'        => 'text/csv',
            'Content-Disposition' => 'attachment; filename="'.$filename.'.csv"',
            'Cache-Control'       => 'private',
            'pragma'              => 'cache',
        ));
    }
}
{'fraction_non_alphanumeric': 0.1430909090909091, 'fraction_numerical': 0.0032727272727272726, 'mean_word_length': 2.1131861912846635, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1527118', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1577, 'n_words': 378}