medz/stream-wrapper-interface

Common interface for streamWrapper class.

v1.0.1 2016-09-04 09:19 UTC

This package is auto-updated.

Last update: 2022-06-12 02:26:29 UTC


README

This repository holds all interfaces defined by streamWrapper.

An instance of this class is initialized as soon as a stream function tries to access the protocol it is associated with.

⚠️Note: This is NOT a real class, only a prototype of how a class defining its own protocol should be.

关于 - 中文

这个包实现了streamWrapper中所要求的所有接口

这个接口类的实例将可以注册后使用流的形势访问。

⚠️️注意: 这个包的class不是一个实例,而是一个可以规范实例需要完成的方法的接口类。

Composer

composer require medz/stream-wrapper-interface

Demo

use Medz\Component\WrapperInterface\WrapperInterface

class DemoStream implements WrapperInterface
{
    /**
     * Enter description here...
     *
     * @param string $path
     * @param string $mode
     * @param int    $options
     * @param string &$opened_path
     *
     * @return bool
     */
    public function stream_open($path, $mode, $options, &$opened_path)
    {
        // TODO
    }
}

Register this object as stream wrapper. 注册这个streamWrapper.

stream_register_wrapper('demo', 'DemoStream');

use the wrapper client. 使用这个注册的自定义流协议。

// get
file_get_contents('demo://test.txt');

// put
file_put_contents('demo://test.txt', 'This is a test content.');

Use vendor package. 使用第三方包

(symfony/finder):

use Symfony\Component\Finder\Finder;

$finder = new Finder();
$finder->files()->in('demo://src');

foreach ($finder as $file)
{
    var_dump($file);
}

Use the package for Aliyun OSS SDK. 使用这个接口的阿里云sdk。

medz/oss-stream-wrapper alias medz/aliyun-oss

License:

MIT