本文整理汇总了PHP中stream_filter_append函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_filter_append函数的具体用法?PHP stream_filter_append怎么用?PHP stream_filter_append使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stream_filter_append函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($file, array $options = array())
{
$defaultOptions = array('length' => 0, 'fromEncoding' => null);
$this->options = array_merge($defaultOptions, $options);
if ($file instanceof SplFileInfo) {
$file = $file->getPathname();
}
if ($file instanceof \Guzzle\Stream\StreamInterface) {
$this->guzzleStream = $file;
$file = $file->getStream();
}
if (is_resource($file)) {
$this->fileHandle = $file;
$this->closeFileHandleOnDestruct = false;
if (null !== $this->options['fromEncoding']) {
throw new Exception('Source encoding can only be specified if constructed with file path');
}
} else {
if (is_string($file)) {
$this->fileHandle = @fopen($file, 'r');
if ($this->fileHandle === false) {
throw new InvalidArgumentException("Could not open csv file with path: '{$file}'");
}
if (null !== $this->options['fromEncoding']) {
stream_filter_append($this->fileHandle, 'convert.iconv.' . $this->options['fromEncoding'] . '/UTF-8');
}
$this->closeFileHandleOnDestruct = true;
} else {
throw new InvalidArgumentException('You must provide either a stream or filename to the csv iterator, you provided a ' . gettype($file));
}
}
parent::__construct(array_diff_key($options, $defaultOptions));
}
示例2: encodeStream
/**
* Encodes the given stream with the given encoding using stream filters
*
* If the given encoding stream filter is not available, an Exception
* will be thrown.
*
* @param string $stream
* @param string $encoding
* @param int $LineLength; defaults to Mime::LINE_LENGTH (72)
* @param string $eol EOL string; defaults to Mime::EOL (\n)
* @return string
*/
public static function encodeStream($stream, $encoding, $lineLength = self::LINE_LENGTH, $eol = self::EOL)
{
if (!self::isEncodingSupported($encoding)) {
throw new Exception("Not supported encoding: {$encoding}");
}
switch ($encoding) {
case self::BASE64:
$filter = 'convert.base64-encode';
break;
case self::QUOTED_PRINTABLE:
$filter = 'convert.quoted-printable-encode';
break;
default:
$filter = null;
}
if ($filter !== null) {
$params = array('line-length' => $lineLength, 'line-break-chars' => $eol);
$streamFilter = stream_filter_append($stream, $filter, STREAM_FILTER_READ, $params);
}
$content = stream_get_contents($stream);
if ($filter !== null) {
stream_filter_remove($streamFilter);
}
fclose($stream);
return $content;
}
示例3: runGiven
/**
* Handle a "given" step.
*
* @param array &$world Joined "world" of variables.
* @param string $action The description of the step.
* @param array $arguments Additional arguments to the step.
*
* @return mixed The outcome of the step.
*/
public function runGiven(&$world, $action, $arguments)
{
switch ($action) {
case 'an incoming message on host':
$world['hostname'] = $arguments[0];
$world['type'] = 'Incoming';
break;
case 'the SMTP sender address is':
$world['sender'] = $arguments[0];
break;
case 'the SMTP recipient address is':
$world['recipient'] = $arguments[0];
break;
case 'the client address is':
$world['client'] = $arguments[0];
break;
case 'the hostname is':
$world['hostname'] = $arguments[0];
break;
case 'the unmodified message content is':
$world['infile'] = $arguments[0];
$world['fp'] = fopen($world['infile'], 'r');
break;
case 'the modified message template is':
$world['infile'] = $arguments[0];
$world['fp'] = fopen($world['infile'], 'r');
stream_filter_register('addresses', 'Horde_Kolab_Filter_Helper_AddressFilter');
stream_filter_append($world['fp'], 'addresses', STREAM_FILTER_READ, array('recipient' => $world['recipient'], 'sender' => $world['sender']));
break;
default:
return $this->notImplemented($action);
}
}
示例4: __construct
/**
* Constructor
*
* @param io.streams.InputStream in
*/
public function __construct(InputStream $in)
{
$this->in = Streams::readableFd($in);
if (!stream_filter_append($this->in, 'zlib.inflate', STREAM_FILTER_READ)) {
throw new IOException('Could not append stream filter');
}
}
示例5: RawAction
public function RawAction()
{
$dataUriRegex = "/data:image\\/([\\w]*);([\\w]*),/i";
//running a regex against a data uri might be slow.
//Streams R fun.
// To avoid lots of processing before needed, copy just the first bit of the incoming data stream to a variable for checking. rewind the stream after. Part of the data will be MD5'd for storage.
// note for
$body = $this->detectRequestBody();
$tempStream = fopen('php://temp', 'r+');
stream_copy_to_stream($body, $tempStream, 500);
rewind($tempStream);
$uriHead = stream_get_contents($tempStream);
$netid = isset($_SERVER['NETID']) ? $_SERVER['NETID'] : "notSet";
$filename = $netid;
$matches = array();
// preg_match_all returns number of matches.
if (0 < preg_match_all($dataUriRegex, $uriHead, $matches)) {
$extension = $matches[1][0];
$encoding = $matches[2][0];
$start = 1 + strpos($uriHead, ",");
$imageData = substr($uriHead, $start);
// THERES NO ARRAY TO STRING CAST HERE PHP STFU
$filename = (string) ("./cache/" . $filename . "-" . md5($imageData) . "." . $extension);
$fileHandle = fopen($filename, "c");
stream_filter_append($fileHandle, 'convert.base64-decode', STREAM_FILTER_WRITE);
stream_copy_to_stream($body, $fileHandle, -1, $start);
}
}
示例6: sgfun
function sgfun($filter, $params = null)
{
$fp = fopen('php://memory', 'w');
$filter = @stream_filter_append($fp, $filter, STREAM_FILTER_WRITE, $params);
if ($filter === false) {
fclose($fp);
$error = error_get_last() + array('message' => '');
throw new RuntimeException('Unable to access built-in filter: ' . $error['message']);
}
// append filter function which buffers internally
$buffer = '';
sgappend($fp, function ($chunk) use(&$buffer) {
$buffer .= $chunk;
// always return empty string in order to skip actually writing to stream resource
return '';
}, STREAM_FILTER_WRITE);
$closed = false;
return function ($chunk = null) use($fp, $filter, &$buffer, &$closed) {
if ($closed) {
throw new RuntimeException('Unable to perform operation on closed stream');
}
if ($chunk === null) {
$closed = true;
$buffer = '';
fclose($fp);
return $buffer;
}
// initialize buffer and invoke filters by attempting to write to stream
$buffer = '';
fwrite($fp, $chunk);
// buffer now contains everything the filter function returned
return $buffer;
};
}
示例7: csp_decryptStream
/**
* csp_decryptStream
*
* Entschlüsselt einen Filestream
* Nach dem Beispiel von http://www.php.net/manual/en/filters.encryption.php
*
* @param resource &$fp Filepointer des zu entschlüsselnden Filestreams
* @param string $crypto_key Verwendeter Schlussel (Passphrase)
*/
function csp_decryptStream(&$fp, $crypto_key)
{
$iv = substr(md5('iv#' . $crypto_key, true), 0, 8);
$key = substr(md5('pass1#' . $crypto_key, true) . md5('pass2#' . $crypto_key, true), 0, 24);
$opts = array('iv' => $iv, 'key' => $key);
stream_filter_append($fp, 'mdecrypt.tripledes', STREAM_FILTER_WRITE, $opts);
}
示例8: doBackup
protected function doBackup($stream, $tables, $gzip = false)
{
$db = Am_Di::getInstance()->db;
$stream_filter = null;
$hash = null;
$len = 0;
if ($gzip) {
$hash = hash_init('crc32b');
// gzip file header
fwrite($stream, $this->getGzHeader());
if (!($stream_filter = stream_filter_append($stream, "zlib.deflate", STREAM_FILTER_WRITE, self::COMPRESSION_LEVEL))) {
throw new Am_Exception_InternalError("Could not attach gzencode filter to output stream");
}
}
$this->out($stream, "### aMember Pro " . AM_VERSION . " database backup\n", $len, $hash);
$this->out($stream, "### Created: " . date('Y-m-d H:i:s') . "\n", $len, $hash);
foreach ($tables as $table) {
$this->out($stream, "\n\nDROP TABLE IF EXISTS {$table};\n", $len, $hash);
$r = $db->selectRow("SHOW CREATE TABLE {$table}");
$this->out($stream, $r['Create Table'] . ";\n", $len, $hash);
$q = $db->queryResultOnly("SELECT * FROM {$table}");
while ($a = $db->fetchRow($q)) {
$fields = join(',', array_keys($a));
$values = join(',', array_map(array($db, 'escape'), array_values($a)));
$this->out($stream, "INSERT INTO {$table} ({$fields}) VALUES ({$values});\n", $len, $hash);
}
$db->freeResult($q);
}
if ($stream_filter) {
stream_filter_remove($stream_filter);
fwrite($stream, $this->getGzFooter($len, $hash));
}
return $stream;
}
示例9: __construct
/**
* Constructor
*
* @param io.streams.InputStream in
*/
public function __construct(InputStream $in)
{
$this->in = Streams::readableFd($in);
if (!stream_filter_append($this->in, 'bzip2.decompress', STREAM_FILTER_READ)) {
throw new \io\IOException('Could not append stream filter');
}
}
示例10: __construct
public function __construct(puzzle_stream_StreamInterface $stream)
{
// Skip the first 10 bytes
$stream = new puzzle_stream_LimitStream($stream, -1, 10);
$resource = puzzle_stream_GuzzleStreamWrapper::getResource($stream);
stream_filter_append($resource, 'zlib.inflate', STREAM_FILTER_READ);
$this->stream = new puzzle_stream_Stream($resource);
}
示例11: __construct
public function __construct(StreamInterface $stream)
{
// Skip the first 10 bytes
$stream = new LimitStream($stream, -1, 10);
$resource = StreamWrapper::getResource($stream);
stream_filter_append($resource, 'zlib.inflate', STREAM_FILTER_READ);
parent::__construct(new Stream($resource));
}
示例12: testEscape
/**
* @dataProvider escapeProvider
*/
public function testEscape($in, $expected)
{
$stream = fopen('php://temp', 'r+');
stream_filter_append($stream, self::FILTER_ID, STREAM_FILTER_READ);
fwrite($stream, $in);
rewind($stream);
$this->assertEquals($expected, stream_get_contents($stream));
}
示例13: __construct
/**
* Constructor
*
* @param io.streams.OutputStream out
* @param int lineLength limit maximum line length
*/
public function __construct(OutputStream $out, $lineLength = 0)
{
$params = $lineLength ? array('line-length' => $lineLength, 'line-break-chars' => "\n") : array();
$this->out = Streams::writeableFd($out);
if (!stream_filter_append($this->out, 'convert.base64-encode', STREAM_FILTER_WRITE, $params)) {
throw new IOException('Could not append stream filter');
}
}
示例14: __construct
/**
* @param callable $func filter proc
* @param callable $ctor constructor
* @param callable $dtor destructor
*/
function __construct(callable $func, callable $ctor = null, callable $dtor = null)
{
/*
* We don't have pipe(2) support, so we'll use socketpair(2) instead.
*/
list($this->input, $this->output) = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
stream_filter_append($this->input, "atick\\IO\\StreamFilter", STREAM_FILTER_WRITE, compact("func", "ctor", "dtor"));
stream_set_blocking($this->output, false);
}
示例15: parse
/**
* Parse the file and yield $closure for each line
* @param callable(RemoteZipCodeObject) $closure
*/
public function parse($url, Closure $closure)
{
$handle = fopen($url, 'r');
stream_filter_append($handle, 'convert.iconv.ISO-8859-15/UTF-8', STREAM_FILTER_READ);
while (($data = fgetcsv($handle, 0, "\t")) !== false) {
list($zip_code, $zip_name, $municipality_code, $municipality_name, $category) = $data;
$closure(new RemoteZipCodeObject($zip_code, $zip_name, $municipality_code, $municipality_name, $category));
}
}