<commit_before><?php namespace Efficiently\AuthorityController;

use App;
use Event;
use Input;

// TODO: Move this class in its own Laravel package
class Parameters
{
    protected $params = [];

    /**
     * Fill the $params property of the given Controller
     *
     * @param  \Illuminate\Routing\Controller $controller
     */
    public function fillController($controller)
    {
        $router = App::make('router');
        $controllerClass = get_classname($controller);
        $paramsFilterPrefix = "router.filter: ";
        $paramsFilterName = "controller.parameters.".$controllerClass;

        if (! Event::hasListeners($paramsFilterPrefix.$paramsFilterName)) {
            $router->filter($paramsFilterName, function () use ($controller, $router) {
                $currentRoute = $router->current();
                $resourceParams = [];
                list($resourceParams['controller'], $resourceParams['action']) = explode('@', $router->currentRouteAction());
                $resourceParams['controller'] = $this->normalizeControllerName($resourceParams['controller']);

                $resourceId = str_singular($resourceParams['controller']);
                if (Input::has($resourceId)) {
                    $params = Input::all();
                } else {
                    $specialInputKeys = $this->specialInputKeys();
                    $params = [$resourceId => Input::except($specialInputKeys)] + Input::only($specialInputKeys);
                }
                $routeParams = $currentRoute->parametersWithoutNulls();

                // In Laravel, unlike Rails, by default 'id' parameter of a 'Product' resource is 'products'
                // And 'shop_id' parameter of a 'Shop' parent resource is 'shops'
                // So we need to reaffect correct parameter name before any controller's actions or filters.
                $routeParamsParsed = [];
                $keysToRemove = [];
                $lastRouteParamKey = last(array_keys($routeParams));
                if ($lastRouteParamKey === 'id' || $resourceId === str_singular($lastRouteParamKey)) {
                    $id = last($routeParams);
                    if (is_string($id) || is_numeric($id)) {
                        $routeParamsParsed['id'] = array_pop($routeParams);
                    }
                }

                foreach ($routeParams as $parentIdKey => $parentIdValue) {
                    if (is_string($parentIdValue) || is_numeric($parentIdValue)) {
                        if (! ends_with($parentIdKey, '_id')) {<commit_msg>Support Route Model Binding in the Parameters class.<commit_after><?php namespace Efficiently\AuthorityController;

use App;
use Event;
use Input;

// TODO: Move this class in its own Laravel package
class Parameters
{
    protected $params = [];

    /**
     * Fill the $params property of the given Controller
     *
     * @param  \Illuminate\Routing\Controller $controller
     */
    public function fillController($controller)
    {
        $router = App::make('router');
        $controllerClass = get_classname($controller);
        $paramsFilterPrefix = "router.filter: ";
        $paramsFilterName = "controller.parameters.".$controllerClass;

        if (! Event::hasListeners($paramsFilterPrefix.$paramsFilterName)) {
            $router->filter($paramsFilterName, function () use ($controller, $router) {
                $currentRoute = $router->current();
                $resourceParams = [];
                list($resourceParams['controller'], $resourceParams['action']) = explode('@', $router->currentRouteAction());
                $resourceParams['controller'] = $this->normalizeControllerName($resourceParams['controller']);

                $resourceId = str_singular($resourceParams['controller']);
                if (Input::has($resourceId)) {
                    $params = Input::all();
                } else {
                    $specialInputKeys = $this->specialInputKeys();
                    $params = [$resourceId => Input::except($specialInputKeys)] + Input::only($specialInputKeys);
                }
                $routeParams = $currentRoute->parametersWithoutNulls();

                // In Laravel, unlike Rails, by default 'id' parameter of a 'Product' resource is 'products'
                // And 'shop_id' parameter of a 'Shop' parent resource is 'shops'
                // So we need to reaffect correct parameter name before any controller's actions or filters.
                $routeParamsParsed = [];
                $keysToRemove = [];
                $lastRouteParamKey = last(array_keys($routeParams));
                if ($lastRouteParamKey === 'id' || $resourceId === str_singular($lastRouteParamKey)) {
                    $id = last($routeParams);
                    if (is_a($id, 'Illuminate\Database\Eloquent\Model')) {
                        $id = $id->getKey();
                    }
                    if (is_string($id) || is_numeric($id)) {
                        array_pop($routeParams);
                        $routeParamsParsed['id'] = $id;
                    }
                }

                foreach ($routeParams as $parentIdKey => $parentIdValue) {
                    if (is_a($parentIdValue, 'Illuminate\Database\Eloquent\Model')) {
                        $parentIdValue = $parentIdValue->getKey();
                    }
                    if (is_string($parentIdValue) || is_numeric($parentIdValue)) {
                        if (! ends_with($parentIdKey, '_id')) {
{'fraction_non_alphanumeric': 0.12710788757932912, 'fraction_numerical': 0.0, 'mean_word_length': 2.1023622047244093, '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': '2974468', 'n_tokens_mistral': 1371, 'n_tokens_neox': 1306, 'n_words': 298}