1 | <?php |
||
25 | abstract class AbstractFactory implements ProviderFactoryInterface |
||
26 | { |
||
27 | protected static $dependencies = []; |
||
28 | |||
29 | abstract protected function getProvider(array $config): Provider; |
||
30 | |||
31 | /** |
||
32 | * {@inheritdoc} |
||
33 | */ |
||
34 | 27 | public function createProvider(array $options = []): Provider |
|
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | 27 | public static function validate(array $options, $providerName) |
|
49 | { |
||
50 | 27 | static::verifyDependencies(); |
|
51 | |||
52 | 27 | $resolver = new OptionsResolver(); |
|
53 | 27 | static::configureOptionResolver($resolver); |
|
54 | |||
55 | try { |
||
56 | 27 | $resolver->resolve($options); |
|
57 | } catch (\Exception $e) { |
||
58 | $message = sprintf( |
||
59 | 'Error while configure provider "%s". Verify your configuration at "bazinga_geocoder.providers.%s.options". %s', |
||
60 | $providerName, |
||
61 | $providerName, |
||
62 | $e->getMessage() |
||
63 | ); |
||
64 | |||
65 | throw new InvalidConfigurationException($message, $e->getCode(), $e); |
||
66 | } |
||
67 | 27 | } |
|
68 | |||
69 | /** |
||
70 | * Make sure that we have the required class and throw and exception if we don't. |
||
71 | * |
||
72 | * @throws \LogicException |
||
73 | */ |
||
74 | 27 | protected static function verifyDependencies() |
|
88 | |||
89 | /** |
||
90 | * By default we do not have any options to configure. A factory should override this function and confgure |
||
91 | * the options resolver. |
||
92 | */ |
||
93 | 1 | protected static function configureOptionResolver(OptionsResolver $resolver) |
|
96 | } |
||
97 |