1 | <?php |
||
18 | class Ma27ApiKeyAuthenticationExtension extends Extension |
||
19 | { |
||
20 | /** |
||
21 | * {@inheritdoc} |
||
22 | */ |
||
23 | 6 | public function load(array $configs, ContainerBuilder $container) |
|
24 | { |
||
25 | 6 | $configuration = new Configuration(); |
|
26 | 6 | $config = $this->processConfiguration($configuration, $configs); |
|
27 | |||
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 | intval(floor($config['user']['api_key_length'] / 2)) |
|
33 | 6 | ); |
|
34 | |||
35 | 6 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
36 | 6 | $this->loadPassword($container, $config['user']['password']); |
|
37 | 6 | $this->loadServices($loader); |
|
38 | 6 | $this->loadApiKeyPurger($container, $loader, $config['api_key_purge']); |
|
39 | 6 | $this->overrideServices($container, $config['services']); |
|
40 | 6 | } |
|
41 | |||
42 | /** |
||
43 | * Loads the password strategy. |
||
44 | * |
||
45 | * @param ContainerBuilder $container |
||
46 | * @param string $passwordConfig |
||
47 | */ |
||
48 | 6 | private function loadPassword(ContainerBuilder $container, $passwordConfig) |
|
49 | { |
||
50 | 6 | $strategyArguments = array(); |
|
51 | 6 | switch ($passwordConfig['strategy']) { |
|
52 | 6 | case 'php55': |
|
53 | 1 | $className = 'Ma27\\ApiKeyAuthenticationBundle\\Model\\Password\\PhpPasswordHasher'; |
|
54 | |||
55 | 1 | break; |
|
56 | 5 | case 'crypt': |
|
57 | 2 | $className = 'Ma27\\ApiKeyAuthenticationBundle\\Model\\Password\\CryptPasswordHasher'; |
|
58 | |||
59 | 2 | break; |
|
60 | 3 | case 'sha512': |
|
61 | 2 | $className = 'Ma27\\ApiKeyAuthenticationBundle\\Model\\Password\\Sha512PasswordHasher'; |
|
62 | |||
63 | 2 | break; |
|
64 | 1 | case 'phpass': |
|
65 | 1 | $className = 'Ma27\\ApiKeyAuthenticationBundle\\Model\\Password\\PHPassHasher'; |
|
66 | 1 | $strategyArguments[] = $passwordConfig['phpass_iteration_length']; |
|
67 | |||
68 | 1 | break; |
|
69 | default: |
||
70 | throw new InvalidConfigurationException('Cannot create password config!'); |
||
71 | 6 | } |
|
72 | |||
73 | 6 | $container->setDefinition( |
|
74 | 6 | 'ma27_api_key_authentication.password.strategy', |
|
75 | 6 | new Definition($className, $strategyArguments) |
|
76 | 6 | ); |
|
77 | 6 | } |
|
78 | |||
79 | /** |
||
80 | * Loads all internal services. |
||
81 | * |
||
82 | * @param Loader\YamlFileLoader $loader |
||
83 | */ |
||
84 | 6 | private function loadServices(Loader\YamlFileLoader $loader) |
|
90 | |||
91 | /** |
||
92 | * Loads the purger job command into the container. |
||
93 | * |
||
94 | * @param ContainerBuilder $container |
||
95 | * @param Loader\YamlFileLoader $loader |
||
96 | * @param string[] $purgerConfig |
||
97 | */ |
||
98 | 6 | private function loadApiKeyPurger(ContainerBuilder $container, Loader\YamlFileLoader $loader, array $purgerConfig) |
|
111 | |||
112 | /** |
||
113 | * Processes the service override configuration into the container. |
||
114 | * |
||
115 | * @param ContainerBuilder $container |
||
116 | * @param array $services |
||
117 | */ |
||
118 | 6 | private function overrideServices(ContainerBuilder $container, array $services) |
|
140 | } |
||
141 |