55namespace FlixTech \SchemaRegistryApi \Registry ;
66
77use AvroSchema ;
8+ use FlixTech \SchemaRegistryApi \Exception \SchemaRegistryException ;
89use FlixTech \SchemaRegistryApi \Registry ;
910use GuzzleHttp \Promise \PromiseInterface ;
1011
@@ -47,7 +48,11 @@ public function __construct(Registry $registry, CacheAdapter $cacheAdapter, call
4748 */
4849 public function register (string $ subject , AvroSchema $ schema , callable $ requestCallback = null )
4950 {
50- $ closure = function (int $ schemaId ) use ($ schema ) {
51+ $ closure = function ($ schemaId ) use ($ schema ) {
52+ if ($ schemaId instanceof SchemaRegistryException) {
53+ return $ schemaId ;
54+ }
55+
5156 $ this ->cacheAdapter ->cacheSchemaWithId ($ schema , $ schemaId );
5257 $ this ->cacheAdapter ->cacheSchemaIdByHash ($ schemaId , $ this ->getSchemaHash ($ schema ));
5358
@@ -68,7 +73,11 @@ function (PromiseInterface $promise) use ($closure) {
6873 */
6974 public function schemaVersion (string $ subject , AvroSchema $ schema , callable $ requestCallback = null )
7075 {
71- $ closure = function (int $ version ) use ($ schema , $ subject ) {
76+ $ closure = function ($ version ) use ($ schema , $ subject ) {
77+ if ($ version instanceof SchemaRegistryException) {
78+ return $ version ;
79+ }
80+
7281 $ this ->cacheAdapter ->cacheSchemaWithSubjectAndVersion ($ schema , $ subject , $ version );
7382
7483 return $ version ;
@@ -94,7 +103,11 @@ public function schemaId(string $subject, AvroSchema $schema, callable $requestC
94103 return $ this ->cacheAdapter ->getIdWithHash ($ schemaHash );
95104 }
96105
97- $ closure = function (int $ schemaId ) use ($ schema , $ schemaHash ) {
106+ $ closure = function ($ schemaId ) use ($ schema , $ schemaHash ) {
107+ if ($ schemaId instanceof SchemaRegistryException) {
108+ return $ schemaId ;
109+ }
110+
98111 $ this ->cacheAdapter ->cacheSchemaWithId ($ schema , $ schemaId );
99112 $ this ->cacheAdapter ->cacheSchemaIdByHash ($ schemaId , $ schemaHash );
100113
@@ -119,7 +132,11 @@ public function schemaForId(int $schemaId, callable $requestCallback = null)
119132 return $ this ->cacheAdapter ->getWithId ($ schemaId );
120133 }
121134
122- $ closure = function (AvroSchema $ schema ) use ($ schemaId ) {
135+ $ closure = function ($ schema ) use ($ schemaId ) {
136+ if ($ schema instanceof SchemaRegistryException) {
137+ return $ schema ;
138+ }
139+
123140 $ this ->cacheAdapter ->cacheSchemaWithId ($ schema , $ schemaId );
124141 $ this ->cacheAdapter ->cacheSchemaIdByHash ($ schemaId , $ this ->getSchemaHash ($ schema ));
125142
@@ -144,7 +161,11 @@ public function schemaForSubjectAndVersion(string $subject, int $version, callab
144161 return $ this ->cacheAdapter ->getWithSubjectAndVersion ($ subject , $ version );
145162 }
146163
147- $ closure = function (AvroSchema $ schema ) use ($ subject , $ version ) {
164+ $ closure = function ($ schema ) use ($ subject , $ version ) {
165+ if ($ schema instanceof SchemaRegistryException) {
166+ return $ schema ;
167+ }
168+
148169 $ this ->cacheAdapter ->cacheSchemaWithSubjectAndVersion ($ schema , $ subject , $ version );
149170
150171 return $ schema ;
@@ -184,6 +205,6 @@ private function applyValueHandlers($value, callable $promiseHandler, callable $
184205
185206 private function getSchemaHash (AvroSchema $ schema ): string
186207 {
187- return call_user_func ($ this ->hashAlgoFunc , $ schema );
208+ return \ call_user_func ($ this ->hashAlgoFunc , $ schema );
188209 }
189210}
0 commit comments