| 1 |
<?php |
| 2 |
/** |
| 3 |
* Global functions. |
| 4 |
* |
| 5 |
* @package Functions |
| 6 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 7 |
* @since 2.3.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
if ( ! function_exists('decalog_get_psr_log_version') ) { |
| 11 |
/** |
| 12 |
* Get the needed version of PSR-3. |
| 13 |
* |
| 14 |
* @return int The PSR-3 needed version. |
| 15 |
* @since 4.0.0 |
| 16 |
*/ |
| 17 |
function decalog_get_psr_log_version() { |
| 18 |
$required = 1; |
| 19 |
if ( ! defined( 'DECALOG_PSR_LOG_VERSION') ) { |
| 20 |
define( 'DECALOG_PSR_LOG_VERSION', 'V1' ); |
| 21 |
} |
| 22 |
switch ( strtolower( DECALOG_PSR_LOG_VERSION ) ) { |
| 23 |
case 'v3': |
| 24 |
$required = 3; |
| 25 |
break; |
| 26 |
case 'auto': |
| 27 |
if ( class_exists( '\Psr\Log\NullLogger') ) { |
| 28 |
$reflection = new \ReflectionMethod(\Psr\Log\NullLogger::class, 'log'); |
| 29 |
foreach ( $reflection->getParameters() as $param ) { |
| 30 |
if ( 'message' === $param->getName() ) { |
| 31 |
if ( str_contains($param->getType() ?? '', '|') ) { |
| 32 |
$required = 3; |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
return $required; |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
|