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-2016 Yuuki Takezawa |
16
|
|
|
* |
17
|
|
|
*/ |
18
|
|
|
namespace Ytake\LaravelAspect\Interceptor; |
19
|
|
|
|
20
|
|
|
use Ray\Aop\MethodInvocation; |
21
|
|
|
use Ray\Aop\MethodInterceptor; |
22
|
|
|
use Ytake\LaravelAspect\Annotation\AnnotationReaderTrait; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class LoggableInterceptor |
26
|
|
|
*/ |
27
|
|
|
class LoggableInterceptor extends AbstractLogger implements MethodInterceptor |
28
|
|
|
{ |
29
|
|
|
use AnnotationReaderTrait; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param MethodInvocation $invocation |
33
|
|
|
* |
34
|
|
|
* @return object |
35
|
|
|
* @throws \Exception |
36
|
|
|
*/ |
37
|
|
|
public function invoke(MethodInvocation $invocation) |
38
|
|
|
{ |
39
|
|
|
$start = microtime(true); |
40
|
|
|
$result = $invocation->proceed(); |
41
|
|
|
$time = microtime(true) - $start; |
42
|
|
|
/** @var \Ytake\LaravelAspect\Annotation\Loggable $annotation */ |
43
|
|
|
$annotation = $this->reader->getMethodAnnotation($invocation->getMethod(), $this->annotation); |
44
|
|
|
$logFormat = $this->logFormatter($annotation, $invocation); |
45
|
|
|
/** @var \Monolog\Logger $logger */ |
46
|
|
|
$logger = app('log')->getMonoLog(); |
47
|
|
|
if (!$annotation->skipResult) { |
48
|
|
|
$logFormat['context']['result'] = $result; |
49
|
|
|
} |
50
|
|
|
$logFormat['context']['time'] = $time; |
51
|
|
|
/** Monolog\Logger */ |
52
|
|
|
$logger->log($logFormat['level'], $logFormat['message'], $logFormat['context']); |
|
|
|
|
53
|
|
|
|
54
|
|
|
return $result; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: