public static function registerWrapper()
 {
     if (!self::$registered) {
         stream_register_wrapper('compress.lzw', __CLASS__);
     }
     self::$registered = true;
 }
Exemple #2
0
 /**
  * Register a stream wrapper according to its scheme and class.
  * Must called prior the opening of first stream under this scheme
  */
 public static function registerStreamWrapper()
 {
     if (in_array(static::SCHEME, stream_get_wrappers())) {
         stream_wrapper_unregister(static::SCHEME);
     }
     stream_register_wrapper(static::SCHEME, get_called_class());
 }
Exemple #3
0
 public function setUp()
 {
     $existed = in_array('imc', stream_get_wrappers());
     if (!$existed) {
         stream_register_wrapper('imc', 'ImcStream\\ImcStream');
     }
 }
 public static function setUpBeforeClass()
 {
     \stream_wrapper_unregister('http');
     \stream_wrapper_unregister('https');
     // Register HTTP
     \stream_register_wrapper('http', '\\Kshabazz\\Interception\\StreamWrappers\\Http', \STREAM_IS_URL);
     // Register HTTPS
     \stream_register_wrapper('https', '\\Kshabazz\\Interception\\StreamWrappers\\Http', \STREAM_IS_URL);
     Http::setSaveDir(FIXTURES_PATH);
 }
Exemple #5
0
 public static function register()
 {
     stream_register_wrapper('mmap', __CLASS__);
 }
Exemple #6
0
    public function stream_seek($offset, $whence)
    {
    }
    // end stream_seek();
    /**
     * PHP stream function - reports some data about the current file.
     * @return Array
     */
    public function stream_stat()
    {
        if (!isset(self::$files[$this->file])) {
            return array();
        }
        return array('size' => strlen($this->file));
    }
    // end stream_stat();
    /**
     * PHP stream function - reports some data about the current file.
     * @return Array
     */
    public function url_stat($path, $flags)
    {
        if (!isset(self::$files[$path])) {
            return false;
        }
        return array('size' => strlen($path));
    }
}
// end Extra_TestFS;
stream_register_wrapper('test', 'Extra_TestFS');
<?php

// << ...custom stream wrapper goes somewhere here...>>
echo '<pre>';
error_reporting(E_ALL);
ini_set('display_errors', true);
clearstatcache();
stream_register_wrapper('test', 'MemoryStream');
mkdir('test://aaa');
mkdir('test://aaa/cc');
mkdir('test://aaa/dd');
echo 'PHP ' . PHP_VERSION;
echo '<br />node exists: ' . file_exists('test://aaa/cc');
echo '<br />node is writable: ' . is_writable('test://aaa/cc');
echo '<br />node is dir: ' . is_dir('test://aaa/cc');
echo '<br />tempnam in dir: ' . tempnam('test://aaa/cc', 'tmp');
echo "<br /></pre>";
Exemple #8
0
 /**
  * Register this object as stream wrapper
  *
  * @param  string $name Protocol name
  */
 public function registerStreamWrapper($name = 'azure')
 {
     /**
      * @see Microsoft_WindowsAzure_Storage_Blob_Stream
      */
     require_once 'Microsoft/WindowsAzure/Storage/Blob/Stream.php';
     stream_register_wrapper($name, 'Microsoft_WindowsAzure_Storage_Blob_Stream');
     $this->registerAsClient($name);
 }
Exemple #9
0
 /**
  * Register this object as stream wrapper
  *
  * @param  string $name
  * @return Zend_Service_Amazon_S3
  */
 public function registerStreamWrapper($name = 's3')
 {
     /**
      * @see Zend_Service_Amazon_S3_Stream
      */
     #require_once 'Zend/Service/Amazon/S3/Stream.php';
     stream_register_wrapper($name, 'Zend_Service_Amazon_S3_Stream');
     $this->registerAsClient($name);
 }
Exemple #10
0
 /**
  * Register this object as stream wrapper
  *
  * @param  string $name
  * @return Zend_Service_Amazon_S3
  */
 public function registerStreamWrapper($name = 's3')
 {
     stream_register_wrapper($name, 'Zend_Service_Amazon_S3_Stream');
     $this->registerAsClient($name);
 }
Exemple #11
0
<?php

class test
{
    function stream_open()
    {
        echo "open\n";
        return true;
    }
    function stream_write($d)
    {
        echo "write {$d}\n";
        return strlen($d);
    }
    function stream_flush()
    {
        echo "flush\n";
        return true;
    }
    function stream_close()
    {
        echo "close\n";
    }
}
stream_register_wrapper("test", "test", STREAM_IS_URL);
var_dump(file_put_contents("test://hello", "w"));
 /**
  * @param \PHPUnit_Framework_TestSuite $suite
  */
 public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
 {
     foreach ($this->wrappers as $wrapper) {
         \stream_wrapper_unregister($wrapper);
         \stream_register_wrapper($wrapper, self::STREAM_WRAPPER_NAME_SPACE . $this->wrapperClass, \STREAM_IS_URL);
     }
     Http::setSaveDir($this->saveDir);
 }
                } else {
                    return false;
                }
                break;
            case SEEK_CUR:
                if ($offset >= 0) {
                    $this->pos += $offset;
                    return true;
                } else {
                    return false;
                }
                break;
            case SEEK_END:
                if (strlen($this->data) + $offset >= 0) {
                    $this->pos = strlen($this->data) + $offset;
                    return true;
                } else {
                    return false;
                }
                break;
            default:
                return false;
        }
    }
}
stream_register_wrapper("test1", "test", STREAM_IS_URL);
stream_register_wrapper("test2", "test");
echo @file_get_contents("test1://hello"), "\n";
@(include "test1://hello");
echo @file_get_contents("test2://hello"), "\n";
include "test2://hello";
Exemple #14
0
                    $this->position += $offset;
                    return true;
                } else {
                    return false;
                }
                break;
            case SEEK_END:
                if (strlen($GLOBALS[$this->varname]) + $offset >= 0) {
                    $this->position = strlen($GLOBALS[$this->varname]) + $offset;
                    return true;
                } else {
                    return false;
                }
                break;
            default:
                trigger_error("Unknown whence for fseek of global variable \${$this->varname}", E_USER_NOTICE);
                return false;
        }
    }
    /**
     * Callback for fstat().
     *
     * @return array
     */
    public function stream_stat()
    {
        return array();
    }
}
stream_register_wrapper('global', 'Q\\VariableStream');
Exemple #15
0
 /**
  * Register the stream
  */
 public function register()
 {
     if (isset($GLOBALS['sugar_config']['upload_wrapper_class'])) {
         SugarAutoLoader::requireWithCustom("include/{$GLOBALS['sugar_config']['upload_wrapper_class']}.php");
         if (class_exists($GLOBALS['sugar_config']['upload_wrapper_class'])) {
             self::$wrapper_class = $GLOBALS['sugar_config']['upload_wrapper_class'];
         } else {
             self::$wrapper_class = __CLASS__;
         }
     } else {
         self::$wrapper_class = __CLASS__;
     }
     stream_register_wrapper(self::STREAM_NAME, self::$wrapper_class);
     self::$instance = new self::$wrapper_class();
 }
 /**
  * Register this object as stream wrapper
  *
  * @param  string $name Protocol name
  */
 public function registerStreamWrapper($name = 'azure')
 {
     stream_register_wrapper($name, __NAMESPACE__ . '\\Stream');
     $this->registerAsClient($name);
 }
Exemple #17
0
    {
        return pg_lo_tell($this->loh);
    }
    function stream_eof()
    {
        return pg_lo_tell($this->loh) >= $this->size;
    }
    function stream_flush()
    {
        return true;
    }
    function stream_stat()
    {
        return array('size' => $this->size, 'ino' => $this->lon);
    }
    function stream_write($data)
    {
        return pg_lo_write($this->loh, $data);
    }
    function stream_close()
    {
        if (pg_lo_close($this->loh)) {
            return pg_query($this->dbh, 'COMMIT');
        } else {
            pg_query($this->dbh, 'ROLLBACK');
            return false;
        }
    }
}
stream_register_wrapper('pglob', 'PgLobStream');
Exemple #18
0
 /**
  * Register a stream.
  *
  * @return int
  */
 public static function registerStream(Stream $stream)
 {
     if (empty(static::$streams)) {
         stream_register_wrapper('filicious-streams', 'Filicious\\Stream\\StreamWrapper', STREAM_IS_URL);
     }
     static::$streams[++static::$streamIndex] = $stream;
     return static::$streamIndex;
 }
Exemple #19
0
 /**
  * Register this object as stream wrapper
  *
  * @param  string $name Protocol name
  */
 public function registerStreamWrapper($name = 'azure')
 {
     stream_register_wrapper($name, 'Blob_Stream');
     $this->registerAsClient($name);
 }
<?php

require_once 'Stream/SHM.php';
stream_register_wrapper('shm', 'Stream_SHM') or die("can't register shm");
$shm = fopen('shm://0xabcd', 'c');
fwrite($shm, "Current time is: " . time());
fclose($shm);
Exemple #21
0
 /**
  * Register the stream
  */
 public function register()
 {
     stream_register_wrapper(self::STREAM_NAME, __CLASS__);
 }
Exemple #22
0
        $this->rid = null;
    }
    /**
     * @access private
     */
    function _parseQuery($str)
    {
        $str = explode('&', $str);
        $new = array();
        foreach ($str as $k => $v) {
            list($kn, $vn) = explode('=', $v);
            if (preg_match('/^([a-zA-Z0-9_-]+)\\[([a-zA-Z0-9_-]+)\\]$/', $kn, $regs)) {
                $kn = $regs[1];
                $tn = 'r' . ucfirst(strtolower($regs[2]));
            } else {
                $tn = 'rEqual';
            }
            if (in_array($kn, array('limit', 'offset', 'orderBy', 'sort'))) {
                $new[$kn] = $vn;
            } else {
                $new[$kn] = new $tn($kn, $vn);
            }
        }
        return $new;
    }
}
if (PHP_VERSION >= '4.3.2') {
    stream_wrapper_register('rex', 'RexStreamer') or die('Failed to register protocol');
} else {
    stream_register_wrapper('rex', 'RexStreamer') or die('Failed to register protocol');
}
Exemple #23
0
 /**
  * Register this object as stream wrapper
  *
  * @param  string $name
  * @return Zend_Service_Amazon_S3
  */
 public function registerStreamWrapper($name = 's3')
 {
     stream_register_wrapper($name, 'Zend\\Service\\Amazon\\S3\\Stream');
     $this->registerAsClient($name);
 }
Exemple #24
0
 /**
  * Register stream handlers specified in the Teleport Config.
  *
  * @throws ConfigException If an error occurs attempting to register a
  * stream_handler configuration element.
  */
 protected function registerStreamHandlers()
 {
     $handlers = $this->getConfig()->get('stream_handlers', null, array());
     if (!is_array($handlers)) {
         throw new ConfigException('Invalid stream_handlers configuration', E_USER_ERROR);
     }
     $defaultStreamContext = array();
     foreach ($handlers as $protocol => $handler) {
         if (isset($handler['class'])) {
             try {
                 $flags = isset($handler['local']) ? !empty($handler['local']) : STREAM_IS_URL;
                 if (isset($handler['register_callback']) && is_callable($handler['register_callback'])) {
                     $registered = $handler['register_callback']($protocol, $handler);
                 } else {
                     if (in_array($protocol, stream_get_wrappers())) {
                         stream_wrapper_unregister($protocol);
                     }
                     $registered = stream_register_wrapper($protocol, $handler['class'], $flags);
                 }
                 if (isset($handler['options']) && is_array($handler['options'])) {
                     $defaultStreamContext[$protocol] = $handler['options'];
                 }
             } catch (\Exception $e) {
                 throw new ConfigException("Error registering stream_handler {$handler['class']} ({$protocol}://)", E_USER_ERROR, $e);
             }
             if (!$registered) {
                 throw new ConfigException("Could not register stream_handler {$handler['class']} ({$protocol}://)", E_USER_ERROR);
             }
         } else {
             throw new ConfigException("Invalid stream_handler configuration for protocol {$protocol}", E_USER_ERROR);
         }
     }
     $this->streamContext = stream_context_set_default($defaultStreamContext);
 }
Exemple #25
0
 /**
  * Static helper that registers the wrappers
  *
  * @access public, static
  * @return bool   true on success (even if SSL doesn't work)
  */
 function register()
 {
     // check that we have the required feature
     if (!function_exists("stream_register_wrapper")) {
         return false;
     }
     // try to register the non-encrypted WebDAV wrapper
     if (!stream_register_wrapper("webdav", "HTTP_WebDAV_Client_Stream")) {
         return false;
     }
     // now try to register the SSL protocol variant
     // it is not critical if this fails
     // TODO check whether SSL is possible with HTTP_Request
     stream_register_wrapper("webdavs", "HTTP_WebDAV_Client_Stream");
     return true;
 }
Exemple #26
0
 /**
  * 注册一个wrapper
  */
 private function __construct()
 {
     stream_register_wrapper('annotate', 'Cross\\Lib\\Other\\StringToPHPStream');
 }
Exemple #27
0
 /**
  * Register this object as stream wrapper
  *
  * @param  string $name Protocol name
  */
 public function registerStreamWrapper($name = 'azure')
 {
     stream_register_wrapper($name, 'Zend_Service_WindowsAzure_Storage_Blob_Stream');
     $this->registerAsClient($name);
 }
Exemple #28
0
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
 * HTTP::Download::PgLOB
 * 
 * PHP versions 4 and 5
 *
 * @category   HTTP
 * @package    HTTP_Download
 * @author     Michael Wallner <*****@*****.**>
 * @copyright  2003-2005 Michael Wallner
 * @license    BSD, revised
 * @version    CVS: $Id: PgLOB.php,v 1.14 2005/11/13 19:18:55 mike Exp $
 * @link       http://pear.php.net/package/HTTP_Download
 */
$GLOBALS['_HTTP_Download_PgLOB_Connection'] = null;
stream_register_wrapper('pglob', 'HTTP_Download_PgLOB');
/**
 * PgSQL large object stream interface for HTTP_Download
 * 
 * Usage:
 * <code>
 * require_once 'HTTP/Download.php';
 * require_once 'HTTP/Download/PgLOB.php';
 * $db = &DB::connect('pgsql://*****:*****@host/db');
 * // or $db = pg_connect(...);
 * $lo = HTTP_Download_PgLOB::open($db, 12345);
 * $dl = &new HTTP_Download;
 * $dl->setResource($lo);
 * $dl->send()
 * </code>
 * 
Exemple #29
0
 /**
  * Register this object as stream wrapper
  *
  * @param  string $name Protocol name
  */
 public function registerStreamWrapper($name = 'azure')
 {
     /**
      * @see Zend_Service_WindowsAzure_Storage_Blob_Stream
      */
     require_once 'Zend/Service/WindowsAzure/Storage/Blob/Stream.php';
     stream_register_wrapper($name, 'Zend_Service_WindowsAzure_Storage_Blob_Stream');
     $this->registerAsClient($name);
 }
require_once 'vendor/autoload.php';
use PHPWeekly\DataSource\ExternalDataSource;
use PHPWeekly\DataSource\HtmlDataSource;
use PHPWeekly\DataSource\LocalDataSource;
use PHPWeekly\Stream\RandomString;
// track execution time
$start = round(microtime(true) * 1000);
/**
 * Custom data sources (optional)
 *
 * Optionally register custom data sources to be used for random
 * string generations in the context stream
 *
 * The default local data source will be used if no custom data sources
 * have been registered
 */
RandomString::addDataSources(new ExternalDataSource('https://www.random.org//strings/?num=1&len=20&digits=on&upperalpha=on&loweralpha=on&unique=on&format=plain&rnd=new'), new ExternalDataSource('https://www.random.org//strings/?num=1&len=20&digits=on&upperalpha=on&loweralpha=on&unique=on&format=plain&rnd=new'), new ExternalDataSource('https://www.random.org//strings/?num=1&len=20&digits=on&upperalpha=on&loweralpha=on&unique=on&format=plain&rnd=new'), new ExternalDataSource('https://www.random.org//strings/?num=1&len=20&digits=on&upperalpha=on&loweralpha=on&unique=on&format=plain&rnd=new'), new ExternalDataSource('https://www.random.org//strings/?num=1&len=20&digits=on&upperalpha=on&loweralpha=on&unique=on&format=plain&rnd=new'), new HtmlDataSource('https://en.wikipedia.org/wiki/Cat'), new LocalDataSource());
// register stream context
stream_register_wrapper('random', RandomString::class);
$randomString = file_get_contents("random://100");
echo $randomString . PHP_EOL;
// outputs 100 random characters
$randomPointer = fopen("random://100", 'r');
echo fread($randomPointer, 50) . PHP_EOL;
// outputs 50 random characters
echo fread($randomPointer, 50) . PHP_EOL;
// outputs 50 random characters
echo fread($randomPointer, 1) . PHP_EOL;
// outputs empty string because max random characters of 100 was exceeded
echo sprintf('Total runtime: %s ms', round(microtime(true) * 1000) - $start) . PHP_EOL;
// output execution time (milliseconds)