-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathDeferMethodCallAspect.php
More file actions
71 lines (64 loc) · 2.14 KB
/
DeferMethodCallAspect.php
File metadata and controls
71 lines (64 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace Flowpack\JobQueue\Common\Job\Aspect;
/*
* This file is part of the Flowpack.JobQueue.Common package.
*
* (c) Contributors to the package
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Aop\JoinPointInterface;
use Neos\Flow\Reflection\ReflectionService;
use Flowpack\JobQueue\Common\Annotations\Defer;
use Flowpack\JobQueue\Common\Job\JobManager;
use Flowpack\JobQueue\Common\Job\StaticMethodCallJob;
/**
* Defer method call aspect
*
* @Flow\Aspect
* @Flow\Scope("singleton")
*/
class DeferMethodCallAspect
{
/**
* @Flow\Inject
* @var JobManager
*/
protected $jobManager;
/**
* @Flow\Inject
* @var ReflectionService
*/
protected $reflectionService;
/**
* @var string
*/
protected string $processingMethodCallHash = '';
/**
* @param JoinPointInterface $joinPoint The current join point
* @return mixed
* @Flow\Around("methodAnnotatedWith(Flowpack\JobQueue\Common\Annotations\Defer)")
*/
public function queueMethodCallAsJob(JoinPointInterface $joinPoint)
{
if ($this->processingMethodCallHash === StaticMethodCallJob::methodCallHash($joinPoint->getClassName(), $joinPoint->getMethodName())) {
return $joinPoint->getAdviceChain()->proceed($joinPoint);
}
/** @var Defer $deferAnnotation */
$deferAnnotation = $this->reflectionService->getMethodAnnotation($joinPoint->getClassName(), $joinPoint->getMethodName(), Defer::class);
$queueName = $deferAnnotation->queueName;
$job = new StaticMethodCallJob($joinPoint->getClassName(), $joinPoint->getMethodName(), $joinPoint->getMethodArguments());
$this->jobManager->queue($queueName, $job, $deferAnnotation->options);
return null;
}
/**
* @param string $processingMethodCallHash
*/
public function setProcessingMethodCallHash(string $processingMethodCallHash): void
{
$this->processingMethodCallHash = $processingMethodCallHash;
}
}