1 | <?php |
||
12 | abstract class AbstractGetFileEntryPoint extends AbstractEntryPoint { |
||
13 | |||
14 | /** |
||
15 | * The directory in which to download the File |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $downloadDir = null; |
||
19 | |||
20 | 1 | public function __construct($url, array $options = array()){ |
|
21 | 1 | $this->setRequest(new GETFile()); |
|
22 | 1 | $this->setResponse(new FileResponse($this->Request->getCurlObject())); |
|
23 | 1 | parent::__construct($url, $options); |
|
24 | 1 | } |
|
25 | |||
26 | 1 | public function configureResponse(){ |
|
27 | 1 | $this->Response->setDestinationPath($this->downloadDir); |
|
|
|||
28 | 1 | parent::configureResponse(); |
|
29 | 1 | } |
|
30 | |||
31 | /** |
||
32 | * Set the download directory for the File the EntryPoint is retrieving |
||
33 | * @param $path |
||
34 | * @return $this |
||
35 | */ |
||
36 | 1 | public function downloadTo($path){ |
|
40 | |||
41 | /** |
||
42 | * Get the download directory for the File the EntryPoint is retrieving |
||
43 | * @return string |
||
44 | */ |
||
45 | 1 | public function getDownloadDir(){ |
|
48 | |||
49 | } |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: