<commit_before><?php

namespace FormObject;

use \ArrayAccess;
use \FormObject\Field\Action;
use \FormObject\Field\HiddenField;
use \FormObject\Validator\ValidatorAdapterInterface;
use FormObject\Validator\SimpleValidator;

class Form extends FormItem implements ArrayAccess{

    const GET = 'get';

    const POST = 'post';

    const REQUEST = 1;

    const MANUAL = 2;

    /**
    * @brief Holds the Form Fields
    * @var FieldList
    */
    public $fields = NULL;

    /**
    * @brief Holds the Form Actions (Submit Button, Reset Button ...)
    * @var FieldList
    */
    public $actions = NULL;


    protected $action = '';

    protected $method = self::POST;

    protected $_needsValidation = FALSE;

    protected $_wasSubmitted = FALSE;

    protected $dataOrigin;

    protected $validator = NULL;

    protected $validatorAdapter = NULL;


    /**
    * @brief multipart/form-data
    * @var string
    */
    protected $encType = '';

    public function __construct($data=NULL){

        $this->fields = $this->createFields();
        $this->actions = $this->createActions();

        $this->getId();
        $this->getName();
        $this->getAction();
        $this->getMethod();
        $this->getEncType();

        if(is_object($data)){
            $this->fillBy($data);
        }
        elseif(is_array($data)){
            $this->fillByArray($data);
        }
    }

    protected function updateAttributes(Attributes $attributes){
        parent::updateAttributes($attributes);
        $attributes['method'] = $this->getMethod();
        $attributes['enctype'] = $this->getEncType();
        $attributes['action'] = $this->getAction();
    }

    public function getValidatorAdapter(){
        if(!$this->validatorAdapter){
            $this->validatorAdapter = $this->createValidatorAdapter($this->getValidator());
        }
        return $this->validatorAdapter;
    }

    public function setValidatorAdapter(ValidatorAdapterInterface $adapter){
        $this->validatorAdapter = $adapter;
        return $this;
    }

    protected function createValidatorAdapter($validator){
        return $this->getValidator();
    }

    public function getValidator(){
        if(!$this->validator){
            $this->validator = $this->createValidator();
        }
        return $this->validator;
    }

    protected function createValidator(){
        return new SimpleValidator($this);
    }

    public function setValidator($validator){
        $this->validator = $validator;
        return $this;
    }

    public function getDataOrigin(){
        return $this->dataOrigin;<commit_msg>Hook into setValidator instead of direct assigning<commit_after><?php

namespace FormObject;

use \ArrayAccess;
use \FormObject\Field\Action;
use \FormObject\Field\HiddenField;
use \FormObject\Validator\ValidatorAdapterInterface;
use FormObject\Validator\SimpleValidator;

class Form extends FormItem implements ArrayAccess{

    const GET = 'get';

    const POST = 'post';

    const REQUEST = 1;

    const MANUAL = 2;

    /**
    * @brief Holds the Form Fields
    * @var FieldList
    */
    public $fields = NULL;

    /**
    * @brief Holds the Form Actions (Submit Button, Reset Button ...)
    * @var FieldList
    */
    public $actions = NULL;


    protected $action = '';

    protected $method = self::POST;

    protected $_needsValidation = FALSE;

    protected $_wasSubmitted = FALSE;

    protected $dataOrigin;

    protected $validator = NULL;

    protected $validatorAdapter = NULL;


    /**
    * @brief multipart/form-data
    * @var string
    */
    protected $encType = '';

    public function __construct($data=NULL){

        $this->fields = $this->createFields();
        $this->actions = $this->createActions();

        $this->getId();
        $this->getName();
        $this->getAction();
        $this->getMethod();
        $this->getEncType();

        if(is_object($data)){
            $this->fillBy($data);
        }
        elseif(is_array($data)){
            $this->fillByArray($data);
        }
    }

    protected function updateAttributes(Attributes $attributes){
        parent::updateAttributes($attributes);
        $attributes['method'] = $this->getMethod();
        $attributes['enctype'] = $this->getEncType();
        $attributes['action'] = $this->getAction();
    }

    public function getValidatorAdapter(){
        if(!$this->validatorAdapter){
            $this->validatorAdapter = $this->createValidatorAdapter($this->getValidator());
        }
        return $this->validatorAdapter;
    }

    public function setValidatorAdapter(ValidatorAdapterInterface $adapter){
        $this->validatorAdapter = $adapter;
        return $this;
    }

    protected function createValidatorAdapter($validator){
        return $this->getValidator();
    }

    public function getValidator(){
        if(!$this->validator){
            $this->setValidator($this->createValidator());
        }
        return $this->validator;
    }

    protected function createValidator(){
        return new SimpleValidator($this);
    }

    public function setValidator($validator){
        $this->validator = $validator;
        return $this;
    }

    public function getDataOrigin(){
        return $this->dataOrigin;
{'fraction_non_alphanumeric': 0.131225146752509, 'fraction_numerical': 0.0007574323044877864, 'mean_word_length': 2.620287868403016, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, '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': '4518316', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1389, 'n_words': 312}