编辑代码

<?php

interface IDriver
{
    public function write(string $content);
}

class Storage
{
    protected IDriver $driver;

    public function __construct(IDriver $driver)
    {
        $this->driver = $driver;
    }

    public function write(string $content)
    {
        $this->driver->write($content);
    }
}

class QiNiuOssDriver implements IDriver
{
    public function write(string $content)
    {
        // 实现上传到七牛云OSS的功能
        echo '我是七牛云OSS驱动正在存储内容:' . $content;
    }
}

class AliYunOssDriver implements IDriver
{
    public function write(string $content)
    {
        // 实现上传到阿里云OSS的功能
        echo '我是阿里云OSS驱动正在存储内容:' . $content;
    }
}

$ossDriver = new QiNiuOssDriver();
$storage = new Storage($ossDriver);
$storage->write('Hello, World!');