<commit_before><?php
namespace Simovative\Zeus\Http\Post;

/**
 * Represents a file that was uploaded by an post request.
 *
 * @author <NAME>
 */
class UploadedFile {
	
	/**
	 * @var string
	 */
	private $inputName;
	/**
	 * @var int
	 */
	private $inputIndex;
	/**
	 * @var string
	 */
	private $label;
	/**
	 * @var string
	 */
	private $type;
	/**
	 * @var string
	 */
	private $path;
	/**
	 * @var int
	 */
	private $errorCode;
	/**
	 * @var int
	 */
	private $size;
	
	/**
	 * @author <NAME>
	 * @param string $inputName
	 * @param int $inputIndex
	 * @param string $label
	 * @param string $type
	 * @param string $path
	 * @param int $errorCode
	 * @param int $size
	 */
	public function __construct($inputName, $inputIndex, $label, $type, $path, $errorCode, $size) {
		$this->inputName = $inputName;
		$this->inputIndex = $inputIndex;
		$this->label = $label;
		$this->type = $type;
		$this->path = $path;
		$this->errorCode = $errorCode;
		$this->size = $size;
	}
	
	/**
	 * Returns the uploaded files from a global files array.
	 *
	 * @author <NAME>
	 * @param array $filesArray
	 * @return UploadedFile[]
	 */
	public static function createFromGlobal($filesArray) {
		$uploadedFiles = array();
		$filesArray = self::normalizeFilesArray($filesArray);
		foreach ($filesArray as $key => $files) {
			foreach ($files as $index => $file) {
				$uploadedFiles[] = new UploadedFile(
					$key,
					$index,
					$file['name'],
					$file['type'],
					$file['tmp_name'],
					$file['error'],
					$file['size']
				);
			}
		}
		return $uploadedFiles;
	}
	
	/**
	 * Method to make handling of the files array easier, copied from
	 * http://php.net/manual/en/features.file-upload.post-method.php.
	 *
	 * @author <NAME>
	 * @param array $filesArray
	 * @return array
	 */
	private static function normalizeFilesArray($filesArray) {
		$normalizedFilesArray = [];
		foreach ($filesArray as $key => $file) {
			if (! is_array($file['name'])) {
				$normalizedFilesArray[$key][] = $file;
				continue;
			}
			foreach ($file['name'] as $fileIndex => $name) {
				$normalizedFilesArray[$key][$fileIndex] = [
					'name' => $name,
					'type' => $file['type'][$fileIndex],
					'tmp_name' => $file['tmp_name'][$fileIndex],
					'error' => $file['error'][$fileIndex],
					'size' => $file['size'][$fileIndex]
				];
			}
		}
		return $normalizedFilesArray;
	}
}<commit_msg>Add file upload for post.<commit_after><?php
namespace Simovative\Zeus\Http\Post;

/**
 * Represents a file that was uploaded by an post request.
 *
 * @author <NAME>
 */
class UploadedFile {
	
	/**
	 * @var string
	 */
	private $inputName;
	/**
	 * @var int
	 */
	private $inputIndex;
	/**
	 * @var string
	 */
	private $label;
	/**
	 * @var string
	 */
	private $type;
	/**
	 * @var string
	 */
	private $path;
	/**
	 * @var int
	 */
	private $errorCode;
	/**
	 * @var int
	 */
	private $size;
	
	/**
	 * @author <NAME>
	 * @param string $inputName
	 * @param int $inputIndex
	 * @param string $label
	 * @param string $type
	 * @param string $path
	 * @param int $errorCode
	 * @param int $size
	 */
	public function __construct($inputName, $inputIndex, $label, $type, $path, $errorCode, $size) {
		$this->inputName = $inputName;
		$this->inputIndex = $inputIndex;
		$this->label = $label;
		$this->type = $type;
		$this->path = $path;
		$this->errorCode = $errorCode;
		$this->size = $size;
	}
	
	/**
	 * Returns the uploaded files from a global files array.
	 *
	 * @author <NAME>
	 * @param array $filesArray
	 * @return UploadedFile[]
	 */
	public static function createFromGlobal($filesArray) {
		$uploadedFiles = array();
		$filesArray = self::normalizeFilesArray($filesArray);
		foreach ($filesArray as $key => $files) {
			foreach ($files as $index => $file) {
				$uploadedFiles[] = new UploadedFile(
					$key,
					$index,
					$file['name'],
					$file['type'],
					$file['tmp_name'],
					$file['error'],
					$file['size']
				);
			}
		}
		return $uploadedFiles;
	}
	
	/**
	 * Method to make handling of the files array easier, copied from
	 * http://php.net/manual/en/features.file-upload.post-method.php.
	 *
	 * @author <NAME>
	 * @param array $filesArray
	 * @return array
	 */
	private static function normalizeFilesArray($filesArray) {
		$normalizedFilesArray = [];
		foreach ($filesArray as $key => $file) {
			if (! is_array($file['name'])) {
				$normalizedFilesArray[$key][] = $file;
				continue;
			}
			foreach ($file['name'] as $fileIndex => $name) {
				$normalizedFilesArray[$key][$fileIndex] = [
					'name' => $name,
					'type' => $file['type'][$fileIndex],
					'tmp_name' => $file['tmp_name'][$fileIndex],
					'error' => $file['error'][$fileIndex],
					'size' => $file['size'][$fileIndex]
				];
			}
		}
		return $normalizedFilesArray;
	}
	
	/**
	 * Returns if we have a valid uploaded file or if someone tried to manipulate the request.
	 *
	 * @author <NAME>
	 * @return bool
	 */
	public function isValidUploadedFile() {
		return is_uploaded_file($this->path);
	}
	
	/**
	 * @author <NAME>
	 * @return string
	 */
	public function getInputName() {
		return $this->inputName;
	}
	
	/**
	 * @author <NAME>
	 * @return int
	 */
	public function getInputIndex() {
		return $this->inputIndex;
	}
	
	/**
	 * @author <NAME>
	 * @return string
	 */
	public function getLabel() {
		return $this->label;
	}
	
	/**
	 * Returns the transmitted file type, but you should not rely on this,
	 * because this can be manipulated.
	 *
	 * @author <NAME>
	 * @return string
	 */
	public function getType() {
		return $this->type;
	}
	
	/**
	 * @author <NAME>
	 * @return string
	 */
	public function getPath() {
		return $this->path;
	}
	
	/**
	 * Returns the Size in bytes.
	 *
	 * @author <NAME>
	 * @return int
	 */
	public function getSize() {
		return $this->size;
	}
	
}
{'fraction_non_alphanumeric': 0.17353654312435055, 'fraction_numerical': 0.0, 'mean_word_length': 3.0356394129979036, 'pattern_counts': {'":': 0, '<': 20, '<?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': '7295843', 'n_tokens_mistral': 2268, 'n_tokens_neox': 1928, 'n_words': 483}