File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 10
10
namespace nicoSWD \Rules ;
11
11
12
12
use Closure ;
13
+ use InvalidArgumentException ;
14
+ use nicoSWD \Rules \Core \CallableUserFunction ;
13
15
use nicoSWD \Rules \Tokens \BaseToken ;
14
16
15
17
class Parser
@@ -256,6 +258,26 @@ protected function assertSyntaxSeemsOkay()
256
258
}
257
259
}
258
260
261
+ public function registerFunctionClass (string $ className )
262
+ {
263
+ /** @var CallableUserFunction $class */
264
+ $ class = new $ className ();
265
+
266
+ if (!$ class instanceof CallableUserFunction) {
267
+ throw new InvalidArgumentException (
268
+ sprintf (
269
+ "%s must be an instance of %s " ,
270
+ get_class ($ className ),
271
+ CallableUserFunction::class
272
+ )
273
+ );
274
+ }
275
+
276
+ $ this ->registerFunction ($ class ->getName (), function () use ($ class ) {
277
+ return $ class ->call (...func_get_args ());
278
+ });
279
+ }
280
+
259
281
public function registerFunction (string $ name , Closure $ callback )
260
282
{
261
283
$ this ->userDefinedFunctions [$ name ] = $ callback ;
You can’t perform that action at this time.
0 commit comments