<commit_before><?php

namespace SilverStripe\MultiForm\Forms;

use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\HiddenField;
use SilverStripe\MultiForm\Models\MultiFormSession;
use SilverStripe\MultiForm\Models\MultiFormStep;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;

/**
 * MultiForm manages the loading of single form steps, and acts as a state
 * machine that connects to a {@link MultiFormSession} object as a persistence
 * layer.
 *
 * CAUTION: If you're using controller permission control,
 * you have to allow the following methods:
 *
 * <code>
 * private static $allowed_actions = array('next','prev');
 * </code>
 *
 */
abstract class MultiForm extends Form
{
    /**
     * A session object stored in the database, to identify and store
     * data for this MultiForm instance.
     *
     * @var MultiFormSession
     */
    protected $session;

    /**
     * The current encrypted MultiFormSession identification.
     *
     * @var string
     */
    protected $currentSessionHash;

    /**
     * Defines which subclass of {@link MultiFormStep} should be the first
     * step in the multi-step process.
     *
     * @var string Classname of a {@link MultiFormStep} subclass
     */
    private static $start_step;

    /**
     * Set the casting for these fields.
     *
     * @var array
     */
    private static $casting = [
        'CompletedStepCount' => 'Int',
        'TotalStepCount' => 'Int',
        'CompletedPercent' => 'Float'
    ];

    /**
     * @var string
     */
    private static $get_var = 'MultiFormSessionID';

    /**
     * These fields are ignored when saving the raw form data into session.
     * This ensures only field data is saved, and nothing else that's useless
     * or potentially dangerous.
     *
     * @var array
     */
    private static $ignored_fields = [
        'url',
        'executeForm',
        'SecurityID'
    ];

    /**
     * Any of the actions defined in this variable are exempt from
     * being validated.
     *
     * This is most useful for the "Back" (action_prev) action, as
     * you typically don't validate the form when the user is going
     * back a step.
     *
     * @var array
     */
    private static $actions_exempt_from_validation = [
        'action_prev'
    ];

    /**
     * @var string
     */
    protected $displayLink;

    /**
     * Flag which is being used in getAllStepsRecursive() to allow adding the completed flag on the steps
     *
     * @var boolean
     */
    protected $currentStepHasBeenFound = false;

    /**
     * Start the MultiForm instance.
     *
     * @param Controller $controller Controller instance this form is created on
     * @param string $name The form name, typically the same as the method name
     */
    public function __construct($controller, $name)
    {
        // First set the controller and name manually so they are available for
        // field construction.
        $this->controller = $controller;
        $this->name       = $name;

        // Set up the session for this MultiForm instance
        $this->setSession();

        // Get the current step available (Note: either returns an existing
        // step or creates a new one if none available)
        $currentStep = $this->getCurrentStep();

        // Set the step returned above as the current step
        $this->setCurrentStep($currentStep);

        // Set the form of the step to this form instance
        $currentStep->setForm($this);

        // Set up the fields for the current step
        $fields = $currentStep->getFields();

        // Set up the actions for the current step
        $actions = $this->actionsFor($currentStep);

        // Set up validation (if necessary)
        $validator = null;
        $applyValidation = true;

        $actionNames = $this->config()->get('actions_exempt_from_validation');

        if ($actionNames) {
            foreach ($actionNames as $exemptAction) {
                if (!empty($this->getRequest()->requestVar($exemptAction))) {
                    $applyValidation = false;
                    break;
                }
            }
        }

        // Apply validation if the current step requires validation (is not exempt)
        if ($applyValidation) {
            if ($currentStep->getValidator()) {
                $this->setValidator($currentStep->getValidator());
            }
        }

        // Give the fields, actions, and validation for the current step back to the parent Form class
        parent::__construct($controller, $name, $fields, $actions);

        $getVar = $this->getGetVar();

        // Set a hidden field in our form with an encrypted hash to identify this session.
        $this->fields->push(HiddenField::create($getVar, false, $this->session->Hash));

        // If there is saved data for the current step, we load it into the form it here
        //(CAUTION: loadData() MUST unserialize first!)
        if ($data = $currentStep->loadData()) {
            $this->loadDataFrom($data);
        }

        // Disable security token - we tie a form to a session ID instead
        $this->disableSecurityToken();
<commit_msg>FIX: getValidator not being applied to instance<commit_after><?php

namespace SilverStripe\MultiForm\Forms;

use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\HiddenField;
use SilverStripe\MultiForm\Models\MultiFormSession;
use SilverStripe\MultiForm\Models\MultiFormStep;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;

/**
 * MultiForm manages the loading of single form steps, and acts as a state
 * machine that connects to a {@link MultiFormSession} object as a persistence
 * layer.
 *
 * CAUTION: If you're using controller permission control,
 * you have to allow the following methods:
 *
 * <code>
 * private static $allowed_actions = array('next','prev');
 * </code>
 *
 */
abstract class MultiForm extends Form
{
    /**
     * A session object stored in the database, to identify and store
     * data for this MultiForm instance.
     *
     * @var MultiFormSession
     */
    protected $session;

    /**
     * The current encrypted MultiFormSession identification.
     *
     * @var string
     */
    protected $currentSessionHash;

    /**
     * Defines which subclass of {@link MultiFormStep} should be the first
     * step in the multi-step process.
     *
     * @var string Classname of a {@link MultiFormStep} subclass
     */
    private static $start_step;

    /**
     * Set the casting for these fields.
     *
     * @var array
     */
    private static $casting = [
        'CompletedStepCount' => 'Int',
        'TotalStepCount' => 'Int',
        'CompletedPercent' => 'Float'
    ];

    /**
     * @var string
     */
    private static $get_var = 'MultiFormSessionID';

    /**
     * These fields are ignored when saving the raw form data into session.
     * This ensures only field data is saved, and nothing else that's useless
     * or potentially dangerous.
     *
     * @var array
     */
    private static $ignored_fields = [
        'url',
        'executeForm',
        'SecurityID'
    ];

    /**
     * Any of the actions defined in this variable are exempt from
     * being validated.
     *
     * This is most useful for the "Back" (action_prev) action, as
     * you typically don't validate the form when the user is going
     * back a step.
     *
     * @var array
     */
    private static $actions_exempt_from_validation = [
        'action_prev'
    ];

    /**
     * @var string
     */
    protected $displayLink;

    /**
     * Flag which is being used in getAllStepsRecursive() to allow adding the completed flag on the steps
     *
     * @var boolean
     */
    protected $currentStepHasBeenFound = false;

    /**
     * Start the MultiForm instance.
     *
     * @param Controller $controller Controller instance this form is created on
     * @param string $name The form name, typically the same as the method name
     */
    public function __construct($controller, $name)
    {
        // First set the controller and name manually so they are available for
        // field construction.
        $this->controller = $controller;
        $this->name       = $name;

        // Set up the session for this MultiForm instance
        $this->setSession();

        // Get the current step available (Note: either returns an existing
        // step or creates a new one if none available)
        $currentStep = $this->getCurrentStep();

        // Set the step returned above as the current step
        $this->setCurrentStep($currentStep);

        // Set the form of the step to this form instance
        $currentStep->setForm($this);

        // Set up the fields for the current step
        $fields = $currentStep->getFields();

        // Set up the actions for the current step
        $actions = $this->actionsFor($currentStep);

        // Give the fields, actions, and validation for the current step back to the parent Form class
        parent::__construct($controller, $name, $fields, $actions);

        // Set up validation (if necessary)
        $validator = null;
        $applyValidation = true;

        $actionNames = $this->config()->get('actions_exempt_from_validation');

        if ($actionNames) {
            foreach ($actionNames as $exemptAction) {
                if (!empty($this->getRequest()->requestVar($exemptAction))) {
                    $applyValidation = false;
                    break;
                }
            }
        }

        // Apply validation if the current step requires validation (is not exempt)
        if ($applyValidation) {
            if ($currentStep->getValidator()) {
                $this->setValidator($currentStep->getValidator());
            }
        }

        $getVar = $this->getGetVar();

        // Set a hidden field in our form with an encrypted hash to identify this session.
        $this->fields->push(HiddenField::create($getVar, false, $this->session->Hash));

        // If there is saved data for the current step, we load it into the form it here
        //(CAUTION: loadData() MUST unserialize first!)
        if ($data = $currentStep->loadData()) {
            $this->loadDataFrom($data);
        }

        // Disable security token - we tie a form to a session ID instead
        $this->disableSecurityToken();

{'fraction_non_alphanumeric': 0.09827174112888398, 'fraction_numerical': 0.0, 'mean_word_length': 2.358752701451065, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 59, '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': '2064115', 'n_tokens_mistral': 2925, 'n_tokens_neox': 2842, 'n_words': 1000}