CURLStringFile.php
34 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | if (\PHP_VERSION_ID >= 70400 && \extension_loaded('curl')) { |
| 5 | class CURLStringFile extends \CURLFile |
| 6 | { |
| 7 | private $data; |
| 8 | public function __construct(string $data, string $postname, string $mime = 'application/octet-stream') |
| 9 | { |
| 10 | $this->data = $data; |
| 11 | parent::__construct('data://application/octet-stream;base64,' . \base64_encode($data), $mime, $postname); |
| 12 | } |
| 13 | public function __set(string $name, $value) : void |
| 14 | { |
| 15 | if ('data' !== $name) { |
| 16 | $this->{$name} = $value; |
| 17 | return; |
| 18 | } |
| 19 | if (\is_object($value) ? !\method_exists($value, '__toString') : !\is_scalar($value)) { |
| 20 | throw new \TypeError('Cannot assign ' . \gettype($value) . ' to property CURLStringFile::$data of type string'); |
| 21 | } |
| 22 | $this->name = 'data://application/octet-stream;base64,' . \base64_encode($value); |
| 23 | } |
| 24 | public function __isset(string $name) : bool |
| 25 | { |
| 26 | return isset($this->{$name}); |
| 27 | } |
| 28 | public function &__get(string $name) |
| 29 | { |
| 30 | return $this->{$name}; |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 |