|
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 Ytake\LaravelAspect\Annotation\LoggableAnnotate; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class AbstractLogger |
|
25
|
|
|
*/ |
|
26
|
|
|
class AbstractLogger |
|
27
|
|
|
{ |
|
28
|
|
|
/** @var string */ |
|
29
|
|
|
protected $format = "%s:%s.%s"; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param LoggableAnnotate $annotation |
|
33
|
|
|
* @param MethodInvocation $invocation |
|
34
|
|
|
* |
|
35
|
|
|
* @return string[] |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function logFormatter(LoggableAnnotate $annotation, MethodInvocation $invocation) |
|
38
|
|
|
{ |
|
39
|
|
|
$context = []; |
|
40
|
|
|
$arguments = $invocation->getArguments(); |
|
41
|
|
|
foreach ($invocation->getMethod()->getParameters() as $parameter) { |
|
42
|
|
|
$context['args'][$parameter->name] = $arguments[$parameter->getPosition()]; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return [ |
|
46
|
|
|
'level' => $annotation->value, |
|
|
|
|
|
|
47
|
|
|
'message' => sprintf( |
|
48
|
|
|
$this->format, |
|
49
|
|
|
$annotation->name, |
|
|
|
|
|
|
50
|
|
|
$invocation->getMethod()->class, |
|
51
|
|
|
$invocation->getMethod()->name |
|
52
|
|
|
), |
|
53
|
|
|
'context' => $context, |
|
54
|
|
|
]; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: