for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
/**
* It's free open-source software released under the MIT License.
*
* @author Anatoly Nekhay <[email protected]>
* @copyright Copyright (c) 2018, Anatoly Nekhay
* @license https://github.com/sunrise-php/http-message/blob/master/LICENSE
* @link https://github.com/sunrise-php/http-message
*/
namespace Sunrise\Http\Message\Stream;
use Sunrise\Http\Message\Exception\RuntimeException;
use Sunrise\Http\Message\Stream;
use function is_resource;
use function is_writable;
use function sys_get_temp_dir;
use function tmpfile;
* The {@see tmpfile()} function opens a unique temporary file in binary
* read/write (w+b) mode. The file will be automatically deleted
* when it is closed or the program terminates.
final class TmpfileStream extends Stream
{
* @throws RuntimeException
public function __construct()
parent::__construct(self::createFile());
}
* @return resource
private static function createFile()
$dirname = sys_get_temp_dir();
if (!is_writable($dirname)) {
throw new RuntimeException('Temporary files directory is not writable');
$resource = tmpfile();
if (!is_resource($resource)) {
throw new RuntimeException('Temporary file cannot be created or opened');
return $resource;