<commit_before><?php

	function SymWrite($section) {
		return new SymWrite($section);
	}

	class SymWrite extends SymQuery {
		protected $filterable = false;
		protected $writes = array();

		public function set($field, $data) {
			$this->writes[] = self::buildFieldWriter($field, $data, $this->section);

			return $this;
		}

		public function write() {
			$author = SymQuery::$symphony->Author;
			$section = $this->section->get('object');
			$entry = SymQuery::$em->create();
			$entry_data = array();

			// Build default entry data:
			$entry->set('section_id', $section->get('id'));
			if (is_object($author)) $entry->set('author_id', $author->get('id'));
			$entry->set('creation_date', DateTimeObj::get('Y-m-d H:i:s'));
			$entry->set('creation_date_gmt', DateTimeObj::getGMT('Y-m-d H:i:s'));

			foreach ($this->writes as $write) {
				$field = $write->get('object');
				$field_data = $write->get('data');

				if ($field == SymQuery::SYSTEM_ID) {
					$entry->set('id', $field_data);
				}

				else if ($field instanceof Field) {
					$field_handle = $field->get('element_name');

					$entry_data[$field_handle] = $field_data;
				}
			}

			if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($entry_data, $errors)) {			
				$validation_errors = array();
				foreach($errors as $field_id => $message) {
					$validation_errors[$field_id] = array(
						'field' => self::$field_cache[$field_id],
						'error' => $message
					);
				}
				
				$error = new SymWriteException('Unable to validate entry.');
				$error->setValidationErrors($validation_errors);

				throw $error;
			}

			if (__ENTRY_OK__ != $entry->setDataFromPost($entry_data, $error)) {
				throw new SymQueryException(sprintf(
					'Unable to save entry: %s', $error
				));
			}
<commit_msg>Field validation<commit_after><?php

	function SymWrite($section) {
		return new SymWrite($section);
	}

	class SymWrite extends SymQuery {
		protected $filterable = false;
		protected $writes = array();

		public function set($field, $data) {
			$this->writes[] = self::buildFieldWriter($field, $data, $this->section);

			return $this;
		}

		public function write() {
			$author = SymQuery::$symphony->Author;
			$section = $this->section->get('object');
			$entry = SymQuery::$em->create();
			$entry_data = array();

			// Build default entry data:
			$entry->set('section_id', $section->get('id'));
			if (is_object($author)) $entry->set('author_id', $author->get('id'));
			$entry->set('creation_date', DateTimeObj::get('Y-m-d H:i:s'));
			$entry->set('creation_date_gmt', DateTimeObj::getGMT('Y-m-d H:i:s'));

			foreach ($this->writes as $write) {
				$field = $write->get('object');
				$field_data = $write->get('data');

				if ($field == SymQuery::SYSTEM_ID) {
					$entry->set('id', $field_data);
				}

				else if ($field instanceof Field) {
					$field_handle = $field->get('element_name');

					$entry_data[$field_handle] = $field_data;
				}
			}

			if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($entry_data, $errors)) {			
				$validation_errors = array();

				foreach($errors as $field_id => $message) {
					$validation_errors[$field_id] = array(
						'field' => self::$field_cache[$field_id],
						'error' => $message
					);
				}
				
				$error = new SymWriteException('Unable to validate entry.');
				$error->setValidationErrors($validation_errors);

				throw $error;
			}

			if (__ENTRY_OK__ != $entry->setDataFromPost($entry_data, $error)) {
				throw new SymQueryException(sprintf(
					'Unable to save entry: %s', $error
				));
			}

{'fraction_non_alphanumeric': 0.18524774774774774, 'fraction_numerical': 0.0, 'mean_word_length': 3.834013605442177, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, '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': '6474212', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1165, 'n_words': 227}