本文整理汇总了PHP中stream_get_filters函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_get_filters函数的具体用法?PHP stream_get_filters怎么用?PHP stream_get_filters使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stream_get_filters函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_register_filter
public function test_register_filter()
{
ConvertMbstringEncoding::register();
$filterName = ConvertMbstringEncoding::getFilterName();
$registeredFilters = stream_get_filters();
$this->assertTrue(in_array($filterName, $registeredFilters));
}
示例2: setUp
/**
* Setup method. Ensure filter we depend on is available
*
* @return void
*/
public function setUp()
{
$depend = $this->filter();
if (!in_array($depend, stream_get_filters())) {
throw new PrerequisitesNotMetError(ucfirst($depend) . ' stream filter not available', null, [$depend]);
}
}
示例3: setUp
public function setUp()
{
// register filter
$filters = stream_get_filters();
if (!in_array('crypto.filter', $filters)) {
stream_filter_register('crypto.filter', 'Fruit\\CryptoKit\\CryptoFilter');
}
}
示例4: register
/**
* Register the stream filter
*
* @return bool
*/
public static function register()
{
$result = false;
$name = self::getName();
if (!empty($name) && !in_array($name, stream_get_filters())) {
$result = stream_filter_register(self::getName(), get_called_class());
}
return $result;
}
示例5: renderWithContext
protected function renderWithContext()
{
if (!in_array("displayObjectRenderer", stream_get_filters())) {
stream_filter_register("displayObjectRenderer", "DisplayObjectRenderer");
}
$pointer = fopen($this->url, "r");
if ($this->context) {
stream_filter_append($pointer, "displayObjectRenderer", STREAM_FILTER_READ, $this->context);
} else {
stream_filter_append($pointer, "displayObjectRenderer", STREAM_FILTER_READ);
}
return stream_get_contents($pointer);
}
示例6: renderDisplayObjectWithUri
public static function renderDisplayObjectWithUri($uri, &$dictionary = null)
{
if (!in_array("displayObjectRenderer_mustache", stream_get_filters())) {
stream_filter_register("displayObjectRenderer_mustache", "AMMustacheRenderer");
}
if (file_exists($uri)) {
$pointer = fopen($uri, "r");
stream_filter_append($pointer, "displayObjectRenderer_mustache", STREAM_FILTER_READ);
return stream_get_contents($pointer);
} else {
trigger_error('AMMustache unable to open file ' . $uri, E_USER_ERROR);
}
}
示例7: renderDisplayObjectWithURLAndDictionary
public static function renderDisplayObjectWithURLAndDictionary($url, &$dictionary = null)
{
static $suffix;
// = 1;
if (!in_array("displayObjectRenderer_{$suffix}", stream_get_filters())) {
stream_filter_register("displayObjectRenderer_{$suffix}", "DisplayObjectRenderer");
}
$pointer = fopen($url, "r");
if ($dictionary) {
stream_filter_append($pointer, "displayObjectRenderer_{$suffix}", STREAM_FILTER_READ, $dictionary);
} else {
stream_filter_append($pointer, "displayObjectRenderer_{$suffix}", STREAM_FILTER_READ);
}
//$suffix++;
return stream_get_contents($pointer);
}
示例8: testHandlesCompression
public function testHandlesCompression()
{
$body = EntityBody::factory('testing 123...testing 123');
$this->assertFalse($body->getContentEncoding(), '-> getContentEncoding() must initially return FALSE');
$size = $body->getContentLength();
$body->compress();
$this->assertEquals('gzip', $body->getContentEncoding(), '-> getContentEncoding() must return the correct encoding after compressing');
$this->assertEquals(gzdeflate('testing 123...testing 123'), (string) $body);
$this->assertTrue($body->getContentLength() < $size);
$this->assertTrue($body->uncompress());
$this->assertEquals('testing 123...testing 123', (string) $body);
$this->assertFalse($body->getContentEncoding(), '-> getContentEncoding() must reset to FALSE');
if (in_array('bzip2.*', stream_get_filters())) {
$this->assertTrue($body->compress('bzip2.compress'));
$this->assertEquals('compress', $body->getContentEncoding(), '-> compress() must set \'compress\' as the Content-Encoding');
}
$this->assertFalse($body->compress('non-existent'), '-> compress() must return false when a non-existent stream filter is used');
// Release the body
unset($body);
// Use gzip compression on the initial content. This will include a
// gzip header which will need to be stripped when deflating the stream
$body = EntityBody::factory(gzencode('test'));
$this->assertSame($body, $body->setStreamFilterContentEncoding('zlib.deflate'));
$this->assertTrue($body->uncompress('zlib.inflate'));
$this->assertEquals('test', (string) $body);
unset($body);
// Test using a very long string
$largeString = '';
for ($i = 0; $i < 25000; $i++) {
$largeString .= chr(rand(33, 126));
}
$body = EntityBody::factory($largeString);
$this->assertEquals($largeString, (string) $body);
$this->assertTrue($body->compress());
$this->assertNotEquals($largeString, (string) $body);
$compressed = (string) $body;
$this->assertTrue($body->uncompress());
$this->assertEquals($largeString, (string) $body);
$this->assertEquals($compressed, gzdeflate($largeString));
$body = EntityBody::factory(fopen(__DIR__ . '/../TestData/compress_test', 'w'));
$this->assertFalse($body->compress());
unset($body);
unlink(__DIR__ . '/../TestData/compress_test');
}
示例9: streams
function streams()
{
$sw = stream_get_wrappers();
$sf = stream_get_filters();
/*
Console::writeLn("Stream Management");
Console::writeLn(" |- Registered wrappers");
for($n=0; $n<count($sw); $n++) {
$this->treenode( $sw[$n] , !(($n+1)<count($sw)), false );
}
Console::writeLn(" '- Registered filters");
for($n=0; $n<count($sf); $n++) {
$this->treenode( $sf[$n] , !(($n+1)<count($sf)), true );
}
*/
$cb = 0;
Console::writeLn(__astr("\\b{Registered Wrappers:}"));
sort($sw);
foreach ($sw as $val) {
Console::write(' %-18s', $val);
$cb++;
if ($cb > 3 && $val != end($sw)) {
Console::writeLn();
$cb = 0;
}
}
Console::writeLn();
Console::writeLn();
$cb = 0;
Console::writeLn(__astr("\\b{Registered Filters:}"));
sort($sf);
foreach ($sf as $val) {
Console::write(' %-18s', $val);
$cb++;
if ($cb > 3 && $val != end($sf)) {
Console::writeLn();
$cb = 0;
}
}
Console::writeLn();
Console::writeLn();
}
示例10: putfile
//.........这里部分代码省略.........
$errno = 0;
$errstr = '';
$hosts = (!empty($proxyHost) ? $scheme . $proxyHost : $scheme . $host) . ':' . (!empty($proxyPort) ? $proxyPort : $port);
$fp = @stream_socket_client($hosts, $errno, $errstr, 120, STREAM_CLIENT_CONNECT);
if (!$fp) {
if (!function_exists('stream_socket_client')) {
html_error('[ERROR] stream_socket_client() is disabled.');
}
$dis_host = !empty($proxyHost) ? $proxyHost : $host;
$dis_port = !empty($proxyPort) ? $proxyPort : $port;
html_error(sprintf(lang(88), $dis_host, $dis_port));
}
if ($errno || $errstr) {
$lastError = $errstr;
return false;
}
if ($proxy) {
echo '<p>' . sprintf(lang(89), $proxyHost, $proxyPort) . '<br />PUT: <b>' . htmlspecialchars($url) . "</b>...<br />\n";
} else {
echo '<p>' . sprintf(lang(90), $host, $port) . '</p>';
}
echo lang(104) . ' <b>' . htmlspecialchars($filename) . '</b>, ' . lang(56) . ' <b>' . bytesToKbOrMbOrGb($fileSize) . '</b>...<br />';
$GLOBALS['id'] = md5(time() * rand(0, 10));
require TEMPLATE_DIR . '/uploadui.php';
flush();
$timeStart = microtime(true);
$chunkSize = GetChunkSize($fileSize);
fwrite($fp, $request);
fflush($fp);
$fs = fopen($file, 'r');
$totalsend = $time = $lastChunkTime = 0;
while (!feof($fs) && !$errno && !$errstr) {
$data = fread($fs, $chunkSize);
if ($data === false) {
fclose($fs);
fclose($fp);
html_error(lang(112));
}
$sendbyte = @fwrite($fp, $data);
fflush($fp);
if ($sendbyte === false || strlen($data) > $sendbyte) {
fclose($fs);
fclose($fp);
html_error(lang(113));
}
$totalsend += $sendbyte;
$time = microtime(true) - $timeStart;
$chunkTime = $time - $lastChunkTime;
$chunkTime = $chunkTime > 0 ? $chunkTime : 1;
$lastChunkTime = $time;
$speed = round($sendbyte / 1024 / $chunkTime, 2);
$percent = round($totalsend / $fileSize * 100, 2);
echo "<script type='text/javascript'>pr('{$percent}', '" . bytesToKbOrMbOrGb($totalsend) . "', '{$speed}');</script>\n";
flush();
}
if ($errno || $errstr) {
$lastError = $errstr;
return false;
}
fclose($fs);
fflush($fp);
$llen = 0;
$header = '';
do {
$header .= fgets($fp, 16384);
$len = strlen($header);
if (!$header || $len == $llen) {
$lastError = lang(91);
stream_socket_shutdown($fp, STREAM_SHUT_RDWR);
fclose($fp);
return false;
}
$llen = $len;
} while (strpos($header, $nn . $nn) === false);
// Array for active stream filters
$sFilters = array();
if (stripos($header, "\nTransfer-Encoding: chunked") !== false && in_array('dechunk', stream_get_filters())) {
$sFilters['dechunk'] = stream_filter_append($fp, 'dechunk', STREAM_FILTER_READ);
}
// Add built-in dechunk filter
$page = '';
do {
$data = @fread($fp, 16384);
if ($data == '') {
break;
}
$page .= $data;
} while (!feof($fp) && strlen($data) > 0);
stream_socket_shutdown($fp, STREAM_SHUT_RDWR);
fclose($fp);
if (stripos($header, "\nTransfer-Encoding: chunked") !== false && empty($sFilters['dechunk']) && function_exists('http_chunked_decode')) {
$dechunked = http_chunked_decode($page);
if ($dechunked !== false) {
$page = $dechunked;
}
unset($dechunked);
}
$page = $header . $page;
return $page;
}
示例11: CheckBack
public function CheckBack($header)
{
if (stripos($header, "\nContent-Type: text/html") !== false) {
global $fp, $sFilters;
if (empty($fp) || !is_resource($fp)) {
html_error('[filesflash_com] Cannot check download error.');
}
$is_chunked = stripos($header, "\nTransfer-Encoding: chunked") !== false;
if (!isset($sFilters) || !is_array($sFilters)) {
$sFilters = array();
}
if ($is_chunked && empty($sFilters['dechunk']) && in_array('dechunk', stream_get_filters())) {
$sFilters['dechunk'] = stream_filter_append($fp, 'dechunk', STREAM_FILTER_READ);
}
$body = stream_get_contents($fp);
if ($is_chunked && empty($sFilters['dechunk']) && function_exists('http_chunked_decode')) {
$dechunked = http_chunked_decode($body);
if ($dechunked !== false) {
$body = $dechunked;
}
unset($dechunked);
}
is_present($body, 'Your IP address is not valid for this link.', '[filesflash_com] Your IP address is not valid for this link.');
is_present($body, 'Your IP address is already downloading another link.', '[filesflash_com] Your IP address is already downloading another link.');
is_present($body, 'Your link has expired.', '[filesflash_com] Your link has expired.');
is_present($body, 'Interrupted free downloads cannot be resumed.', '[filesflash_com] Interrupted free downloads cannot be resumed.');
html_error('[filesflash_com] Unknown download error.');
}
}
示例12: attachFilter
/**
* Attach a filter in FIFO order
*
* @param mixed $filter An object that implements ObjectInterface, ObjectIdentifier object
* or valid identifier string
* @param array $config An optional array of filter config options
* @return bool Returns TRUE if the filter was attached, FALSE otherwise
*/
public function attachFilter($filter, $config = array())
{
$result = false;
//Handle custom filters
if (!in_array($filter, stream_get_filters())) {
//Create the complete identifier if a partial identifier was passed
if (is_string($filter) && strpos($filter, '.') === false) {
$identifier = clone $this->getIdentifier();
$identifier->path = array('stream', 'filter');
$identifier->name = $filter;
} else {
$identifier = $this->getIdentifier($filter);
}
if ($identifier->inherits('Nooku\\Library\\FilesystemStreamFilterInterface')) {
$filter = $identifier->classname;
$filter::register();
$filter = $filter::getName();
}
}
//If we have a valid filter name create the filter and append it
if (is_string($filter) && !empty($filter)) {
$mode = 0;
if ($this->isReadable()) {
$mode = $mode & STREAM_FILTER_READ;
}
if ($this->isWritable()) {
$mode = $mode & STREAM_FILTER_WRITE;
}
if ($resource = stream_filter_append($this->_resource, $filter, $mode, $config)) {
$this->_filters[$filter] = $filter;
$result = true;
}
}
return $result;
}
示例13: testRespondWithPaddedStreamFilterOutput
/**
* @runInSeparateProcess
*/
public function testRespondWithPaddedStreamFilterOutput()
{
$availableFilter = stream_get_filters();
if (in_array('mcrypt.*', $availableFilter) && in_array('mdecrypt.*', $availableFilter)) {
$app = new App();
$app->get('/foo', function ($req, $res) {
$key = base64_decode('xxxxxxxxxxxxxxxx');
$iv = base64_decode('Z6wNDk9LogWI4HYlRu0mng==');
$data = 'Hello';
$length = strlen($data);
$stream = fopen('php://temp', 'r+');
$filter = stream_filter_append($stream, 'mcrypt.rijndael-128', STREAM_FILTER_WRITE, ['key' => $key, 'iv' => $iv]);
fwrite($stream, $data);
rewind($stream);
stream_filter_remove($filter);
stream_filter_append($stream, 'mdecrypt.rijndael-128', STREAM_FILTER_READ, ['key' => $key, 'iv' => $iv]);
return $res->withHeader('Content-Length', $length)->withBody(new Body($stream));
});
// Prepare request and response objects
$env = Environment::mock(['SCRIPT_NAME' => '/index.php', 'REQUEST_URI' => '/foo', 'REQUEST_METHOD' => 'GET']);
$uri = Uri::createFromEnvironment($env);
$headers = Headers::createFromEnvironment($env);
$cookies = [];
$serverParams = $env->all();
$body = new RequestBody();
$req = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
$res = new Response();
// Invoke app
$resOut = $app($req, $res);
$app->respond($resOut);
$this->assertInstanceOf('\\Psr\\Http\\Message\\ResponseInterface', $resOut);
$this->expectOutputString('Hello');
} else {
$this->assertTrue(true);
}
}
示例14: registerStreamExtensions
/**
* Registers stream extensions for PartStream and CharsetStreamFilter
*
* @see stream_filter_register
* @see stream_wrapper_register
*/
protected function registerStreamExtensions()
{
stream_filter_register(UUEncodeStreamFilter::STREAM_FILTER_NAME, __NAMESPACE__ . '\\Stream\\UUEncodeStreamFilter');
stream_filter_register(CharsetStreamFilter::STREAM_FILTER_NAME, __NAMESPACE__ . '\\Stream\\CharsetStreamFilter');
stream_wrapper_register(PartStream::STREAM_WRAPPER_PROTOCOL, __NAMESPACE__ . '\\Stream\\PartStream');
// hhvm compatibility -- at time of writing, no convert.* filters
// should return false if already registered
$filters = stream_get_filters();
// @codeCoverageIgnoreStart
if (!in_array('convert.*', $filters)) {
stream_filter_register(QuotedPrintableDecodeStreamFilter::STREAM_FILTER_NAME, __NAMESPACE__ . '\\Stream\\QuotedPrintableDecodeStreamFilter');
stream_filter_register(Base64DecodeStreamFilter::STREAM_FILTER_NAME, __NAMESPACE__ . '\\Stream\\Base64DecodeStreamFilter');
}
// @codeCoverageIgnoreEnd
}
示例15: CheckBack
public function CheckBack(&$headers)
{
if (substr($headers, 9, 3) == '416') {
html_error('[google_com.php] Plugin needs a fix, \'Range\' method is not working.');
}
if (stripos($headers, "\nTransfer-Encoding: chunked") !== false) {
global $fp, $sFilters;
if (empty($fp) || !is_resource($fp)) {
html_error('Error: Your rapidleech copy is outdated and it doesn\'t support functions required by this plugin.');
}
if (!in_array('dechunk', stream_get_filters())) {
html_error('Error: dechunk filter not available, cannot download chunked file.');
}
if (!isset($sFilters) || !is_array($sFilters)) {
$sFilters = array();
}
if (empty($sFilters['dechunk'])) {
$sFilters['dechunk'] = stream_filter_append($fp, 'dechunk', STREAM_FILTER_READ);
}
if (!$sFilters['dechunk']) {
html_error('Error: Unknown error while initializing dechunk filter, cannot download chunked file.');
}
// Little hack to get the filesize.
$headers = preg_replace('@\\nContent-Range\\: bytes 0-\\d+/@i', "\nContent-Length: ", $headers, 1);
}
}