| 1 |
<?php |
| 2 |
/** |
| 3 |
* PHP utilities. |
| 4 |
* |
| 5 |
* Helpers for PHP paths and files handling. |
| 6 |
* |
| 7 |
* @package System |
| 8 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 9 |
* @since 2.0.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace Decalog\System; |
| 13 |
|
| 14 |
use Decalog\System\Option; |
| 15 |
use Decalog\System\File; |
| 16 |
use Decalog\Logger; |
| 17 |
|
| 18 |
/** |
| 19 |
* Define the PHP functionality. |
| 20 |
* |
| 21 |
* Helpers for PHP paths and files handling. |
| 22 |
* |
| 23 |
* @package System |
| 24 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 25 |
* @since 2.0.0 |
| 26 |
*/ |
| 27 |
class PHP { |
| 28 |
|
| 29 |
/** |
| 30 |
* Normalizes a path+file. |
| 31 |
* |
| 32 |
* @param string $file The raw file name. |
| 33 |
* @return string The normalized file name. |
| 34 |
* @since 2.0.0 |
| 35 |
*/ |
| 36 |
public static function normalized_file( $file ) { |
| 37 |
if ( 'unknown' === $file || '' === $file ) { |
| 38 |
return 'PHP kernel'; |
| 39 |
} |
| 40 |
if ( false !== strpos( $file, 'phar://' ) ) { |
| 41 |
return str_replace( 'phar://', '', wp_normalize_path( $file ) ); |
| 42 |
} |
| 43 |
return './' . str_replace( wp_normalize_path( ABSPATH ), '', wp_normalize_path( $file ) ); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Normalizes a path+file. |
| 48 |
* |
| 49 |
* @param string $file The raw file name. |
| 50 |
* @param string $line Optional. The file line. |
| 51 |
* @return string The normalized file name. |
| 52 |
* @since 2.0.0 |
| 53 |
*/ |
| 54 |
public static function normalized_file_line( $file, $line = '' ) { |
| 55 |
if ( '' === (string) $line || '0' === (string) $line ) { |
| 56 |
return self::normalized_file( $file ); |
| 57 |
} |
| 58 |
return self::normalized_file( $file ) . ':' . (string) $line; |
| 59 |
} |
| 60 |
|
| 61 |
} |
| 62 |
|