/** * 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); } }
function main() { stream_filter_register('test.md5', 'Md5Filter'); stream_filter_register('test.ucase', 'UpperCaseFilter'); doTest('stream_filter_append'); doTest('stream_filter_prepend'); }
public function setup() { stream_filter_register('horde_crc32', 'Horde_Stream_Filter_Crc32'); $this->testdata = str_repeat("0123456789ABCDE", 1000); $this->fp = fopen('php://temp', 'r+'); fwrite($this->fp, $this->testdata); }
public function setup() { stream_filter_register('horde_null', 'Horde_Stream_Filter_Null'); $this->testdata = "abcdefghij"; $this->fp = fopen('php://temp', 'r+'); fwrite($this->fp, $this->testdata); }
/** * Attaches the current filter to a stream. * * @return bool true on success or false on failure. */ public function register() { if (!$this->isRegistered) { $this->isRegistered = stream_filter_register(static::NAME, get_called_class()); } return $this->isRegistered; }
function register_default_stream_filters() { \stream_filter_register('zlib.deflate', '__SystemLib\\DeflateStreamFilter'); \stream_filter_register('zlib.inflate', '__SystemLib\\InflateStreamFilter'); \stream_filter_register('string.rot13', '__SystemLib\\StringRot13StreamFilter'); \stream_filter_Register('string.toupper', '__SystemLib\\StringToUpperStreamFilter'); \stream_filter_Register('string.tolower', '__SystemLib\\StringToLowerStreamFilter'); }
public function setUp() { // register filter $filters = stream_get_filters(); if (!in_array('crypto.filter', $filters)) { stream_filter_register('crypto.filter', 'Fruit\\CryptoKit\\CryptoFilter'); } }
/** * Register Influence loader and filter. */ private function registerModules() { $loaders = spl_autoload_functions(); foreach ($loaders as $loader) { spl_autoload_unregister($loader); } spl_autoload_register([$this, 'loadClass']); stream_filter_register('influence.reader', 'Influence\\Filter'); }
function sgregister() { static $registered = null; if ($registered === null) { $registered = 'stream-callback'; stream_filter_register($registered, 'CallbackFilter'); } return $registered; }
/** * 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; }
/** * Register this class as a stream filter * @throws \RuntimeException */ public static function register() { if (self::$hasBeenRegistered === true) { return; } if (stream_filter_register(self::getFilterName(), __CLASS__) === false) { throw new RuntimeException('Failed to register stream filter: ' . self::getFilterName()); } self::$hasBeenRegistered = true; }
static function register($filter = null, $class = null) { if (empty($filter)) { $filter = empty($class) ? new static() : new $class(); } $class = get_class($filter); self::$registry[$class] = $filter; stream_filter_register($class, $class); return $filter->filterPrefix = 'php://filter/read=' . $class . '/resource='; }
/** * @dataProvider bodyFilterProvider() */ public function testBodyFilter($data, $result) { $params = new stdClass(); $stream = fopen('php://temp', 'r+'); stream_filter_register('horde_smtp_body', 'Horde_Smtp_Filter_Body'); stream_filter_append($stream, 'horde_smtp_body', STREAM_FILTER_WRITE, $params); fwrite($stream, $data); fclose($stream); $this->assertEquals($result, $params->body); }
public function testUserFilter() { stream_filter_register("strtoupper", "strtoupper_filter"); $fp = fopen("php://memory", 'r+'); stream_filter_append($fp, "strtoupper"); fputs($fp, "test\n"); rewind($fp); $contents = stream_get_contents($fp); $this->assertEquals("TEST\n", $contents); }
/** * @dataProvider provideBrokenParameters */ public function testFilterHandlesBrokenParameter($param) { $fp = fopen('php://memory', 'w+'); $append = "hello {$param}\n"; fputs($fp, str_repeat('a', 16384 - strlen($append)) . $append . str_repeat('test', 300)); rewind($fp); stream_filter_register('addresses', 'Horde_Kolab_Filter_Helper_AddressFilter'); stream_filter_append($fp, 'addresses'); fread($fp, 16384 - strlen($append)); $this->assertEquals("hello {$param}\n", fread($fp, strlen($append))); }
/** * Register current loader as stream filter in PHP * * @param string $filterId Identifier for the filter * @throws \RuntimeException If registration was failed */ public static function register($filterId = self::FILTER_IDENTIFIER) { if (!empty(self::$filterId)) { throw new \RuntimeException('Stream filter already registered'); } $result = stream_filter_register($filterId, __CLASS__); if (!$result) { throw new \RuntimeException('Stream filter was not registered'); } self::$filterId = $filterId; }
function register_default_stream_filters() { \stream_filter_register('zlib.deflate', '__SystemLib\\DeflateStreamFilter'); \stream_filter_register('zlib.inflate', '__SystemLib\\InflateStreamFilter'); \stream_filter_register('string.rot13', '__SystemLib\\StringRot13StreamFilter'); \stream_filter_Register('string.toupper', '__SystemLib\\StringToUpperStreamFilter'); \stream_filter_Register('string.tolower', '__SystemLib\\StringToLowerStreamFilter'); \stream_filter_Register('convert.iconv.*', '__SystemLib\\ConvertIconvFilter'); \stream_filter_Register('convert.*', '__SystemLib\\ConvertFilter'); \stream_filter_Register('bzip2.*', '__SystemLib\\Bzip2Filter'); }
public function __construct(MessageFactoryInterface $messageFactory, $entrypoint, $context = null, $useTls = null) { if ($context === null) { $context = stream_context_create(); } $this->entrypoint = $entrypoint; $this->messageFactory = $messageFactory; $this->context = $context; $this->useTls = $useTls; stream_filter_register('chunk', '\\Docker\\Http\\Stream\\Filter\\Chunk'); stream_filter_register('event', '\\Docker\\Http\\Stream\\Filter\\Event'); }
function main() { $fname = tempnam('/tmp', 'foo'); stream_filter_register('ClosingFilter', 'ClosingFilter'); $f = fopen($fname, 'r+'); stream_filter_append($f, 'ClosingFilter', STREAM_FILTER_WRITE); fwrite($f, 'foo bar'); fwrite($f, 'herp derp'); fclose($f); var_dump(file_get_contents($fname)); unlink($fname); }
/** * Return the escaped string as a stream. * * @return resource The IMAP escaped stream. */ public function escapeStream() { if ($this->literal()) { throw new Horde_Imap_Client_Data_Format_Exception('String requires literal to output.'); } rewind($this->_data->stream); $stream = new Horde_Stream_Temp(); $stream->add($this->_data, true); stream_filter_register('horde_imap_client_string_quote', 'Horde_Imap_Client_Data_Format_Filter_Quote'); stream_filter_append($stream->stream, 'horde_imap_client_string_quote', STREAM_FILTER_READ); return $stream->stream; }
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); } }
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); }
/** * Loads an XML file. * * @param string $file The filename. * * @return SimpleXMLElement * * @throw RuntimeException If file not found or there was an error when reading the file. */ public static function loadFile($file) { if (file_exists($file) === false) { throw new \RuntimeException(sprintf('File "%s" not found.', $file)); } $internal_errors = libxml_use_internal_errors(true); stream_filter_register('xmlutf8', 'Spress\\Import\\Support\\ValidUtf8XmlFilter'); $xml = simplexml_load_file('php://filter/read=xmlutf8/resource=' . $file); if ($xml === false) { throw new \RuntimeException(sprintf('There was an error when reading this XML file: "%s".', libxml_get_errors())); } return $xml; }
/** * Register a stream filter. * * @param string $name Filter name. * @param mixed $class Class name or instance. * @param bool $overwrite Overwrite filter if already exists or * not. Given by self::*OVERWRITE constants. * @return bool * @throws \Hoa\Stream\Filter\Exception */ public static function register($name, $class, $overwrite = self::DO_NOT_OVERWRITE) { if ($overwrite === self::DO_NOT_OVERWRITE && true === self::isRegistered($name)) { throw new Exception('Filter %s is already registered.', 0, $name); } if (empty($name)) { throw new Exception('Filter name cannot be empty.', 1); } if (is_object($class)) { $class = get_class($class); } return stream_filter_register($name, $class); }
function main() { $filters = array('FatalFilter', 'StrPassFilter', 'BoolPassFilter', 'NullFilter'); foreach ($filters as $filter) { printf("---%s---\n", $filter); stream_filter_register($filter, $filter); $f = fopen('php://memory', 'r+'); stream_filter_append($f, $filter, STREAM_FILTER_READ); fwrite($f, 'foo'); rewind($f); var_dump(fread($f, 1024)); } }
/** * @param string $xmlFileUri * @param string $delimiterTagName * @param array $options * * @throws \Exception */ function __construct($xmlFileUri, $delimiterTagName, $options = array()) { $this->xmlFileUri = $xmlFileUri; $this->delimiterTagName = $delimiterTagName; // work-around for non-scalar default value $this->options["readerOptions"] = \XMLReader::VALIDATE | \XMLReader::SUBST_ENTITIES | LIBXML_NOCDATA; $this->options = array_replace_recursive($this->options, $options); $this->reader = new \XMLReader(); $this->doc = new \DOMDocument(); if ($this->options["utf8Filter"]) { require_once "Utf8Filter.php"; stream_filter_register('xmlutf8', __NAMESPACE__ . "\\Utf8Filter"); } }
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); }
/** */ public function send($recipients, array $headers, $body) { $headers = $this->_sanitizeHeaders($headers); $recipients = implode(',', $this->parseRecipients($recipients)); $subject = ''; foreach (array_keys($headers) as $hdr) { if (strcasecmp($hdr, 'Subject') === 0) { // Get the Subject out of the headers array so that we can // pass it as a separate argument to mail(). $subject = $headers[$hdr]; unset($headers[$hdr]); } elseif (strcasecmp($hdr, 'To') === 0) { // Remove the To: header. The mail() function will add its // own To: header based on the contents of $recipients. unset($headers[$hdr]); } } // Flatten the headers out. list(, $text_headers) = $this->prepareHeaders($headers); // mail() requires a string for $body. If resource, need to convert // to a string. if (is_resource($body)) { $body_str = ''; stream_filter_register('horde_eol', 'Horde_Stream_Filter_Eol'); stream_filter_append($body, 'horde_eol', STREAM_FILTER_READ, array('eol' => $this->sep)); rewind($body); while (!feof($body)) { $body_str .= fread($body, 8192); } $body = $body_str; } else { // Convert EOL characters in body. $body = $this->_normalizeEOL($body); } // We only use mail()'s optional fifth parameter if the additional // parameters have been provided and we're not running in safe mode. if (empty($this->_params) || ini_get('safe_mode')) { $result = mail($recipients, $subject, $body, $text_headers); } else { $result = mail($recipients, $subject, $body, $text_headers, isset($this->_params['args']) ? $this->_params['args'] : ''); } // If the mail() function returned failure, we need to create an // Exception and return it instead of the boolean result. if ($result === false) { throw new Horde_Mail_Exception('mail() returned failure.'); } }
function main() { $filters = array('TrueFilter', 'FalseFilter', 'NullFilter'); foreach ($filters as $filter) { printf("---%s---\n", $filter); stream_filter_register($filter, $filter); print "r\n"; $fr = fopen('php://memory', 'r'); stream_filter_append($fr, $filter); print "r+\n"; $frp = fopen('php://memory', 'r+'); stream_filter_append($frp, $filter); print "w\n"; $fw = fopen('php://memory', 'w'); stream_filter_append($fw, $filter); } }
function main() { stream_filter_register('Foo', 'Foo'); stream_filter_register('Bar', 'Bar'); $f = fopen('php://memory', 'r+'); $filter = stream_filter_append($f, 'Foo', STREAM_FILTER_WRITE); fwrite($f, 'herp'); stream_filter_remove($filter); rewind($f); var_dump(fread($f, 1024)); $f = fopen('php://memory', 'r+'); $filter = stream_filter_append($f, 'Bar', STREAM_FILTER_WRITE); fwrite($f, 'herp'); stream_filter_remove($filter); rewind($f); var_dump(fread($f, 1024)); }