<commit_before><?php

namespace SwaggerUI\Silex\Provider;

use Twig_Autoloader,
    Twig_Loader_Filesystem,
    Twig_Environment;


use Silex\Application;
use Silex\ServiceProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
 * The SwaggerUIServiceProvider adds views for swagger UI to a silex app, making
 * it possible to view swagger docs.
 */
class SwaggerUIServiceProvider implements ServiceProviderInterface
{
    /**
     * Add routes to the swagger UI documentation browser
     *
     * @param Application $app
     */
    public function boot(Application $app)
    {
        if ($app["logger"]) {
            $logger = Logger::getInstance();
            $originalLog = $logger->log;
            $logger->log = function ($entry, $type) use ($app, $originalLog) {
                $app["logger"]->notice($entry);
                $originalLog($entry, $type);
            };
        }

        $app->get($app['swaggerui.path'], function() use ($app) {
            echo str_replace(['{{swaggerui-root}}', '{{swagger-docs}}'], [$app['swaggerui.path'], $app['swaggerui.apiDovPath']], file_get_contents(__DIR__ . '/../../../../public/index.html'));die;
        });

        $app->get($app['swaggerui.path'] . '/{resource}', function($resource) use ($app) {
            $file = __DIR__ . '/../../../../public/' . $resource;
            if (is_file($file)) {
                return file_get_contents($file);
            }

            return '';
        });

        $app->get($app['swaggerui.path'] . '/lib/{resource}', function($resource) use ($app) {
            return $this->getFile(
                __DIR__ . '/../../../../public/lib/' . $resource,
                'text/javascript'
            );
        });

        $app->get($app['swaggerui.path'] . '/css/{resource}', function($resource) use ($app) {
            return $this->getFile(
                __DIR__ . '/../../../../public/css/' . $resource,
                'text/css'
            );
        });

        $app->get($app['swaggerui.path'] . '/images/{resource}', function($resource) use ($app) {
            return $this->getFile(
                __DIR__ . '/../../../../public/images/' . $resource,
                'image/png'
            );
        });
    }

    /**
     * Registers the swagger UI service
     *
     * @param Application $app
     */
    public function register(Application $app) {}

    /**
     * Get a public file
     *
     * @param string Path to file
     * @param string Content-type
     * @return Response
     */
    public function getFile($path, $contentType) {
        if (is_file($path)) {
            $response = new Response(file_get_contents($path));
            $response->headers->set('Content-Type', $contentType);
            $response->setCharset('UTF-8');
            return $response;
        }

        return new Response('', 404);
    }
}
<commit_msg>Removed use statements for Twig (no longer necessary)<commit_after><?php

namespace SwaggerUI\Silex\Provider;

use Silex\Application;
use Silex\ServiceProviderInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
 * The SwaggerUIServiceProvider adds views for swagger UI to a silex app, making
 * it possible to view swagger docs.
 */
class SwaggerUIServiceProvider implements ServiceProviderInterface
{
    /**
     * Add routes to the swagger UI documentation browser
     *
     * @param Application $app
     */
    public function boot(Application $app)
    {
        if ($app["logger"]) {
            $logger = Logger::getInstance();
            $originalLog = $logger->log;
            $logger->log = function ($entry, $type) use ($app, $originalLog) {
                $app["logger"]->notice($entry);
                $originalLog($entry, $type);
            };
        }

        $app->get($app['swaggerui.path'], function() use ($app) {
            echo str_replace(['{{swaggerui-root}}', '{{swagger-docs}}'], [$app['swaggerui.path'], $app['swaggerui.apiDovPath']], file_get_contents(__DIR__ . '/../../../../public/index.html'));die;
        });

        $app->get($app['swaggerui.path'] . '/{resource}', function($resource) use ($app) {
            $file = __DIR__ . '/../../../../public/' . $resource;
            if (is_file($file)) {
                return file_get_contents($file);
            }

            return '';
        });

        $app->get($app['swaggerui.path'] . '/lib/{resource}', function($resource) use ($app) {
            return $this->getFile(
                __DIR__ . '/../../../../public/lib/' . $resource,
                'text/javascript'
            );
        });

        $app->get($app['swaggerui.path'] . '/css/{resource}', function($resource) use ($app) {
            return $this->getFile(
                __DIR__ . '/../../../../public/css/' . $resource,
                'text/css'
            );
        });

        $app->get($app['swaggerui.path'] . '/images/{resource}', function($resource) use ($app) {
            return $this->getFile(
                __DIR__ . '/../../../../public/images/' . $resource,
                'image/png'
            );
        });
    }

    /**
     * Registers the swagger UI service
     *
     * @param Application $app
     */
    public function register(Application $app) {}

    /**
     * Get a public file
     *
     * @param string Path to file
     * @param string Content-type
     * @return Response
     */
    public function getFile($path, $contentType) {
        if (is_file($path)) {
            $response = new Response(file_get_contents($path));
            $response->headers->set('Content-Type', $contentType);
            $response->setCharset('UTF-8');
            return $response;
        }

        return new Response('', 404);
    }
}

{'fraction_non_alphanumeric': 0.17035286172547695, 'fraction_numerical': 0.0013506668917778154, 'mean_word_length': 1.9516691579471848, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '7587005', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1650, 'n_words': 345}