OpenXE/classes/Modules/TaxdooApi/Bootstrap.php

45 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2021-05-21 08:49:41 +02:00
<?php
namespace Xentral\Modules\TaxdooApi;
use Xentral\Core\DependencyInjection\ContainerInterface;
use Xentral\Modules\TaxdooApi\Exception\ConfigurationMissingException;
use Xentral\Modules\TaxdooApi\Exception\KeyNotFoundException;
final class Bootstrap
{
/**
* @return array
*/
public static function registerServices()
{
return [
'TaxdooApiService' => 'onInitTaxdooApiService',
];
}
/**
* @param ContainerInterface $container
*
* @throws KeyNotFoundException|ConfigurationMissingException
*
* @return TaxdooApiService
*/
public static function onInitTaxdooApiService(ContainerInterface $container)
{
$app = $container->get('LegacyApplication');
$token = $app->erp->GetKonfiguration('taxdoo_token');
if ($token === '') {
throw new KeyNotFoundException();
}
$land = $app->erp->GetKonfiguration('taxdoo_land');
if (strlen($land) !== 2) {
throw new ConfigurationMissingException('Land muss ISO-2 sein');
}
return new TaxdooApiService($token);
}
}