@@ -10,10 +10,10 @@ |
||
| 10 | 10 | interface ServiceInstanceInterface |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** @return string */ |
|
| 14 | - public function getServiceName(); |
|
| 13 | + /** @return string */ |
|
| 14 | + public function getServiceName(); |
|
| 15 | 15 | |
| 16 | - /** @return mixed */ |
|
| 17 | - public function getInstance(); |
|
| 16 | + /** @return mixed */ |
|
| 17 | + public function getInstance(); |
|
| 18 | 18 | |
| 19 | 19 | } |
@@ -10,16 +10,16 @@ |
||
| 10 | 10 | interface ServiceDefinitionInterface |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** @return string */ |
|
| 14 | - public function getServiceName(); |
|
| 13 | + /** @return string */ |
|
| 14 | + public function getServiceName(); |
|
| 15 | 15 | |
| 16 | - /** @return string */ |
|
| 17 | - public function getClass(); |
|
| 16 | + /** @return string */ |
|
| 17 | + public function getClass(); |
|
| 18 | 18 | |
| 19 | - /** @return array */ |
|
| 20 | - public function getConstructArgs(); |
|
| 19 | + /** @return array */ |
|
| 20 | + public function getConstructArgs(); |
|
| 21 | 21 | |
| 22 | - /** @return array */ |
|
| 23 | - public function getCalls(); |
|
| 22 | + /** @return array */ |
|
| 23 | + public function getCalls(); |
|
| 24 | 24 | |
| 25 | 25 | } |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | declare( strict_types = 1 ); |
| 3 | 3 | |
| 4 | 4 | if ( PHP_SAPI !== 'cli' ) { |
| 5 | - die( 'Not an entry point' ); |
|
| 5 | + die( 'Not an entry point' ); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | error_reporting( -1 ); |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | ini_set( 'display_errors', '1' ); |
| 11 | 11 | |
| 12 | 12 | if ( !is_readable( __DIR__ . '/../vendor/autoload.php' ) ) { |
| 13 | - die( 'You need to install this package with Composer before you can run the tests' ); |
|
| 13 | + die( 'You need to install this package with Composer before you can run the tests' ); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | require_once __DIR__ . '/../vendor/autoload.php'; |
@@ -1,16 +1,16 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare( strict_types = 1 ); |
|
| 2 | +declare(strict_types=1); |
|
| 3 | 3 | |
| 4 | -if ( PHP_SAPI !== 'cli' ) { |
|
| 5 | - die( 'Not an entry point' ); |
|
| 4 | +if (PHP_SAPI !== 'cli') { |
|
| 5 | + die('Not an entry point'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | error_reporting( -1 ); |
| 9 | 9 | |
| 10 | -ini_set( 'display_errors', '1' ); |
|
| 10 | +ini_set('display_errors', '1'); |
|
| 11 | 11 | |
| 12 | -if ( !is_readable( __DIR__ . '/../vendor/autoload.php' ) ) { |
|
| 13 | - die( 'You need to install this package with Composer before you can run the tests' ); |
|
| 12 | +if (!is_readable(__DIR__ . '/../vendor/autoload.php')) { |
|
| 13 | + die('You need to install this package with Composer before you can run the tests'); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | require_once __DIR__ . '/../vendor/autoload.php'; |
@@ -9,62 +9,62 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class ServiceDefinition implements ServiceDefinitionInterface |
| 11 | 11 | { |
| 12 | - /** @var string */ |
|
| 13 | - private $serviceName; |
|
| 12 | + /** @var string */ |
|
| 13 | + private $serviceName; |
|
| 14 | 14 | |
| 15 | - /** @var string */ |
|
| 16 | - private $class; |
|
| 15 | + /** @var string */ |
|
| 16 | + private $class; |
|
| 17 | 17 | |
| 18 | - /** @var array */ |
|
| 19 | - private $constructArgs; |
|
| 18 | + /** @var array */ |
|
| 19 | + private $constructArgs; |
|
| 20 | 20 | |
| 21 | - /** @var array */ |
|
| 22 | - private $calls; |
|
| 21 | + /** @var array */ |
|
| 22 | + private $calls; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * RepositoryFactory constructor. |
|
| 26 | - * |
|
| 27 | - * @param string $serviceName |
|
| 28 | - * @param string $class |
|
| 29 | - * @param array $args |
|
| 30 | - * @param array $calls |
|
| 31 | - */ |
|
| 32 | - public function __construct(string $serviceName, string $class, array $args = [], array $calls = []) |
|
| 33 | - { |
|
| 34 | - $this->serviceName = $serviceName; |
|
| 35 | - $this->class = $class; |
|
| 36 | - $this->constructArgs = $args; |
|
| 37 | - $this->calls = $calls; |
|
| 38 | - } |
|
| 24 | + /** |
|
| 25 | + * RepositoryFactory constructor. |
|
| 26 | + * |
|
| 27 | + * @param string $serviceName |
|
| 28 | + * @param string $class |
|
| 29 | + * @param array $args |
|
| 30 | + * @param array $calls |
|
| 31 | + */ |
|
| 32 | + public function __construct(string $serviceName, string $class, array $args = [], array $calls = []) |
|
| 33 | + { |
|
| 34 | + $this->serviceName = $serviceName; |
|
| 35 | + $this->class = $class; |
|
| 36 | + $this->constructArgs = $args; |
|
| 37 | + $this->calls = $calls; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @return string |
|
| 42 | - */ |
|
| 43 | - public function getClass() |
|
| 44 | - { |
|
| 45 | - return $this->class; |
|
| 46 | - } |
|
| 40 | + /** |
|
| 41 | + * @return string |
|
| 42 | + */ |
|
| 43 | + public function getClass() |
|
| 44 | + { |
|
| 45 | + return $this->class; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** @return string */ |
|
| 49 | - public function getServiceName() |
|
| 50 | - { |
|
| 51 | - return $this->serviceName; |
|
| 52 | - } |
|
| 48 | + /** @return string */ |
|
| 49 | + public function getServiceName() |
|
| 50 | + { |
|
| 51 | + return $this->serviceName; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return array |
|
| 56 | - */ |
|
| 57 | - public function getConstructArgs() |
|
| 58 | - { |
|
| 59 | - return $this->constructArgs; |
|
| 60 | - } |
|
| 54 | + /** |
|
| 55 | + * @return array |
|
| 56 | + */ |
|
| 57 | + public function getConstructArgs() |
|
| 58 | + { |
|
| 59 | + return $this->constructArgs; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @return array |
|
| 64 | - */ |
|
| 65 | - public function getCalls() |
|
| 66 | - { |
|
| 67 | - return $this->calls; |
|
| 68 | - } |
|
| 62 | + /** |
|
| 63 | + * @return array |
|
| 64 | + */ |
|
| 65 | + public function getCalls() |
|
| 66 | + { |
|
| 67 | + return $this->calls; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | 70 | } |
@@ -9,8 +9,8 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | final class Fields |
| 11 | 11 | { |
| 12 | - const ROOT_CONFIG_NAME = 'services'; |
|
| 13 | - const CLASS_CONFIG_NAME = 'class'; |
|
| 14 | - const CONSTRUCTOR_PARAMS_CONFIG_NAME = 'arguments'; |
|
| 15 | - const METHOD_CALLS_CONFIG_NAME = 'calls'; |
|
| 12 | + const ROOT_CONFIG_NAME = 'services'; |
|
| 13 | + const CLASS_CONFIG_NAME = 'class'; |
|
| 14 | + const CONSTRUCTOR_PARAMS_CONFIG_NAME = 'arguments'; |
|
| 15 | + const METHOD_CALLS_CONFIG_NAME = 'calls'; |
|
| 16 | 16 | } |
@@ -14,53 +14,53 @@ |
||
| 14 | 14 | class YamlParser implements ParserInterface |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @param string $filePath |
|
| 19 | - * @return array |
|
| 20 | - * @throws ResourceNotFoundException |
|
| 21 | - * @throws InvalidResourceException |
|
| 22 | - */ |
|
| 23 | - public function loadFile(string $filePath): array |
|
| 24 | - { |
|
| 25 | - if (false === file_exists($filePath)) { |
|
| 26 | - throw new ResourceNotFoundException('The file "' . $filePath . '" does not exists'); |
|
| 27 | - } |
|
| 17 | + /** |
|
| 18 | + * @param string $filePath |
|
| 19 | + * @return array |
|
| 20 | + * @throws ResourceNotFoundException |
|
| 21 | + * @throws InvalidResourceException |
|
| 22 | + */ |
|
| 23 | + public function loadFile(string $filePath): array |
|
| 24 | + { |
|
| 25 | + if (false === file_exists($filePath)) { |
|
| 26 | + throw new ResourceNotFoundException('The file "' . $filePath . '" does not exists'); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - if (false === is_file($filePath)) { |
|
| 30 | - throw new InvalidResourceException('The resource "' . $filePath . '" is not a file'); |
|
| 31 | - } |
|
| 29 | + if (false === is_file($filePath)) { |
|
| 30 | + throw new InvalidResourceException('The resource "' . $filePath . '" is not a file'); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - $parse = Yaml::parseFile($filePath); |
|
| 33 | + $parse = Yaml::parseFile($filePath); |
|
| 34 | 34 | |
| 35 | - return null === $parse ? [] : $parse; |
|
| 36 | - } |
|
| 35 | + return null === $parse ? [] : $parse; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @param string $directorPath |
|
| 40 | - * @return array |
|
| 41 | - * @throws InvalidResourceException |
|
| 42 | - * @throws ResourceNotFoundException |
|
| 43 | - */ |
|
| 44 | - public function loadDirectory(string $directorPath): array |
|
| 45 | - { |
|
| 46 | - if (false === file_exists($directorPath)) { |
|
| 47 | - throw new ResourceNotFoundException('The directory "' . $directorPath . '" does not exists'); |
|
| 48 | - } |
|
| 38 | + /** |
|
| 39 | + * @param string $directorPath |
|
| 40 | + * @return array |
|
| 41 | + * @throws InvalidResourceException |
|
| 42 | + * @throws ResourceNotFoundException |
|
| 43 | + */ |
|
| 44 | + public function loadDirectory(string $directorPath): array |
|
| 45 | + { |
|
| 46 | + if (false === file_exists($directorPath)) { |
|
| 47 | + throw new ResourceNotFoundException('The directory "' . $directorPath . '" does not exists'); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - if (false === is_dir($directorPath)) { |
|
| 51 | - throw new InvalidResourceException('The resource "' . $directorPath . '" is not a directory'); |
|
| 52 | - } |
|
| 50 | + if (false === is_dir($directorPath)) { |
|
| 51 | + throw new InvalidResourceException('The resource "' . $directorPath . '" is not a directory'); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - $config = []; |
|
| 54 | + $config = []; |
|
| 55 | 55 | |
| 56 | - $files = array_diff(scandir($directorPath), array('.', '..')); |
|
| 57 | - foreach ($files as $file) { |
|
| 58 | - if (false !== preg_match('/^.+(yml|yaml)$/i', $file)) { |
|
| 59 | - $config[$file] = Yaml::parseFile(realpath($directorPath) . DIRECTORY_SEPARATOR . $file); |
|
| 60 | - } |
|
| 61 | - } |
|
| 56 | + $files = array_diff(scandir($directorPath), array('.', '..')); |
|
| 57 | + foreach ($files as $file) { |
|
| 58 | + if (false !== preg_match('/^.+(yml|yaml)$/i', $file)) { |
|
| 59 | + $config[$file] = Yaml::parseFile(realpath($directorPath) . DIRECTORY_SEPARATOR . $file); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return $config; |
|
| 64 | - } |
|
| 63 | + return $config; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | } |
@@ -10,16 +10,16 @@ |
||
| 10 | 10 | interface ParserInterface |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @param string $filePath |
|
| 15 | - * @return array |
|
| 16 | - */ |
|
| 17 | - public function loadFile(string $filePath): array; |
|
| 13 | + /** |
|
| 14 | + * @param string $filePath |
|
| 15 | + * @return array |
|
| 16 | + */ |
|
| 17 | + public function loadFile(string $filePath): array; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @param string $directorPath |
|
| 21 | - * @return array |
|
| 22 | - */ |
|
| 23 | - public function loadDirectory(string $directorPath): array; |
|
| 19 | + /** |
|
| 20 | + * @param string $directorPath |
|
| 21 | + * @return array |
|
| 22 | + */ |
|
| 23 | + public function loadDirectory(string $directorPath): array; |
|
| 24 | 24 | |
| 25 | 25 | } |
@@ -15,122 +15,122 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class ServiceLoader |
| 17 | 17 | { |
| 18 | - /** @var ParserInterface */ |
|
| 19 | - private $parser; |
|
| 20 | - |
|
| 21 | - /** @var ConfigurationValidator */ |
|
| 22 | - private $validator; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * ServiceLoader constructor. |
|
| 26 | - * @param ParserInterface $parser |
|
| 27 | - */ |
|
| 28 | - public function __construct(ParserInterface $parser) |
|
| 29 | - { |
|
| 30 | - $this->parser = $parser; |
|
| 31 | - $this->validator = new ConfigurationValidator(); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @param string $filePath |
|
| 36 | - * @return ServiceDefinition[] |
|
| 37 | - * @throws InvalidConfigFormatException |
|
| 38 | - */ |
|
| 39 | - public function loadFile(string $filePath) |
|
| 40 | - { |
|
| 41 | - $definitionList = $this->parser->loadFile($filePath); |
|
| 42 | - |
|
| 43 | - return $this->loadDefinitions($definitionList); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @param string $directoryPath |
|
| 48 | - * @return ServiceDefinition[] |
|
| 49 | - * @throws InvalidConfigFormatException |
|
| 50 | - */ |
|
| 51 | - public function loadDirectory(string $directoryPath) |
|
| 52 | - { |
|
| 53 | - $definitionList = $this->parser->loadDirectory($directoryPath); |
|
| 54 | - |
|
| 55 | - $list = []; |
|
| 56 | - foreach ($definitionList as $item) { |
|
| 57 | - $list = array_merge($list, $this->loadDefinitions($item)); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - return $list; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @param array $definitionList |
|
| 65 | - * @return ServiceDefinition[] |
|
| 66 | - * @throws InvalidConfigFormatException |
|
| 67 | - */ |
|
| 68 | - private function loadDefinitions(array $definitionList) |
|
| 69 | - { |
|
| 70 | - $this->validator->validateDefinitions($definitionList); |
|
| 71 | - |
|
| 72 | - if (null === $definitionList[Fields::ROOT_CONFIG_NAME]) { |
|
| 73 | - return []; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - $list = []; |
|
| 77 | - foreach ($definitionList[Fields::ROOT_CONFIG_NAME] as $serviceName => $serviceConfig) { |
|
| 78 | - $list[] = $this->initServiceDefinition($serviceName, $serviceConfig); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - return $list; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @param string $serviceName |
|
| 86 | - * @param array $serviceConfig |
|
| 87 | - * @return ServiceDefinition |
|
| 88 | - */ |
|
| 89 | - private function initServiceDefinition(string $serviceName, array $serviceConfig) |
|
| 90 | - { |
|
| 91 | - $definition = new ServiceDefinition( |
|
| 92 | - $serviceName, |
|
| 93 | - $this->getClass($serviceConfig), |
|
| 94 | - $this->getConstructorParams($serviceConfig), |
|
| 95 | - $this->getMethodCalls($serviceConfig) |
|
| 96 | - ); |
|
| 97 | - |
|
| 98 | - return $definition; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @param $serviceConfig |
|
| 103 | - * @return string |
|
| 104 | - */ |
|
| 105 | - private function getClass($serviceConfig) |
|
| 106 | - { |
|
| 107 | - return $serviceConfig[Fields::CLASS_CONFIG_NAME]; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @param $serviceConfig |
|
| 112 | - * @return array |
|
| 113 | - */ |
|
| 114 | - private function getConstructorParams($serviceConfig) |
|
| 115 | - { |
|
| 116 | - if (false === array_key_exists(Fields::CONSTRUCTOR_PARAMS_CONFIG_NAME, $serviceConfig)) { |
|
| 117 | - return []; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - return $serviceConfig[Fields::CONSTRUCTOR_PARAMS_CONFIG_NAME]; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @param $serviceConfig |
|
| 125 | - * @return array |
|
| 126 | - */ |
|
| 127 | - private function getMethodCalls($serviceConfig) |
|
| 128 | - { |
|
| 129 | - if (false === array_key_exists(Fields::METHOD_CALLS_CONFIG_NAME, $serviceConfig)) { |
|
| 130 | - return []; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - return $serviceConfig[Fields::METHOD_CALLS_CONFIG_NAME]; |
|
| 134 | - } |
|
| 18 | + /** @var ParserInterface */ |
|
| 19 | + private $parser; |
|
| 20 | + |
|
| 21 | + /** @var ConfigurationValidator */ |
|
| 22 | + private $validator; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * ServiceLoader constructor. |
|
| 26 | + * @param ParserInterface $parser |
|
| 27 | + */ |
|
| 28 | + public function __construct(ParserInterface $parser) |
|
| 29 | + { |
|
| 30 | + $this->parser = $parser; |
|
| 31 | + $this->validator = new ConfigurationValidator(); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @param string $filePath |
|
| 36 | + * @return ServiceDefinition[] |
|
| 37 | + * @throws InvalidConfigFormatException |
|
| 38 | + */ |
|
| 39 | + public function loadFile(string $filePath) |
|
| 40 | + { |
|
| 41 | + $definitionList = $this->parser->loadFile($filePath); |
|
| 42 | + |
|
| 43 | + return $this->loadDefinitions($definitionList); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @param string $directoryPath |
|
| 48 | + * @return ServiceDefinition[] |
|
| 49 | + * @throws InvalidConfigFormatException |
|
| 50 | + */ |
|
| 51 | + public function loadDirectory(string $directoryPath) |
|
| 52 | + { |
|
| 53 | + $definitionList = $this->parser->loadDirectory($directoryPath); |
|
| 54 | + |
|
| 55 | + $list = []; |
|
| 56 | + foreach ($definitionList as $item) { |
|
| 57 | + $list = array_merge($list, $this->loadDefinitions($item)); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + return $list; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @param array $definitionList |
|
| 65 | + * @return ServiceDefinition[] |
|
| 66 | + * @throws InvalidConfigFormatException |
|
| 67 | + */ |
|
| 68 | + private function loadDefinitions(array $definitionList) |
|
| 69 | + { |
|
| 70 | + $this->validator->validateDefinitions($definitionList); |
|
| 71 | + |
|
| 72 | + if (null === $definitionList[Fields::ROOT_CONFIG_NAME]) { |
|
| 73 | + return []; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + $list = []; |
|
| 77 | + foreach ($definitionList[Fields::ROOT_CONFIG_NAME] as $serviceName => $serviceConfig) { |
|
| 78 | + $list[] = $this->initServiceDefinition($serviceName, $serviceConfig); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + return $list; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @param string $serviceName |
|
| 86 | + * @param array $serviceConfig |
|
| 87 | + * @return ServiceDefinition |
|
| 88 | + */ |
|
| 89 | + private function initServiceDefinition(string $serviceName, array $serviceConfig) |
|
| 90 | + { |
|
| 91 | + $definition = new ServiceDefinition( |
|
| 92 | + $serviceName, |
|
| 93 | + $this->getClass($serviceConfig), |
|
| 94 | + $this->getConstructorParams($serviceConfig), |
|
| 95 | + $this->getMethodCalls($serviceConfig) |
|
| 96 | + ); |
|
| 97 | + |
|
| 98 | + return $definition; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @param $serviceConfig |
|
| 103 | + * @return string |
|
| 104 | + */ |
|
| 105 | + private function getClass($serviceConfig) |
|
| 106 | + { |
|
| 107 | + return $serviceConfig[Fields::CLASS_CONFIG_NAME]; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @param $serviceConfig |
|
| 112 | + * @return array |
|
| 113 | + */ |
|
| 114 | + private function getConstructorParams($serviceConfig) |
|
| 115 | + { |
|
| 116 | + if (false === array_key_exists(Fields::CONSTRUCTOR_PARAMS_CONFIG_NAME, $serviceConfig)) { |
|
| 117 | + return []; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + return $serviceConfig[Fields::CONSTRUCTOR_PARAMS_CONFIG_NAME]; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @param $serviceConfig |
|
| 125 | + * @return array |
|
| 126 | + */ |
|
| 127 | + private function getMethodCalls($serviceConfig) |
|
| 128 | + { |
|
| 129 | + if (false === array_key_exists(Fields::METHOD_CALLS_CONFIG_NAME, $serviceConfig)) { |
|
| 130 | + return []; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + return $serviceConfig[Fields::METHOD_CALLS_CONFIG_NAME]; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | 136 | } |
@@ -13,109 +13,109 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class ConfigurationValidator |
| 15 | 15 | { |
| 16 | - private const ERROR_PREFIX = 'The service configuration'; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * @param array $definitionList |
|
| 20 | - * @throws InvalidConfigFormatException |
|
| 21 | - */ |
|
| 22 | - public function validateDefinitions(array $definitionList) |
|
| 23 | - { |
|
| 24 | - $this->validateRoot($definitionList); |
|
| 25 | - |
|
| 26 | - if (null === $definitionList[Fields::ROOT_CONFIG_NAME]) { |
|
| 27 | - return; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - foreach ($definitionList[Fields::ROOT_CONFIG_NAME] as $serviceName => $service) { |
|
| 31 | - $this->validateService($serviceName, $service); |
|
| 32 | - } |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @param array $definitionList |
|
| 37 | - * @throws InvalidConfigFormatException |
|
| 38 | - */ |
|
| 39 | - private function validateRoot(array $definitionList) |
|
| 40 | - { |
|
| 41 | - if (false === array_key_exists(Fields::ROOT_CONFIG_NAME, $definitionList)) { |
|
| 42 | - throw new InvalidConfigFormatException( |
|
| 43 | - self::ERROR_PREFIX . ' need the root config key "' . Fields::ROOT_CONFIG_NAME . '"' |
|
| 44 | - ); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - $field = $definitionList[Fields::ROOT_CONFIG_NAME]; |
|
| 48 | - if (false === is_array($field) && false === is_null($field)) { |
|
| 49 | - throw new InvalidConfigFormatException( |
|
| 50 | - self::ERROR_PREFIX . ' key "' . Fields::ROOT_CONFIG_NAME . '" must be an associative array' |
|
| 51 | - ); |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param $serviceName |
|
| 57 | - * @param $service |
|
| 58 | - * @throws InvalidConfigFormatException |
|
| 59 | - */ |
|
| 60 | - private function validateService($serviceName, $service) |
|
| 61 | - { |
|
| 62 | - if (false === is_array($service)) { |
|
| 63 | - throw new InvalidConfigFormatException( |
|
| 64 | - self::ERROR_PREFIX . ' key "' . $serviceName . '" must be an associative array' |
|
| 65 | - ); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - if (false === array_key_exists(Fields::CLASS_CONFIG_NAME, $service)) { |
|
| 69 | - throw new InvalidConfigFormatException( |
|
| 70 | - self::ERROR_PREFIX . ' key "' . Fields::CLASS_CONFIG_NAME . '" is required' |
|
| 71 | - ); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - if (false === is_string($service[Fields::CLASS_CONFIG_NAME])) { |
|
| 75 | - throw new InvalidConfigFormatException( |
|
| 76 | - self::ERROR_PREFIX . ' key "' . Fields::CLASS_CONFIG_NAME . '" must be a string' |
|
| 77 | - ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - if (true === array_key_exists(Fields::CONSTRUCTOR_PARAMS_CONFIG_NAME, $service) && |
|
| 81 | - false === is_array($service[Fields::CONSTRUCTOR_PARAMS_CONFIG_NAME]) |
|
| 82 | - ) { |
|
| 83 | - throw new InvalidConfigFormatException( |
|
| 84 | - self::ERROR_PREFIX . ' key "' . Fields::CONSTRUCTOR_PARAMS_CONFIG_NAME . |
|
| 85 | - '" must be an array or null' |
|
| 86 | - ); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - if (true === array_key_exists(Fields::METHOD_CALLS_CONFIG_NAME, $service) && |
|
| 90 | - false === is_array($service[Fields::METHOD_CALLS_CONFIG_NAME]) |
|
| 91 | - ) { |
|
| 92 | - throw new InvalidConfigFormatException( |
|
| 93 | - self::ERROR_PREFIX . ' key "' . Fields::METHOD_CALLS_CONFIG_NAME . |
|
| 94 | - '" must be an array or null' |
|
| 95 | - ); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - if (false === array_key_exists(Fields::METHOD_CALLS_CONFIG_NAME, $service)) { |
|
| 99 | - return; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - foreach ($service[Fields::METHOD_CALLS_CONFIG_NAME] as $methodName => $call) { |
|
| 103 | - $this->validateCalls($methodName, $call); |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param $methodName |
|
| 109 | - * @param $call |
|
| 110 | - * @throws InvalidConfigFormatException |
|
| 111 | - */ |
|
| 112 | - private function validateCalls($methodName, $call) |
|
| 113 | - { |
|
| 114 | - if (false === is_array($call)) { |
|
| 115 | - throw new InvalidConfigFormatException( |
|
| 116 | - self::ERROR_PREFIX . ' key "' . $methodName . '" must be be an array' |
|
| 117 | - ); |
|
| 118 | - } |
|
| 119 | - } |
|
| 16 | + private const ERROR_PREFIX = 'The service configuration'; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * @param array $definitionList |
|
| 20 | + * @throws InvalidConfigFormatException |
|
| 21 | + */ |
|
| 22 | + public function validateDefinitions(array $definitionList) |
|
| 23 | + { |
|
| 24 | + $this->validateRoot($definitionList); |
|
| 25 | + |
|
| 26 | + if (null === $definitionList[Fields::ROOT_CONFIG_NAME]) { |
|
| 27 | + return; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + foreach ($definitionList[Fields::ROOT_CONFIG_NAME] as $serviceName => $service) { |
|
| 31 | + $this->validateService($serviceName, $service); |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @param array $definitionList |
|
| 37 | + * @throws InvalidConfigFormatException |
|
| 38 | + */ |
|
| 39 | + private function validateRoot(array $definitionList) |
|
| 40 | + { |
|
| 41 | + if (false === array_key_exists(Fields::ROOT_CONFIG_NAME, $definitionList)) { |
|
| 42 | + throw new InvalidConfigFormatException( |
|
| 43 | + self::ERROR_PREFIX . ' need the root config key "' . Fields::ROOT_CONFIG_NAME . '"' |
|
| 44 | + ); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + $field = $definitionList[Fields::ROOT_CONFIG_NAME]; |
|
| 48 | + if (false === is_array($field) && false === is_null($field)) { |
|
| 49 | + throw new InvalidConfigFormatException( |
|
| 50 | + self::ERROR_PREFIX . ' key "' . Fields::ROOT_CONFIG_NAME . '" must be an associative array' |
|
| 51 | + ); |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param $serviceName |
|
| 57 | + * @param $service |
|
| 58 | + * @throws InvalidConfigFormatException |
|
| 59 | + */ |
|
| 60 | + private function validateService($serviceName, $service) |
|
| 61 | + { |
|
| 62 | + if (false === is_array($service)) { |
|
| 63 | + throw new InvalidConfigFormatException( |
|
| 64 | + self::ERROR_PREFIX . ' key "' . $serviceName . '" must be an associative array' |
|
| 65 | + ); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + if (false === array_key_exists(Fields::CLASS_CONFIG_NAME, $service)) { |
|
| 69 | + throw new InvalidConfigFormatException( |
|
| 70 | + self::ERROR_PREFIX . ' key "' . Fields::CLASS_CONFIG_NAME . '" is required' |
|
| 71 | + ); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + if (false === is_string($service[Fields::CLASS_CONFIG_NAME])) { |
|
| 75 | + throw new InvalidConfigFormatException( |
|
| 76 | + self::ERROR_PREFIX . ' key "' . Fields::CLASS_CONFIG_NAME . '" must be a string' |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + if (true === array_key_exists(Fields::CONSTRUCTOR_PARAMS_CONFIG_NAME, $service) && |
|
| 81 | + false === is_array($service[Fields::CONSTRUCTOR_PARAMS_CONFIG_NAME]) |
|
| 82 | + ) { |
|
| 83 | + throw new InvalidConfigFormatException( |
|
| 84 | + self::ERROR_PREFIX . ' key "' . Fields::CONSTRUCTOR_PARAMS_CONFIG_NAME . |
|
| 85 | + '" must be an array or null' |
|
| 86 | + ); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + if (true === array_key_exists(Fields::METHOD_CALLS_CONFIG_NAME, $service) && |
|
| 90 | + false === is_array($service[Fields::METHOD_CALLS_CONFIG_NAME]) |
|
| 91 | + ) { |
|
| 92 | + throw new InvalidConfigFormatException( |
|
| 93 | + self::ERROR_PREFIX . ' key "' . Fields::METHOD_CALLS_CONFIG_NAME . |
|
| 94 | + '" must be an array or null' |
|
| 95 | + ); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + if (false === array_key_exists(Fields::METHOD_CALLS_CONFIG_NAME, $service)) { |
|
| 99 | + return; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + foreach ($service[Fields::METHOD_CALLS_CONFIG_NAME] as $methodName => $call) { |
|
| 103 | + $this->validateCalls($methodName, $call); |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param $methodName |
|
| 109 | + * @param $call |
|
| 110 | + * @throws InvalidConfigFormatException |
|
| 111 | + */ |
|
| 112 | + private function validateCalls($methodName, $call) |
|
| 113 | + { |
|
| 114 | + if (false === is_array($call)) { |
|
| 115 | + throw new InvalidConfigFormatException( |
|
| 116 | + self::ERROR_PREFIX . ' key "' . $methodName . '" must be be an array' |
|
| 117 | + ); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | 121 | } |