<commit_before><?php

namespace App\Providers;

use App\Http\ViewComposers\Header;
use App\Http\ViewComposers\Piwik;
use Faker\Factory;
use Faker\Generator;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        /* @var \Illuminate\View\View v */
        $v = view();

        $v->composer('header', Header::class);
        $v->composer('piwik', Piwik::class);

        // add a @markdown(...) directive which formats value to markdown
        \Blade::directive('markdown', function ($expr) {
            return "<?php echo \\Parsedown::instance()->parse({$expr}) ?>";
        });

        \Blade::directive('press', function ($expr) {
            return<<<LPMARKUP
<?php
    \$expr = collect(explode("\n", $expr))->map(function (\$line) { return trim(\$line); })->implode("\n");
    \$letterpress = app(EFrane\Letterpress\Letterpress::class);
    \$markuped = \$letterpress->markdown(\$expr);
    \$typofixed = \$letterpress->typofix(\$markuped);

    echo \$typofixed;
?>
LPMARKUP;
        });

        /*
         * Blade Directive @dumpasset:
         *
         * Dump an asset's content directly into the page
         */
        \Blade::directive('dumpasset', function ($expr) {
            $filename = str_replace(['"', "'"], '', $expr);
            $filename = public_path($filename);

            $content = '';

            if (file_exists($filename)) {
                $content = file_get_contents($filename);
            }

            $mime = mime_content_type($filename);
            if (starts_with($mime, 'image/')) {
                $type = pathinfo($filename, PATHINFO_EXTENSION);
                $content = base64_encode($content);

                $content = sprintf('data:image/%s;base64,%s', $type, $content);
            }

            return $content;
        });
    }

    /**
     * Register any application services.
     *
     * This service provider is a great spot to register your various container
     * bindings with the application. As you can see, we are registering our
     * "Registrar" implementation here. You can add your own bindings too!
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton(Generator::class, function () {
            return Factory::create('de_DE');<commit_msg>Move mime type detection inside file existence check<commit_after><?php

namespace App\Providers;

use App\Http\ViewComposers\Header;
use App\Http\ViewComposers\Piwik;
use Faker\Factory;
use Faker\Generator;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        /* @var \Illuminate\View\View v */
        $v = view();

        $v->composer('header', Header::class);
        $v->composer('piwik', Piwik::class);

        // add a @markdown(...) directive which formats value to markdown
        \Blade::directive('markdown', function ($expr) {
            return "<?php echo \\Parsedown::instance()->parse({$expr}) ?>";
        });

        \Blade::directive('press', function ($expr) {
            return<<<LPMARKUP
<?php
    \$expr = collect(explode("\n", $expr))->map(function (\$line) { return trim(\$line); })->implode("\n");
    \$letterpress = app(EFrane\Letterpress\Letterpress::class);
    \$markuped = \$letterpress->markdown(\$expr);
    \$typofixed = \$letterpress->typofix(\$markuped);

    echo \$typofixed;
?>
LPMARKUP;
        });

        /*
         * Blade Directive @dumpasset:
         *
         * Dump an asset's content directly into the page
         */
        \Blade::directive('dumpasset', function ($expr) {
            $filename = str_replace(['"', "'"], '', $expr);
            $filename = public_path($filename);

            $content = '';

            if (file_exists($filename)) {
                $content = file_get_contents($filename);

                $mime = mime_content_type($filename);
                if (starts_with($mime, 'image/')) {
                    $type = pathinfo($filename, PATHINFO_EXTENSION);
                    $content = base64_encode($content);

                    $content = sprintf('data:image/%s;base64,%s', $type, $content);
                }
            }

            return $content;
        });
    }

    /**
     * Register any application services.
     *
     * This service provider is a great spot to register your various container
     * bindings with the application. As you can see, we are registering our
     * "Registrar" implementation here. You can add your own bindings too!
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton(Generator::class, function () {
            return Factory::create('de_DE');
{'fraction_non_alphanumeric': 0.14814814814814814, 'fraction_numerical': 0.0016191054442420564, 'mean_word_length': 2.238532110091743, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, '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': '111521', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1380, 'n_words': 324}