. * * ========================= * * This file contains the class UploadedFilesSource * * @category API * @package DmarcSrg * @author Aleksey Andreev (liuch) * @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPLv3 */ namespace Liuch\DmarcSrg\Sources; use Liuch\DmarcSrg\ReportFile\ReportFile; use Liuch\DmarcSrg\Exception\SoftException; /** * This class is designed to process report files from uploaded files. */ class UploadedFilesSource extends Source { private $index = 0; /** * Returns an instance of the ReportFile class for the current file. * * @return ReportFile */ public function current(): object { if ($this->data['error'][$this->index] !== UPLOAD_ERR_OK) { throw new SoftException('Failed to upload the report file'); } $realfname = $this->data['name'][$this->index]; $tempfname = $this->data['tmp_name'][$this->index]; if (!is_uploaded_file($tempfname)) { throw new SoftException('Possible file upload attack'); } return ReportFile::fromFile($tempfname, $realfname, false); } /** * Returns the index of the currect file. * * @return int */ public function key(): int { return $this->index; } /** * Moves forward to the next file. * * @return void */ public function next(): void { ++$this->index; } /** * Rewinds the position to the first file. * * @return void */ public function rewind(): void { $this->index = 0; } /** * Checks if the current postion is valid * * @return bool */ public function valid(): bool { return isset($this->data['name'][$this->index]); } /** * Returns type of the source. * * @return int */ public function type(): int { return Source::SOURCE_UPLOADED_FILE; } }