1 | <?php |
||
17 | class Ma27ApiKeyAuthenticationExtension extends Extension |
||
18 | { |
||
19 | /** |
||
20 | * {@inheritdoc} |
||
21 | */ |
||
22 | 6 | public function load(array $configs, ContainerBuilder $container) |
|
23 | { |
||
24 | 6 | $configuration = new Configuration(); |
|
25 | 6 | $config = $this->processConfiguration($configuration, $configs); |
|
26 | |||
27 | 6 | $container->setParameter('ma27_api_key_authentication.key_header', $config['key_header']); |
|
28 | 6 | $container->setParameter('ma27_api_key_authentication.model_name', $config['user']['model_name']); |
|
29 | 6 | $container->setParameter('ma27_api_key_authentication.object_manager', $config['user']['object_manager']); |
|
30 | 6 | $container->setParameter( |
|
31 | 6 | 'ma27_api_key_authentication.property.apiKeyLength', |
|
32 | 6 | (int) floor($config['user']['api_key_length'] / 2) // TODO to be moved to the `KeyFactory` |
|
33 | 6 | ); |
|
34 | |||
35 | 6 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
36 | 6 | $this->loadPassword($container, $config['user']['password'], $loader); |
|
37 | 6 | $this->loadServices($loader); |
|
38 | 6 | $this->loadApiKeyPurger($container, $loader, $config['api_key_purge']); |
|
39 | 6 | $this->overrideServices($container, $config['services']); |
|
40 | |||
41 | 6 | $container->setParameter('ma27_api_key_authentication.response_values', $config['response']); |
|
42 | 6 | } |
|
43 | |||
44 | /** |
||
45 | * Loads the password strategy. |
||
46 | * |
||
47 | * @param ContainerBuilder $container |
||
48 | * @param string $passwordConfig |
||
49 | * @param Loader\YamlFileLoader $loader |
||
50 | */ |
||
51 | 6 | private function loadPassword(ContainerBuilder $container, $passwordConfig, Loader\YamlFileLoader $loader) |
|
52 | { |
||
53 | // TODO refactor this, the `phpass_iteration_length` is specific for a single strategy and therefore it shouldn't be present in the semantic configuration. |
||
54 | 6 | $container->setParameter( |
|
55 | 6 | 'ma27_api_key_authentication.password_hasher.phpass.iteration_length', |
|
56 | 6 | isset($passwordConfig['phpass_iteration_length']) ? $passwordConfig['phpass_iteration_length'] : 8 |
|
57 | 6 | ); |
|
58 | 6 | $loader->load('hashers.yml'); |
|
59 | |||
60 | 6 | $container->setParameter( |
|
61 | 6 | 'ma27_api_key_authentication.password_hashing_service', |
|
62 | 6 | $passwordConfig['strategy'] |
|
63 | 6 | ); |
|
64 | 6 | } |
|
65 | |||
66 | /** |
||
67 | * Loads all internal services. |
||
68 | * |
||
69 | * @param Loader\YamlFileLoader $loader |
||
70 | */ |
||
71 | 6 | private function loadServices(Loader\YamlFileLoader $loader) |
|
77 | |||
78 | /** |
||
79 | * Loads the purger job command into the container. |
||
80 | * |
||
81 | * @param ContainerBuilder $container |
||
82 | * @param Loader\YamlFileLoader $loader |
||
83 | * @param string[] $purgerConfig |
||
84 | */ |
||
85 | 6 | private function loadApiKeyPurger(ContainerBuilder $container, Loader\YamlFileLoader $loader, array $purgerConfig) |
|
106 | |||
107 | /** |
||
108 | * Processes the service override configuration into the container. |
||
109 | * |
||
110 | * @param ContainerBuilder $container |
||
111 | * @param array $services |
||
112 | */ |
||
113 | 6 | private function overrideServices(ContainerBuilder $container, array $services) |
|
139 | } |
||
140 |
If you suppress an error, we recommend checking for the error condition explicitly: