<commit_before><?php

namespace mii\web;


use mii\util\HTML;
use mii\util\Upload;
use mii\valid\Validation;
use mii\web\Request;

class Form {

    /**
     * @var Validation
     */
    public $validation;

    public $fields = [];

    public $select_data = [];

    public $labels = [];

    public $enable_csrf_validation = true;

    protected $_csrf_token = '';

    protected $_data = [];

    /**
     * @param null $data Initial data for form. If null then request->post() will be used
     */
    public function __construct($data = null) {

        $this->validation = new Validation();
    }

    /**
     * Load form from _POST values or $data values
     * Return true if request method is post
     * @return bool
     */
    public function load($data = null) {

        if($this->posted()) {
            $data = \Mii::$app->request->post();
        }

        if(count($data)) {
            $this->fields = array_replace_recursive($this->fields, $data);
            $this->_data = $data;
        }

        return $this->posted();
    }

    public function posted() {
        return \Mii::$app->request->method() === Request::POST;
    }

    public function rules() {
        return [];
    }

    public function fields() {
        return $this->fields;
    }

    public function data() {
        return $this->_data;
    }

    public function get($name) {
        return $this->fields[$name];
    }

    public function set($name, $value) {
        return $this->fields[$name] =  $value;<commit_msg>form->load now can process orm model<commit_after><?php

namespace mii\web;


use mii\db\ORM;
use mii\util\HTML;
use mii\util\Upload;
use mii\valid\Validation;
use mii\web\Request;

class Form {

    /**
     * @var Validation
     */
    public $validation;

    public $fields = [];

    public $select_data = [];

    public $labels = [];

    public $enable_csrf_validation = true;

    protected $_csrf_token = '';

    protected $_data = [];

    protected $_model;

    /**
     * @param null $data Initial data for form. If null then request->post() will be used
     */
    public function __construct($data = null) {

        $this->validation = new Validation();
    }

    /**
     * Load form from _POST values or $data values
     * Return true if request method is post
     * @return bool
     */
    public function load($data = null) {

        if($this->posted()) {
            $data = \Mii::$app->request->post();
        }

        if(is_object($data) AND $data instanceof ORM) {
            $this->_model = $data;
            $data = $data->as_array();
        }

        if(count($data)) {
            $this->fields = array_replace_recursive($this->fields, $data);
            $this->_data = $data;
        }

        return $this->posted();
    }

    public function posted() {
        return \Mii::$app->request->method() === Request::POST;
    }

    public function rules() {
        return [];
    }

    public function fields() {
        return $this->fields;
    }

    public function model() {
        return $this->_model;
    }

    public function data() {
        return $this->_data;
    }

    public function get($name) {
        return $this->fields[$name];
    }

    public function set($name, $value) {
        return $this->fields[$name] =  $value;
{'fraction_non_alphanumeric': 0.1450105517033464, 'fraction_numerical': 0.0, 'mean_word_length': 2.052437902483901, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, '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': '1020101', 'n_tokens_mistral': 1014, 'n_tokens_neox': 965, 'n_words': 252}