Skip to content

Instantly share code, notes, and snippets.

@chx
Created July 7, 2012 09:05
Show Gist options
  • Save chx/3065563 to your computer and use it in GitHub Desktop.
Save chx/3065563 to your computer and use it in GitHub Desktop.
Dummy filter
<?php
class DummyFilter extends PHP_User_Filter
{
private $_data;
/* Called when the filter is initialized */
function onCreate( )
{
$this->_data = '';
return true;
}
/* This is where the actual stream data conversion takes place */
public function filter($in, $out, &$consumed, $closing)
{
/* We read all the stream data and store it in
the '$_data' variable
*/
while($bucket = stream_bucket_make_writeable($in))
{
$this->_data .= $bucket->data;
$this->bucket = $bucket;
$consumed = 0;
}
/* Now that we have read all the data from the stream we process
it and save it again to the bucket.
*/
if($closing)
{
$consumed += strlen($this->_data);
$this->bucket->data = $this->_data;
$this->bucket->datalen = strlen($this->_data);
// echo 'here'; // just to show this code is actually ran.
if(!empty($this->bucket->data))
stream_bucket_append($out, $this->bucket);
return PSFS_PASS_ON;
}
return PSFS_FEED_ME;
}
}
stream_filter_register('dummy', 'DummyFilter');
include("php://filter/read=dummy/resource=y.php");
$f = new ReflectionFunction('foobar');
echo $f->getFileName();
<?php
function foobar() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment