| Conditions | 7 |
| Paths | 4 |
| Total Lines | 22 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | public function __invoke(ContainerInterface $container): TokenManager |
||
| 13 | { |
||
| 14 | $config = $container->get('config')['token_manager'] ?? null; |
||
| 15 | if ($config === null) { |
||
| 16 | throw new ConfigException("['token_manager'] config key is missing."); |
||
| 17 | } |
||
| 18 | if (mb_strlen($config['private_key'] ?: '') < 32) { |
||
| 19 | throw new ConfigException("['tokenManager']['private_key'] config key is must be at least 32 chars long."); |
||
| 20 | } |
||
| 21 | |||
| 22 | if (isset($config['default_expiry']) && ( |
||
| 23 | !is_numeric($config['default_expiry']) || $config['default_expiry'] < 0 |
||
| 24 | )) { |
||
| 25 | throw new ConfigException("['tokenManager']['default_expiry'] must be numeric > 0"); |
||
| 26 | } |
||
| 27 | |||
| 28 | $defaultExpiry = $config['default_expiry'] ?? TokenManager::DEFAULT_EXPIRY; |
||
| 29 | |||
| 30 | $issuer = $config['default_issuer'] ?? $this->getDefaultIssuer(); |
||
| 31 | $audience = $config['default_audience'] ?? $this->getDefaultIssuer(); |
||
| 32 | |||
| 33 | return new TokenManager($config['private_key'], $defaultExpiry, $issuer, $audience); |
||
| 34 | } |
||
| 41 |