本文整理汇总了PHP中stream_filter_prepend函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_filter_prepend函数的具体用法?PHP stream_filter_prepend怎么用?PHP stream_filter_prepend使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stream_filter_prepend函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCrc32
public function testCrc32()
{
$filter = stream_filter_prepend($this->fp, 'horde_bin2hex', STREAM_FILTER_READ);
rewind($this->fp);
$this->assertEquals(bin2hex($this->testdata), stream_get_contents($this->fp));
stream_filter_remove($filter);
}
示例2: testNull
public function testNull()
{
$filter = stream_filter_prepend($this->fp, 'horde_null', STREAM_FILTER_READ);
rewind($this->fp);
$this->assertEquals('abcdefghij', stream_get_contents($this->fp));
stream_filter_remove($filter);
}
示例3: sgprepend
function sgprepend($stream, $callback, $read_write = STREAM_FILTER_ALL)
{
$ret = @stream_filter_prepend($stream, sgregister(), $read_write, $callback);
if ($ret === false) {
$error = error_get_last() + array('message' => '');
throw new RuntimeException('Unable to prepend filter: ' . $error['message']);
}
return $ret;
}
示例4: testCrc32
public function testCrc32()
{
$params = new stdClass();
$filter = stream_filter_prepend($this->fp, 'horde_crc32', STREAM_FILTER_READ, $params);
rewind($this->fp);
while (fread($this->fp, 1024)) {
}
$this->assertObjectHasAttribute('crc32', $params);
$this->assertEquals(crc32($this->testdata), $params->crc32);
stream_filter_remove($filter);
}
示例5: filter_test
function filter_test($names)
{
$fp = tmpfile();
fwrite($fp, $GLOBALS["text"]);
rewind($fp);
foreach ($names as $name) {
echo "filter: {$name}\n";
var_dump(stream_filter_prepend($fp, $name));
}
var_dump(fgets($fp));
fclose($fp);
}
示例6: testBug12673
public function testBug12673()
{
$test = str_repeat(str_repeat("A", 1) . "\r\n", 4000);
rewind($this->fp);
fwrite($this->fp, $test);
$filter = stream_filter_prepend($this->fp, 'horde_eol', STREAM_FILTER_READ, array('eol' => "\r\n"));
rewind($this->fp);
$this->assertEquals($test, stream_get_contents($this->fp));
$test = str_repeat(str_repeat("A", 14) . "\r\n", 2);
rewind($this->fp);
ftruncate($this->fp, 0);
fwrite($this->fp, $test);
stream_filter_prepend($this->fp, 'horde_eol', STREAM_FILTER_READ, array('eol' => "\r\n"));
rewind($this->fp);
$this->assertEquals($test, fread($this->fp, 14) . fread($this->fp, 1) . fread($this->fp, 1) . fread($this->fp, 14) . fread($this->fp, 2) . fread($this->fp, 100));
}
示例7: _checkEncoding
/**
* Checks if the data needs to be encoded like e.g., when outputing binary
* data in-line during ITEMOPERATIONS requests.
*
* @param mixed $data The data to check. A string or stream resource.
* @param string $tag The tag we are outputing.
*
* @return mixed The encoded data. A string or stream resource with
* a filter attached.
*/
protected function _checkEncoding($data, $tag)
{
if ($tag == Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_DATA) {
// See Bug: 14086. Use a STREAM_FILTER_WRITE and perform the
// filtering here instead of using the currently broken behavior of
// PHP when using base64-encode as STREAM_FILTER_READ. feof() is
// apparently not safe to use when using STREAM_FILTER_READ.
if (is_resource($data)) {
$temp = fopen('php://temp/', 'r+');
$filter = stream_filter_prepend($temp, 'convert.base64-encode', STREAM_FILTER_WRITE);
rewind($data);
while (!feof($data)) {
fwrite($temp, fread($data, 8192));
}
stream_filter_remove($filter);
rewind($temp);
return $temp;
} else {
return base64_encode($data);
}
}
return $data;
}
示例8: array
function &prependFilter($filtername, $read_write = STREAM_FILTER_READ, $params = array())
{
$res = false;
if ($this->_fh) {
// Capture PHP errors
$php_errormsg = '';
$track_errors = ini_get('track_errors');
ini_set('track_errors', true);
$res = @stream_filter_prepend($this->_fh, $filername, $read_write, $params);
if (!$res && $php_errormsg) {
$this->setError($php_errormsg);
} else {
JUtility::array_unshift_ref($res, $this->filters);
}
// push the new resource onto the filter stack
// restore error tracking to what it was before
ini_set('track_errors', $track_errors);
}
return $res;
}
示例9: var_dump
if ($closed > 0) {
var_dump($closed++);
}
return PSFS_PASS_ON;
}
}
class SecondFilter extends php_user_filter
{
public function filter($in, $out, &$consumed, $closing)
{
static $closed = 0;
while ($bucket = stream_bucket_make_writeable($in)) {
stream_bucket_append($out, stream_bucket_new($this->stream, $bucket->data));
}
if ($closing) {
$closed++;
}
if ($closed > 0) {
var_dump($closed++);
}
return PSFS_PASS_ON;
}
}
$r = fopen("php://stdout", "w+");
stream_filter_register("first", "FirstFilter");
stream_filter_register("second", "SecondFilter");
$first = stream_filter_prepend($r, "first", STREAM_FILTER_WRITE, []);
$second = stream_filter_prepend($r, "second", STREAM_FILTER_WRITE, []);
fwrite($r, "test\n");
stream_filter_remove($second);
stream_filter_remove($first);
开发者ID:gleamingthecube,项目名称:php,代码行数:31,代码来源:ext_standard_tests_streams_stream_multi_filters_close.php
示例10: CheckBack
public function CheckBack($header)
{
$statuscode = intval(substr($header, 9, 3));
if ($statuscode != 200) {
switch ($statuscode) {
case 509:
html_error('[Mega] Transfer quota exeeded.');
case 503:
html_error('Too many connections for this download.');
case 403:
html_error('Link used/expired.');
case 404:
html_error('Link expired.');
default:
html_error('[HTTP] ' . trim(substr($header, 9, strpos($header, "\n") - 8)));
}
}
global $fp;
if (empty($fp) || !is_resource($fp)) {
html_error("Error: Your rapidleech version is outdated and it doesn't support this plugin.");
}
if (!empty($_GET['T8']['fkey'])) {
$key = $this->base64_to_a32(urldecode($_GET['T8']['fkey']));
} elseif (preg_match('@^(T8)?!([^!]{8})!([\\w\\-\\,]{43})@i', parse_url($_GET['referer'], PHP_URL_FRAGMENT), $dat)) {
$key = $this->base64_to_a32($dat[2]);
} else {
html_error("[CB] File's key not found.");
}
$iv = array_merge(array_slice($key, 4, 2), array(0, 0));
$key = array($key[0] ^ $key[4], $key[1] ^ $key[5], $key[2] ^ $key[6], $key[3] ^ $key[7]);
$opts = array('iv' => $this->a32_to_str($iv), 'key' => $this->a32_to_str($key), 'mode' => 'ctr');
stream_filter_register('MegaDlDecrypt', 'Th3822_MegaDlDecrypt');
stream_filter_prepend($fp, 'MegaDlDecrypt', STREAM_FILTER_READ, $opts);
}
示例11: enable_compression
/**
* attempt enable IMAP COMPRESS extension
* @todo: currently does not work ...
* @return void
*/
public function enable_compression()
{
if ($this->is_supported('COMPRESS=DEFLATE')) {
$this->send_command("COMPRESS DEFLATE\r\n");
$res = $this->get_response(false, true);
if ($this->check_response($res, true)) {
stream_filter_prepend($this->handle, 'zlib.inflate', STREAM_FILTER_READ);
stream_filter_append($this->handle, 'zlib.deflate', STREAM_FILTER_WRITE, 6);
$this->debug[] = 'DEFLATE compression extension activated';
}
}
}
示例12: var_dump
<?php
var_dump(stream_get_filters("a"));
var_dump(stream_filter_register());
var_dump(stream_filter_append());
var_dump(stream_filter_prepend());
var_dump(stream_filter_remove());
var_dump(stream_bucket_make_writeable());
var_dump(stream_bucket_append());
var_dump(stream_bucket_prepend());
示例13: convert
/**
*
* Change file encoding
*
* @param string $file file path
* @param string $from original file encoding
* @param string $to target file encoding
* @throws waException
* @return string converted file path
*/
public static function convert($file, $from, $to = 'UTF-8')
{
if ($src = fopen($file, 'rb')) {
$filter = sprintf('convert.iconv.%s/%s//IGNORE', $from, $to);
if (!@stream_filter_prepend($src, $filter)) {
throw new waException("error while register file filter");
}
$file = preg_replace('/(\\.[^\\.]+)$/', '.' . $to . '$1', $file);
if ($this->fp && ($dst = fopen($file, 'wb'))) {
stream_copy_to_stream($this->fp, $dst);
fclose($src);
fclose($dst);
} else {
throw new waException("Error while convert file encoding");
}
return $file;
} else {
return false;
}
}
示例14: convert
/**
*
* Changes text file character encoding.
*
* @param string $file Path to file
* @param string $from Original encoding
* @param string $to Target encoding
* @param string $target Optional path to save encoded file to
* @throws waException
* @return string Path to file containing converted text
*/
public static function convert($file, $from, $to = 'UTF-8', $target = null)
{
if ($src = fopen($file, 'rb')) {
$filter = sprintf('convert.iconv.%s/%s//IGNORE', $from, $to);
if (!@stream_filter_prepend($src, $filter)) {
throw new waException("error while register file filter");
}
if ($target === null) {
$extension = pathinfo($file, PATHINFO_EXTENSION);
if ($extension) {
$extension = '.' . $extension;
}
$target = preg_replace('@\\.[^\\.]+$@', '', $file) . '_' . $to . $extension;
}
if ($dst = fopen($target, 'wb')) {
stream_copy_to_stream($src, $dst);
fclose($src);
fclose($dst);
} else {
fclose($src);
throw new waException("Error while convert file encoding");
}
return $target;
} else {
return false;
}
}
示例15: prependFilter
/**
* Prepend a filter to the chain
*
* @param string $filtername The key name of the filter.
* @param integer $read_write Optional. Defaults to STREAM_FILTER_READ.
* @param array $params An array of params for the stream_filter_prepend call.
*
* @return mixed
*
* @see http://php.net/manual/en/function.stream-filter-prepend.php
* @since 11.1
*/
public function prependFilter($filtername, $read_write = STREAM_FILTER_READ, $params = array())
{
$res = false;
if ($this->_fh) {
// Capture PHP errors
$php_errormsg = '';
$track_errors = ini_get('track_errors');
ini_set('track_errors', true);
$res = @stream_filter_prepend($this->_fh, $filtername, $read_write, $params);
if (!$res && $php_errormsg) {
$this->setError($php_errormsg);
// set the error msg
} else {
array_unshift($res, '');
$res[0] =& $this->filters;
}
// Restore error tracking to what it was before.
ini_set('track_errors', $track_errors);
}
return $res;
}