<commit_before><?php

namespace SlimAdditions;

class RouteGenerator
{
    private $controller_cache = array();
    private $app;

    public function __construct($app)
    {
        $this->app = $app;
    }

    private function permissions($controller_name, $method)
    {
        if (!isset($this->permissions_cache[$controller_name])) {
            $class_name = "\\App\\Permissions\\" . $controller_name;
            $this->permissions_cache[$controller_name] = new $class_name($this->app);
        }

        return array($this->permissions_cache[$controller_name], "check");
    }

    private function action($controller_name, $method)
    {
        if (!isset($this->controller_cache[$controller_name])) {
            $class_name = '\\App\\Controllers\\' . $controller_name;
            $this->controller_cache[$controller_name] = new $class_name($this->app);
        }

        return array($this->controller_cache[$controller_name], $method);
    }

    private function get($url, $controller, $action)
    {
        return $this->app->get($url, $this->permissions($controller, $action), $this->action($controller, $action));
    }

    private function patch($url, $controller, $action)
    {
        return $this->app->patch($url, $this->permissions($controller, $action), $this->action($controller, $action));
    }

    private function post($url, $controller, $action)
    {
        return $this->app->post($url, $this->permissions($controller, $action), $this->action($controller, $action));
    }

    private function put($url, $controller, $action)
    {
        return $this->app->put($url, $this->permissions($controller, $action), $this->action($controller, $action));
    }

    private function delete($url, $controller, $action)
    {
        return $this->app->delete($url, $this->permissions($controller, $action), $this->action($controller, $action));
    }

    private function options($url, $controller, $action)
    {
        return $this->app->options($url, $this->action($controller, $action));
    }

    private function defaultConditions($conditions)
    {
        \Slim\Route::setDefaultConditions($conditions);
    }

    public function loadRoutes()
    {
        include 'config/routes.php';
    }
}<commit_msg>Add route generator for Slim v3<commit_after><?php

namespace SlimAdditions;

class RouteGenerator
{
    private $app;

    public function __construct($app)
    {
        $this->app = $app;
    }

    private function permissions($controller_name, $method)
    {
        return '\\App\\Permissions\\' . $controller_name . ':check';
    }

    private function request($controller_name, $method)
    {
        return '\\App\\Controllers\\' . $controller_name . ":" . $method;
    }

    private function route($http_method, $url, $controller, $action)
    {
        return $this->app->$http_method($url, $this->request($controller, $action))->add($this->permissions($controller, $action));
    }

    public function loadRoutes($path = "config/routes.php")
    {
        include $path;
    }
}
{'fraction_non_alphanumeric': 0.1618516086671044, 'fraction_numerical': 0.00032829940906106366, 'mean_word_length': 3.162568306010929, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 41, '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': '1860180', 'n_tokens_mistral': 891, 'n_tokens_neox': 877, 'n_words': 168}