File tree Expand file tree Collapse file tree 3 files changed +50
-48
lines changed
Expand file tree Collapse file tree 3 files changed +50
-48
lines changed Original file line number Diff line number Diff line change @@ -8,10 +8,14 @@ parameters:
88 methodThrowTypeDeclarations : []
99 functionThrowTypeDeclarations : []
1010
11- extensions :
12- exceptionRules : Pepakriz\PHPStanExceptionRules\DI\ExceptionRulesExtension
13-
1411services :
12+ -
13+ class : Pepakriz\PHPStanExceptionRules\DynamicThrowTypeServiceFactory
14+
15+ -
16+ class : Pepakriz\PHPStanExceptionRules\DynamicThrowTypeService
17+ factory : @Pepakriz\PHPStanExceptionRules\DynamicThrowTypeServiceFactory::create
18+
1519 -
1620 class : Pepakriz\PHPStanExceptionRules\ThrowsAnnotationReader
1721 -
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Pepakriz \PHPStanExceptionRules ;
4+
5+ use Nette \DI \Container ;
6+ use function array_keys ;
7+ use function array_map ;
8+
9+ class DynamicThrowTypeServiceFactory
10+ {
11+
12+ private const TAG_DYNAMIC_METHOD_THROW_TYPE = 'exceptionRules.dynamicMethodThrowTypeExtension ' ;
13+ private const TAG_DYNAMIC_STATIC_METHOD_THROW_TYPE = 'exceptionRules.dynamicStaticMethodThrowTypeExtension ' ;
14+ private const TAG_DYNAMIC_CONSTRUCTOR_THROW_TYPE = 'exceptionRules.dynamicConstructorThrowTypeExtension ' ;
15+ private const TAG_DYNAMIC_FUNCTION_THROW_TYPE = 'exceptionRules.dynamicFunctionThrowTypeExtension ' ;
16+
17+ /**
18+ * @var Container
19+ */
20+ private $ container ;
21+
22+ public function __construct (Container $ container )
23+ {
24+ $ this ->container = $ container ;
25+ }
26+
27+ public function create (): DynamicThrowTypeService
28+ {
29+ $ tagToService = function (array $ tags ) {
30+ return array_map (function (string $ serviceName ) {
31+ return $ this ->container ->getService ($ serviceName );
32+ }, array_keys ($ tags ));
33+ };
34+
35+ return new DynamicThrowTypeService (
36+ $ tagToService ($ this ->container ->findByTag (self ::TAG_DYNAMIC_METHOD_THROW_TYPE )),
37+ $ tagToService ($ this ->container ->findByTag (self ::TAG_DYNAMIC_STATIC_METHOD_THROW_TYPE )),
38+ $ tagToService ($ this ->container ->findByTag (self ::TAG_DYNAMIC_CONSTRUCTOR_THROW_TYPE )),
39+ $ tagToService ($ this ->container ->findByTag (self ::TAG_DYNAMIC_FUNCTION_THROW_TYPE ))
40+ );
41+ }
42+
43+ }
You can’t perform that action at this time.
0 commit comments