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 Psr\Log\LoggerInterface; |
21
|
|
|
use Ray\Aop\MethodInvocation; |
22
|
|
|
use Ytake\LaravelAspect\Annotation\LoggableAnnotate; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class AbstractLogger |
26
|
|
|
*/ |
27
|
|
|
class AbstractLogger |
28
|
|
|
{ |
29
|
|
|
/** @var string */ |
30
|
|
|
protected $format = "%s:%s.%s"; |
31
|
|
|
|
32
|
|
|
/** @var LoggerInterface */ |
33
|
|
|
protected static $logger; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param LoggableAnnotate $annotation |
37
|
|
|
* @param MethodInvocation $invocation |
38
|
|
|
* |
39
|
|
|
* @return string[] |
40
|
|
|
*/ |
41
|
|
|
protected function logFormatter(LoggableAnnotate $annotation, MethodInvocation $invocation) |
42
|
|
|
{ |
43
|
|
|
$context = []; |
44
|
|
|
$arguments = $invocation->getArguments(); |
45
|
|
|
foreach ($invocation->getMethod()->getParameters() as $parameter) { |
46
|
|
|
$context['args'][$parameter->name] = $arguments[$parameter->getPosition()]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return [ |
50
|
|
|
'level' => $annotation->value, |
|
|
|
|
51
|
|
|
'message' => sprintf( |
52
|
|
|
$this->format, |
53
|
|
|
$annotation->name, |
|
|
|
|
54
|
|
|
$invocation->getMethod()->class, |
55
|
|
|
$invocation->getMethod()->name |
56
|
|
|
), |
57
|
|
|
'context' => $context, |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param LoggerInterface $logger |
63
|
|
|
*/ |
64
|
|
|
public function setLogger(LoggerInterface $logger) |
65
|
|
|
{ |
66
|
|
|
self::$logger = $logger; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
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: