1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace BristolSU\AirTable; |
4
|
|
|
|
5
|
|
|
use BristolSU\AirTable\Control\AirtableHandler as ControlAirTableHandler; |
6
|
|
|
use BristolSU\AirTable\Progress\AirtableHandler as ProgressAirTableHandler; |
7
|
|
|
use BristolSU\ControlDB\Export\Exporter; |
8
|
|
|
use BristolSU\ControlDB\Export\ExportManager; |
9
|
|
|
use BristolSU\Support\Progress\ProgressExport; |
10
|
|
|
use Illuminate\Support\ServiceProvider; |
11
|
|
|
|
12
|
|
|
class AirTableServiceProvider extends ServiceProvider |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
public function boot() |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
ProgressExport::extend('airtable', function($container, $config) { |
|
|
|
|
18
|
|
|
$missingKey = null; |
19
|
|
|
if(!array_key_exists('apiKey', $config)) { |
|
|
|
|
20
|
|
|
$missingKey = 'apiKey'; |
21
|
|
|
} |
22
|
|
|
if(!array_key_exists('tableName', $config)) { |
|
|
|
|
23
|
|
|
$missingKey = 'tableName'; |
24
|
|
|
} |
25
|
|
|
if(!array_key_exists('baseId', $config)) { |
|
|
|
|
26
|
|
|
$missingKey = 'baseId'; |
27
|
|
|
} |
28
|
|
|
if($missingKey !== null) { |
|
|
|
|
29
|
|
|
throw new \Exception(sprintf('The [%s] field must be given', $missingKey)); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
return new ProgressAirTableHandler( |
33
|
|
|
$config['baseId'], |
34
|
|
|
$config['tableName'], |
35
|
|
|
$config['apiKey'], |
36
|
|
|
(array_key_exists('debug', $config) ? (bool) $config['debug'] : false) |
37
|
|
|
); |
38
|
|
|
}); |
|
|
|
|
39
|
|
|
|
40
|
|
|
Exporter::extend('airtable', function($container, $config) { |
|
|
|
|
41
|
|
|
$missingKey = null; |
42
|
|
|
if(!array_key_exists('apiKey', $config)) { |
|
|
|
|
43
|
|
|
$missingKey = 'apiKey'; |
44
|
|
|
} |
45
|
|
|
if(!array_key_exists('tableName', $config)) { |
|
|
|
|
46
|
|
|
$missingKey = 'tableName'; |
47
|
|
|
} |
48
|
|
|
if(!array_key_exists('baseId', $config)) { |
|
|
|
|
49
|
|
|
$missingKey = 'baseId'; |
50
|
|
|
} |
51
|
|
|
if($missingKey !== null) { |
|
|
|
|
52
|
|
|
throw new \Exception(sprintf('The [%s] field must be given', $missingKey)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return new ControlAirTableHandler($config); |
56
|
|
|
}); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
} |