1 | <?php |
||
11 | class AliyunOssAdapter extends BaseAdapter implements CanOverwriteFiles |
||
12 | { |
||
13 | /** |
||
14 | * @var AliyunOssConfig |
||
15 | */ |
||
16 | protected $ossConfig; |
||
17 | |||
18 | /** |
||
19 | * @param OssClient $ossClient |
||
20 | * @param AliyunOssConfig $ossConfig |
||
21 | */ |
||
22 | 1 | public function __construct(OssClient $ossClient, AliyunOssConfig $ossConfig) |
|
27 | |||
28 | /** |
||
29 | * {@inheritdoc} |
||
30 | */ |
||
31 | 6 | protected function getOptionsFromConfig(Config $config) |
|
42 | |||
43 | /** |
||
44 | * Used by \Illuminate\Filesystem\FilesystemAdapter::url |
||
45 | * Get the URL for the file at the given path. |
||
46 | * |
||
47 | * @param string $path |
||
48 | * @return string |
||
49 | */ |
||
50 | 3 | public function getUrl($path) |
|
54 | |||
55 | /** |
||
56 | * Used by \Illuminate\Filesystem\FilesystemAdapter::temporaryUrl |
||
57 | * Get a temporary URL for the file at the given path. |
||
58 | * |
||
59 | * @param string $path |
||
60 | * @param \DateTimeInterface $expiration |
||
61 | * @param array $options |
||
62 | * @return string |
||
63 | * |
||
64 | * @throws \RuntimeException |
||
65 | */ |
||
66 | 2 | public function getTemporaryUrl($path, $expiration, array $options = []) |
|
79 | } |
||
80 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.