Skip to content

Commit a7e437f

Browse files
committed
Add operation injector which is experimental
1 parent 0aaf36b commit a7e437f

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ $javaClass = new JavaClass(
278278
| validation.method.arguments_count_only | boolean | false | If this mode `true` then ClassResolver validate arguments size only. | JavaClass |
279279
| operations.enable_trace | boolean | true | Store operations history into memory if this is enabled. | JavaClass |
280280
| operations.temporary_code_stream | string | php://memory | Operation code will be outputted to temporary stream. Change temporary stream if your code is heavy. You'll get happy. | JavaClass |
281+
| operations.injector.before | callable | null | Inject an executor before from executing an operation. | JavaClass |
282+
| operations.injector.after | callable | null | Inject an executor after to executing an operation. | JavaClass |
281283
| log.level | int | Logger::EMERGENCY | This option set `Monolog` output level. | Both |
282284
| log.path | string or resource | php://stdout | This option set `Monolog` output destination. | Both |
283285
| dry_run (Not Implemented) | boolean | false | Dry-run denotes to check JavaClass/JavaArchive structures only. If this options is `true` then to run dry-run mode. | Both |

src/Core/JVM/Invoker/Invokable.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,17 @@ function ($item) {
267267
)
268268
);
269269

270+
$beforeTrigger = $this->options['operations']['injections']['before'] ?? GlobalOptions::get('operations.injections.before');
271+
if (is_callable($beforeTrigger)) {
272+
$beforeTrigger(
273+
$this->javaClassInvoker,
274+
$stacks,
275+
$localStorage,
276+
$reader,
277+
$currentConstantPool
278+
);
279+
}
280+
270281
/**
271282
* @var OperationInterface|Accumulator|ConstantPool $executor
272283
*/
@@ -281,6 +292,17 @@ function ($item) {
281292
);
282293
$returnValue = $executor->execute();
283294

295+
$afterTrigger = $this->options['operations']['injections']['after'] ?? GlobalOptions::get('operations.injections.after');
296+
if (is_callable($afterTrigger)) {
297+
$afterTrigger(
298+
$this->javaClassInvoker,
299+
$stacks,
300+
$localStorage,
301+
$reader,
302+
$currentConstantPool
303+
);
304+
}
305+
284306
if ($returnValue !== null) {
285307
$this->javaClassInvoker->getJavaClass()->appendDebug($debugTraces);
286308
$this->debugTool->getLogger()->info('Finish operations: ' . $methodBeautified);

0 commit comments

Comments
 (0)