| 1 |
<?php |
| 2 |
|
| 3 |
declare (strict_types=1); |
| 4 |
namespace WCPOS\Vendor\Sentry\Attachment; |
| 5 |
|
| 6 |
/** |
| 7 |
* Represents a file that is readable by using a path. |
| 8 |
*/ |
| 9 |
class FileAttachment extends Attachment |
| 10 |
{ |
| 11 |
/** |
| 12 |
* @var string |
| 13 |
*/ |
| 14 |
private $path; |
| 15 |
public function __construct(string $path, string $contentType) |
| 16 |
{ |
| 17 |
parent::__construct(\basename($path), $contentType); |
| 18 |
$this->path = $path; |
| 19 |
} |
| 20 |
public function getSize() : ?int |
| 21 |
{ |
| 22 |
$size = @\filesize($this->path); |
| 23 |
if ($size !== \false) { |
| 24 |
return $size; |
| 25 |
} |
| 26 |
return null; |
| 27 |
} |
| 28 |
public function getData() : ?string |
| 29 |
{ |
| 30 |
try { |
| 31 |
$content = @\file_get_contents($this->path); |
| 32 |
if ($content !== \false) { |
| 33 |
return $content; |
| 34 |
} |
| 35 |
return null; |
| 36 |
} catch (\ValueError $e) { |
| 37 |
return null; |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|