4
4
5
5
namespace TypeLang \PHPDoc ;
6
6
7
+ use TypeLang \PHPDoc \Exception \InvalidTagException ;
8
+ use TypeLang \PHPDoc \Exception \ParsingException ;
9
+ use TypeLang \PHPDoc \Exception \RuntimeExceptionInterface ;
7
10
use TypeLang \PHPDoc \Parser \Description \DescriptionParserInterface ;
8
11
use TypeLang \PHPDoc \Tag \Tag ;
9
12
@@ -16,7 +19,7 @@ public function __construct(
16
19
private array $ factories = [],
17
20
) {}
18
21
19
- public function add (array |string $ tags , FactoryInterface $ delegate ): void
22
+ public function register (array |string $ tags , FactoryInterface $ delegate ): void
20
23
{
21
24
foreach ((array ) $ tags as $ tag ) {
22
25
$ this ->factories [$ tag ] = $ delegate ;
@@ -28,7 +31,24 @@ public function create(string $name, string $content, DescriptionParserInterface
28
31
$ delegate = $ this ->factories [$ name ] ?? null ;
29
32
30
33
if ($ delegate !== null ) {
31
- return $ delegate ->create ($ name , $ content , $ descriptions );
34
+ try {
35
+ return $ delegate ->create ($ name , $ content , $ descriptions );
36
+ } catch (ParsingException $ e ) {
37
+ throw $ e ;
38
+ } catch (RuntimeExceptionInterface $ e ) {
39
+ throw InvalidTagException::fromCreatingTag (
40
+ tag: $ name ,
41
+ source: $ e ->getSource (),
42
+ offset: $ e ->getOffset (),
43
+ prev: $ e ,
44
+ );
45
+ } catch (\Throwable $ e ) {
46
+ throw InvalidTagException::fromCreatingTag (
47
+ tag: $ name ,
48
+ source: $ content ,
49
+ prev: $ e ,
50
+ );
51
+ }
32
52
}
33
53
34
54
return new Tag ($ name , $ descriptions ->parse ($ content ));
0 commit comments