<?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)
{
echo '我是七牛云OSS驱动正在存储内容:' . $content;
}
}
class AliYunOssDriver implements IDriver
{
public function write(string $content)
{
echo '我是阿里云OSS驱动正在存储内容:' . $content;
}
}
$ossDriver = new QiNiuOssDriver();
$storage = new Storage($ossDriver);
$storage->write('Hello, World!');