@@ -44,6 +44,7 @@ final class Ast implements BuildMode
4444 private ?string $ needsParent = null ;
4545
4646 public function __construct (
47+ private readonly array $ blacklistedPredicates ,
4748 public readonly bool $ allowUnpacking ,
4849 private array $ outputSchema = []
4950 ) {
@@ -82,14 +83,14 @@ public function finalize(array $outgoingCons, array $incomingCons, string $refMa
8283 'stored_constructor ' => $ cons ,
8384 ];
8485 }
85- $ dbSchema = '' ;
86+ $ dbSchema = " boolFalse#bc799737 = Bool; \n boolTrue#997275b5 = Bool; \n true#3fedd339 = True; \n vector#1cb5c415 {t:Type} # [ t ] = Vector t; \n\n" ;
8687 foreach ($ fileIdCons as $ cons => $ _ ) {
87- $ dbSchema .= self :: stringifySchema ($ cons , ['id ' => 'long ' ], "FileId " )."\n" ;
88+ $ dbSchema .= $ this -> stringifySchema ($ cons , ['id ' => 'long ' ], "FileId " )."\n" ;
8889 }
8990 $ dbSchema .= "\n" ;
9091
9192 foreach ($ this ->outputSchema as $ constructor => $ params ) {
92- $ dbSchema .= self :: stringifySchema ($ constructor , $ params , "FileSource " )."\n" ;
93+ $ dbSchema .= $ this -> stringifySchema ($ constructor , $ params , "FileSource " )."\n" ;
9394 }
9495 $ dbSchemaJSON = (new TL (null ))->toJson ($ dbSchema );
9596
@@ -115,15 +116,25 @@ public function finalize(array $outgoingCons, array $incomingCons, string $refMa
115116 $ s = $ s ->setOther (['filerefs ' => __DIR__ . '/../../../src/TL_file_ref_map_schema.tl ' ]);
116117 $ TL = new TL ((new ReflectionClass (MTProto::class))->newInstanceWithoutConstructor ());
117118 $ TL ->init ($ s );
119+
120+ $ json = $ TL ->toJson (__DIR__ . '/../../../src/TL_file_ref_map_schema.tl ' );
121+ foreach ($ json ['constructors ' ] as $ constructor ) {
122+ Assert::keyNotExists ($ this ->blacklistedPredicates , $ constructor ['predicate ' ], "{$ constructor ['predicate ' ]} is blacklisted and cannot be used in the schema " );
123+ }
124+ foreach ($ json ['methods ' ] as $ method ) {
125+ Assert::keyNotExists ($ this ->blacklistedPredicates , $ method ['method ' ], "{$ method ['method ' ]} is blacklisted and cannot be used in the schema " );
126+ }
127+
118128 $ serialized = $ TL ->serializeObject (['type ' => 'FileReferenceOrigins ' ], $ value , '' );
119129 $ valueDe = $ TL ->deserialize ($ serialized , ['type ' => '' , 'connection ' => null , 'encrypted ' => true ]);
120130 Assert::true ($ value == $ valueDe );
121131 file_put_contents ($ refMapFile , $ serialized );
122132 file_put_contents ($ refMapFileJson , json_encode ($ valueDe , flags: JSON_THROW_ON_ERROR ));
123133 }
124134
125- private static function stringifySchema (string $ constructor , array $ params , string $ cType ): string
135+ private function stringifySchema (string $ constructor , array $ params , string $ cType ): string
126136 {
137+ Assert::keyNotExists ($ this ->blacklistedPredicates , $ constructor , "$ constructor is blacklisted and cannot be used in the schema " );
127138 $ paramsStr = "$ constructor " ;
128139 foreach ($ params as $ name => $ type ) {
129140 Assert::notContains ($ type , 'InputPeer ' , "$ constructor cannot contain InputPeer " );
@@ -192,7 +203,7 @@ public function addNode(TLContext $ctx, ?array $action = null, ?string $why = nu
192203 }
193204 }
194205 foreach ($ stored as $ name => ['type ' => $ type ]) {
195- throw new AssertionError ("Leftover parameter $ constructor. $ name: $ type for " .self :: stringifySchema ($ constructor , $ existing , 'FileSource ' ));
206+ throw new AssertionError ("Leftover parameter $ constructor. $ name: $ type for " .$ this -> stringifySchema ($ constructor , $ existing , 'FileSource ' ));
196207 }
197208 } else {
198209 $ types = [];
0 commit comments