createBody($filepath); if (class_exists(\Mimey\MimeTypes::class)) { $mime = (new \Mimey\MimeTypes())->getMimeType(pathinfo($filepath, PATHINFO_EXTENSION)); } else { $finfo = finfo_open(FILEINFO_MIME_TYPE); $mime = finfo_file($finfo, $filepath); finfo_close($finfo); } parent::__construct( $body, $status, $this->injectContentType($mime, $headers) ); } /** * Create the message body. * * @param string|StreamInterface $filepath * @throws Exception\InvalidArgumentException if $filepath is neither a string or stream. */ private function createBody($filepath) : StreamInterface { if ($filepath instanceof StreamInterface) { return $filepath; } if (! is_string($filepath)) { throw new Exception\InvalidArgumentException(sprintf( 'Invalid content (%s) provided to %s', (is_object($filepath) ? get_class($filepath) : gettype($filepath)), __CLASS__ )); } if ( ! file_exists($filepath) ) { throw new Exception\InvalidArgumentException("Given file (%s) do not look like a valid file path.", $filepath); } if ( ! is_readable($filepath) ) { throw new Exception\InvalidArgumentException("Given file (%s) do not seem to be readable. This could indicate a permission problem", $filepath); } return new Stream(fopen($filepath, "r"), 'r'); } }