sebastianfeldmann /
phpbu
| 1 | <?php |
||
| 2 | |||
| 3 | namespace phpbu\App\Backup\File; |
||
| 4 | |||
| 5 | use Arhitector\Yandex\Disk; |
||
| 6 | use Arhitector\Yandex\Disk\Resource\Closed; |
||
| 7 | use InvalidArgumentException; |
||
| 8 | use phpbu\App\Exception; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * YandexDisk class. |
||
| 12 | * |
||
| 13 | * @package phpbu |
||
| 14 | * @subpackage Backup |
||
| 15 | * @author Sebastian Feldmann <[email protected]> |
||
| 16 | * @author Alexander Palchikov AxelPAL <[email protected]> |
||
| 17 | * @copyright Sebastian Feldmann <[email protected]> |
||
| 18 | * @license https://opensource.org/licenses/MIT The MIT License (MIT) |
||
| 19 | * @link http://phpbu.de/ |
||
| 20 | */ |
||
| 21 | class YandexDisk extends Remote |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * YandexDisk api client. |
||
| 25 | * |
||
| 26 | * @var Disk |
||
| 27 | */ |
||
| 28 | protected $disk; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * YandexDisk constructor. |
||
| 32 | * |
||
| 33 | * @param Disk $disk |
||
| 34 | * @param Closed $yandexFile |
||
| 35 | */ |
||
| 36 | 4 | public function __construct(Disk $disk, Closed $yandexFile) |
|
| 37 | { |
||
| 38 | 4 | $this->disk = $disk; |
|
| 39 | 4 | $this->filename = $yandexFile->get('name'); |
|
| 40 | 4 | $this->pathname = $yandexFile->get('path'); |
|
| 41 | 4 | $this->size = $yandexFile->get('size'); |
|
| 42 | 4 | $this->lastModified = strtotime($yandexFile->get('modified')); |
|
| 43 | 4 | } |
|
| 44 | |||
| 45 | /** |
||
| 46 | * Deletes the file on YandexDisk. |
||
| 47 | * |
||
| 48 | * @throws Exception |
||
| 49 | */ |
||
| 50 | 1 | public function unlink() |
|
| 51 | { |
||
| 52 | try { |
||
| 53 | 1 | $item = $this->disk->getResource($this->pathname); |
|
| 54 | 1 | $item->delete($this->pathname); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 55 | 1 | } catch (InvalidArgumentException $e) { |
|
| 56 | 1 | throw new Exception($e->getMessage()); |
|
| 57 | } |
||
| 58 | } |
||
| 59 | } |
||
| 60 |