<?php
 declare(strict_types=1); namespace Square\Utils; use SplFileObject; class FileWrapper { private $realFilePath; private $mimeType; private $filename; public static function createFromPath(string $realFilePath, ?string $mimeType = null, ?string $filename = ''): self { return new self($realFilePath, $mimeType, $filename); } private function __construct(string $realFilePath, ?string $mimeType, ?string $filename) { $this->realFilePath = $realFilePath; $this->mimeType = $mimeType; $this->filename = $filename; } public function getMimeType(): ?string { return $this->mimeType; } public function getFilename(): ?string { return $this->filename; } public function createCurlFileInstance(string $defaultMimeType): \CURLFile { $mimeType = $this->mimeType ?? $defaultMimeType; return new \CURLFile($this->realFilePath, $mimeType, $this->filename); } public function getContent(): ?string { $thisFile = new SplFileObject($this->realFilePath); $content = $thisFile->fread($thisFile->getSize()); return $content === false ? null : $content; } } 