/** * @deprecated Moved to puzzle_stream_Utils::open() */ function puzzle_stream_safe_open($filename, $mode) { return puzzle_stream_Utils::open($filename, $mode); }
public static function ___error_handler() { $funcArgs = func_get_args(); $arg1 = $funcArgs[1]; self::$_open_ex = new RuntimeException(sprintf('Unable to open %s using mode %s: %s', self::$_open_filename, self::$_open_mode, $arg1)); }
/** * Creates the underlying stream lazily when required. * * @return puzzle_stream_StreamInterface */ protected function createStream() { return puzzle_stream_Stream::factory(puzzle_stream_Utils::open($this->filename, $this->mode)); }
/** * Drain the stream into the destination stream */ private function getSaveToBody(puzzle_message_RequestInterface $request, puzzle_stream_StreamInterface $stream) { $config = $request->getConfig(); if ($saveTo = $config['save_to']) { // Stream the response into the destination stream $saveTo = is_string($saveTo) ? new puzzle_stream_Stream(puzzle_stream_Utils::open($saveTo, 'r+')) : puzzle_stream_Stream::factory($saveTo); } else { // Stream into the default temp stream $saveTo = puzzle_stream_Stream::factory(); } puzzle_stream_Utils::copyToStream($stream, $saveTo); $saveTo->seek(0); $stream->close(); return $saveTo; }
public function testProxiesToFactory() { $this->assertEquals('foo', (string) puzzle_stream_Utils::create('foo')); }
public function getContents($maxLength = -1) { return puzzle_stream_Utils::copyToString($this, $maxLength); }
public function testSkipsOverwrittenBytes() { $decorated = puzzle_stream_Stream::factory(implode("\n", array_map(array($this, '__callback_testSkipsOverwrittenBytes'), range(0, 25))), true); $body = new puzzle_stream_CachingStream($decorated); $this->assertEquals("0000\n", puzzle_stream_Utils::readline($body)); $this->assertEquals("0001\n", puzzle_stream_Utils::readline($body)); // Write over part of the body yet to be read, so skip some bytes $this->assertEquals(5, $body->write("TEST\n")); $this->assertEquals(5, $this->readAttribute($body, 'skipReadBytes')); // Read, which skips bytes, then reads $this->assertEquals("0003\n", puzzle_stream_Utils::readline($body)); $this->assertEquals(0, $this->readAttribute($body, 'skipReadBytes')); $this->assertEquals("0004\n", puzzle_stream_Utils::readline($body)); $this->assertEquals("0005\n", puzzle_stream_Utils::readline($body)); // Overwrite part of the cached body (so don't skip any bytes) $body->seek(5); $this->assertEquals(5, $body->write("ABCD\n")); $this->assertEquals(0, $this->readAttribute($body, 'skipReadBytes')); $this->assertEquals("TEST\n", puzzle_stream_Utils::readline($body)); $this->assertEquals("0003\n", puzzle_stream_Utils::readline($body)); $this->assertEquals("0004\n", puzzle_stream_Utils::readline($body)); $this->assertEquals("0005\n", puzzle_stream_Utils::readline($body)); $this->assertEquals("0006\n", puzzle_stream_Utils::readline($body)); $this->assertEquals(5, $body->write("1234\n")); $this->assertEquals(5, $this->readAttribute($body, 'skipReadBytes')); // Seek to 0 and ensure the overwritten bit is replaced $body->seek(0); $this->assertEquals("0000\nABCD\nTEST\n0003\n0004\n0005\n0006\n1234\n0008\n0009\n", $body->read(50)); // Ensure that casting it to a string does not include the bit that was overwritten $this->assertContains("0000\nABCD\nTEST\n0003\n0004\n0005\n0006\n1234\n0008\n0009\n", (string) $body); }