@@ -81,12 +81,12 @@ public function register($type, $schema)
81
81
82
82
$ isOk = (
83
83
(is_string ($ schema ) === true && empty ($ schema ) === false ) ||
84
- $ schema instanceof Closure ||
84
+ is_callable ( $ schema) ||
85
85
$ schema instanceof SchemaProviderInterface
86
86
);
87
87
if ($ isOk === false ) {
88
88
throw new InvalidArgumentException (T::t (
89
- 'Schema for type \'%s \' must be non-empty string, Closure or SchemaProviderInterface instance. ' ,
89
+ 'Schema for type \'%s \' must be non-empty string, callable or SchemaProviderInterface instance. ' ,
90
90
[$ type ]
91
91
));
92
92
}
@@ -146,11 +146,12 @@ public function getSchemaByType($type)
146
146
throw new InvalidArgumentException (T::t ('Schema is not registered for type \'%s \'. ' , [$ type ]));
147
147
}
148
148
149
- $ classNameOrClosure = $ this ->getProviderMapping ($ type );
150
- if ($ classNameOrClosure instanceof Closure ) {
151
- $ schema = $ this ->createSchemaFromClosure ( $ classNameOrClosure );
149
+ $ classNameOrCallable = $ this ->getProviderMapping ($ type );
150
+ if (is_string ( $ classNameOrCallable ) === true ) {
151
+ $ schema = $ this ->createSchemaFromClassName ( $ classNameOrCallable );
152
152
} else {
153
- $ schema = $ this ->createSchemaFromClassName ($ classNameOrClosure );
153
+ assert ('is_callable($classNameOrCallable) === true ' );
154
+ $ schema = $ this ->createSchemaFromCallable ($ classNameOrCallable );
154
155
}
155
156
$ this ->setCreatedProvider ($ type , $ schema );
156
157
@@ -313,6 +314,7 @@ protected function getResourceType($resource)
313
314
}
314
315
315
316
/**
317
+ * @deprecated Use `createSchemaFromCallable` method instead.
316
318
* @param Closure $closure
317
319
*
318
320
* @return SchemaProviderInterface
@@ -324,6 +326,19 @@ protected function createSchemaFromClosure(Closure $closure)
324
326
return $ schema ;
325
327
}
326
328
329
+ /**
330
+ * @param callable $callable
331
+ *
332
+ * @return SchemaProviderInterface
333
+ */
334
+ protected function createSchemaFromCallable (callable $ callable )
335
+ {
336
+ $ schema = $ callable instanceof Closure ?
337
+ $ this ->createSchemaFromClosure ($ callable ) : call_user_func ($ callable , $ this ->getFactory ());
338
+
339
+ return $ schema ;
340
+ }
341
+
327
342
/**
328
343
* @param string $className
329
344
*
0 commit comments