|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Contains class ActivationStrategy. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5.5 |
|
6
|
|
|
* |
|
7
|
|
|
* LICENSE: |
|
8
|
|
|
* This file is part of Yet Another Php Eve Api Library also know as Yapeal |
|
9
|
|
|
* which can be used to access the Eve Online API data and place it into a |
|
10
|
|
|
* database. |
|
11
|
|
|
* Copyright (C) 2016 Michael Cummings |
|
12
|
|
|
* |
|
13
|
|
|
* This program is free software: you can redistribute it and/or modify it |
|
14
|
|
|
* under the terms of the GNU Lesser General Public License as published by the |
|
15
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
|
16
|
|
|
* option) any later version. |
|
17
|
|
|
* |
|
18
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
19
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
20
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
|
21
|
|
|
* for more details. |
|
22
|
|
|
* |
|
23
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
24
|
|
|
* along with this program. If not, see |
|
25
|
|
|
* <http://www.gnu.org/licenses/>. |
|
26
|
|
|
* |
|
27
|
|
|
* You should be able to find a copy of this license in the LICENSE.md file. A |
|
28
|
|
|
* copy of the GNU GPL should also be available in the GNU-GPL.md file. |
|
29
|
|
|
* |
|
30
|
|
|
* @copyright 2016 Michael Cummings |
|
31
|
|
|
* @license LGPL-3.0+ |
|
32
|
|
|
* @author Michael Cummings <[email protected]> |
|
33
|
|
|
*/ |
|
34
|
|
|
namespace Yapeal\Log; |
|
35
|
|
|
|
|
36
|
|
|
use Monolog\Handler\FingersCrossed\ActivationStrategyInterface; |
|
37
|
|
|
use Monolog\Logger; |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Class ActivationStrategy. |
|
41
|
|
|
* |
|
42
|
|
|
* A runtime instead of just new instance settable error level activation strategy like what is include with Monolog. |
|
43
|
|
|
*/ |
|
44
|
|
|
class ActivationStrategy implements ActivationStrategyInterface |
|
45
|
|
|
{ |
|
46
|
|
|
/** |
|
47
|
|
|
* ActivationStrategy constructor. |
|
48
|
|
|
* |
|
49
|
|
|
* @param $actionLevel |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __construct($actionLevel) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->actionLevel = Logger::toMonologLevel($actionLevel); |
|
54
|
|
|
} |
|
55
|
|
|
/** |
|
56
|
|
|
* @param array $record |
|
57
|
|
|
* |
|
58
|
|
|
* @return bool |
|
59
|
|
|
*/ |
|
60
|
|
|
public function isHandlerActivated(array $record) |
|
61
|
|
|
{ |
|
62
|
|
|
return $record['level'] >= $this->actionLevel; |
|
63
|
|
|
} |
|
64
|
|
|
public function setActionLevel($value) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->actionLevel = Logger::toMonologLevel($value); |
|
67
|
|
|
} |
|
68
|
|
|
/** |
|
69
|
|
|
* @var int $actionLevel |
|
70
|
|
|
*/ |
|
71
|
|
|
private $actionLevel; |
|
72
|
|
|
} |
|
73
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: