firefly-iii /
csv-importer
| 1 | <?php |
||
| 2 | declare(strict_types=1); |
||
| 3 | /** |
||
| 4 | * HaveAccess.php |
||
| 5 | * Copyright (c) 2020 [email protected] |
||
| 6 | * |
||
| 7 | * This file is part of the Firefly III CSV importer |
||
| 8 | * (https://github.com/firefly-iii/csv-importer). |
||
| 9 | * |
||
| 10 | * This program is free software: you can redistribute it and/or modify |
||
| 11 | * it under the terms of the GNU Affero General Public License as |
||
| 12 | * published by the Free Software Foundation, either version 3 of the |
||
| 13 | * License, or (at your option) any later version. |
||
| 14 | * |
||
| 15 | * This program is distributed in the hope that it will be useful, |
||
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 18 | * GNU Affero General Public License for more details. |
||
| 19 | * |
||
| 20 | * You should have received a copy of the GNU Affero General Public License |
||
| 21 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
| 22 | */ |
||
| 23 | |||
| 24 | namespace App\Console; |
||
| 25 | |||
| 26 | use GrumpyDictator\FFIIIApiSupport\Exceptions\ApiHttpException; |
||
| 27 | use GrumpyDictator\FFIIIApiSupport\Request\SystemInformationRequest; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Trait HaveAccess |
||
| 31 | */ |
||
| 32 | trait HaveAccess |
||
| 33 | { |
||
| 34 | /** |
||
| 35 | * @return bool |
||
| 36 | */ |
||
| 37 | private function haveAccess(): bool |
||
| 38 | { |
||
| 39 | $uri = (string)config('csv_importer.uri'); |
||
| 40 | $token = (string)config('csv_importer.access_token'); |
||
| 41 | $request = new SystemInformationRequest($uri, $token); |
||
| 42 | try { |
||
| 43 | $request->get(); |
||
| 44 | } catch (ApiHttpException $e) { |
||
| 45 | $this->error(sprintf('Could not connect to Firefly III: %s', $e->getMessage())); |
||
| 46 | |||
| 47 | return false; |
||
| 48 | } |
||
| 49 | |||
| 50 | return true; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param $string |
||
| 55 | * @param null $verbosity |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 56 | * |
||
| 57 | * @return void |
||
| 58 | */ |
||
| 59 | abstract public function error($string, $verbosity = null); |
||
| 60 | } |
||
| 61 |