|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
5
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
6
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
7
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
8
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
9
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
10
|
|
|
* THE SOFTWARE. |
|
11
|
|
|
* |
|
12
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
13
|
|
|
* and is licensed under the MIT license. |
|
14
|
|
|
* |
|
15
|
|
|
* Copyright (c) 2015-2017 Yuuki Takezawa |
|
16
|
|
|
* |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace Ytake\LaravelAspect\Queue; |
|
20
|
|
|
|
|
21
|
|
|
use Ray\Aop\MethodInvocation; |
|
22
|
|
|
use Illuminate\Bus\Queueable; |
|
23
|
|
|
use Illuminate\Container\Container; |
|
24
|
|
|
use Illuminate\Queue\SerializesModels; |
|
25
|
|
|
use Illuminate\Queue\InteractsWithQueue; |
|
26
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Class LazyMessage |
|
30
|
|
|
*/ |
|
31
|
|
|
class LazyMessage implements ShouldQueue |
|
32
|
|
|
{ |
|
33
|
|
|
use InteractsWithQueue, Queueable, SerializesModels; |
|
34
|
|
|
|
|
35
|
|
|
/** @var MethodInvocation */ |
|
36
|
|
|
protected $methodInvocation; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* LazyMessage constructor. |
|
40
|
|
|
* |
|
41
|
|
|
* @param MethodInvocation $invocation |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct(MethodInvocation $invocation) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->methodInvocation = $invocation; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param Container $container |
|
50
|
|
|
*/ |
|
51
|
|
|
public function handle(Container $container) |
|
52
|
|
|
{ |
|
53
|
|
|
$class = new \ReflectionClass(get_class($this->methodInvocation->getThis())); |
|
54
|
|
|
require_once $class->getFileName(); |
|
55
|
|
|
$method = $this->methodInvocation->getMethod()->getName(); |
|
|
|
|
|
|
56
|
|
|
$container->call( |
|
57
|
|
|
[ |
|
58
|
|
|
$this->methodInvocation->getThis(), |
|
59
|
|
|
$method, |
|
60
|
|
|
], |
|
61
|
|
|
$this->methodInvocation->getArguments()->getArrayCopy() |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|