<commit_before><?php
namespace Czim\CmsModels\Http\Requests;

use Czim\CmsModels\Contracts\Data\ModelInformationInterface;
use Czim\CmsModels\Contracts\Repositories\ModelInformationRepositoryInterface;
use Czim\CmsModels\Contracts\Routing\RouteHelperInterface;
use Czim\CmsModels\Support\Data\ModelInformation;
use RuntimeException;

abstract class AbstractModelRequest extends Request
{

    /**
     * The key for the currently active model module.
     *
     * @var string
     */
    protected $moduleKey;

    /**
     * @var ModelInformationInterface|ModelInformation
     */
    protected $modelInformation;
    

    /**
     * @param \Illuminate\Contracts\Validation\Factory $factory
     * @return mixed
     */
    public function validator($factory)
    {
        $this->initializeForModelRoute();

        return $factory->make(
            $this->validationData(),
            $this->container->call([$this, 'processedRules']),
            $this->messages(),
            $this->attributes()
        );
    }

    /**
     * Returns post-processed validation rules.
     *
     * @return array
     */
    public function processedRules()
    {
        return $this->container->call([$this, 'rules']);
    }

    /**
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Initializes form request and checks context expecting a model route.
     *
     * @return $this
     */
    protected function initializeForModelRoute()
    {
        $routeHelper = $this->getRouteHelper();

        $this->moduleKey = $routeHelper->getModuleKeyForCurrentRoute();

        if ( ! $this->moduleKey) {
            throw new RuntimeException("Could not determine module key for route in request");
        }

        $this->modelInformation = $this->getModelInformationRepository()->getByKey($this->moduleKey);

        if ( ! $this->modelInformation) {
            throw new RuntimeException(
                "Could not load information for module key '{$this->moduleKey}' in request"
            );
        }

        return $this;
    }


    /**
     * @return ModelInformationInterface|ModelInformation
     */
    protected function getModelInformation()
    {
        return $this->modelInformation;
    }

    /**
     * @return RouteHelperInterface
     */
    protected function getRouteHelper()
    {
        return app(RouteHelperInterface::class);
    }

    /**
     * @return ModelInformationRepositoryInterface
     */
    protected function getModelInformationRepository()
    {
        return app(ModelInformationRepositoryInterface::class);
    }

}
<commit_msg>Fixed issue with form request model slug/key mixup<commit_after><?php
namespace Czim\CmsModels\Http\Requests;

use Czim\CmsModels\Contracts\Data\ModelInformationInterface;
use Czim\CmsModels\Contracts\Repositories\ModelInformationRepositoryInterface;
use Czim\CmsModels\Contracts\Routing\RouteHelperInterface;
use Czim\CmsModels\Support\Data\ModelInformation;
use RuntimeException;

abstract class AbstractModelRequest extends Request
{

    /**
     * The key/slug for the currently active model.
     *
     * @var string
     */
    protected $modelSlug;

    /**
     * @var ModelInformationInterface|ModelInformation
     */
    protected $modelInformation;
    

    /**
     * @param \Illuminate\Contracts\Validation\Factory $factory
     * @return mixed
     */
    public function validator($factory)
    {
        $this->initializeForModelRoute();

        return $factory->make(
            $this->validationData(),
            $this->container->call([$this, 'processedRules']),
            $this->messages(),
            $this->attributes()
        );
    }

    /**
     * Returns post-processed validation rules.
     *
     * @return array
     */
    public function processedRules()
    {
        return $this->container->call([$this, 'rules']);
    }

    /**
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Initializes form request and checks context expecting a model route.
     *
     * @return $this
     */
    protected function initializeForModelRoute()
    {
        $routeHelper = $this->getRouteHelper();

        $this->modelSlug = $routeHelper->getModelSlugForCurrentRoute();

        if ( ! $this->modelSlug) {
            throw new RuntimeException("Could not determine model slug for route in request");
        }

        $this->modelInformation = $this->getModelInformationRepository()->getByKey($this->modelSlug);

        if ( ! $this->modelInformation) {
            throw new RuntimeException(
                "Could not load information for model slug '{$this->modelSlug}' in request"
            );
        }

        return $this;
    }


    /**
     * @return ModelInformationInterface|ModelInformation
     */
    protected function getModelInformation()
    {
        return $this->modelInformation;
    }

    /**
     * @return RouteHelperInterface
     */
    protected function getRouteHelper()
    {
        return app(RouteHelperInterface::class);
    }

    /**
     * @return ModelInformationRepositoryInterface
     */
    protected function getModelInformationRepository()
    {
        return app(ModelInformationRepositoryInterface::class);
    }

}

{'fraction_non_alphanumeric': 0.10970782280867107, 'fraction_numerical': 0.0, 'mean_word_length': 2.407835581245986, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '1203553', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1376, 'n_words': 288}