| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Converts stored redirect matching engine class names into admin-facing labels. |
| 9 |
*/ |
| 10 |
class ABJ_404_Solution_RedirectEngineLabeler { |
| 11 |
|
| 12 |
/** |
| 13 |
* Convert a raw engine class name to a human-readable label. |
| 14 |
* |
| 15 |
* @param string $rawName |
| 16 |
* @return string |
| 17 |
*/ |
| 18 |
public function humanize(string $rawName): string { |
| 19 |
$name = preg_replace('/^ABJ_404_Solution_/', '', $rawName); |
| 20 |
if (!is_string($name)) { |
| 21 |
$name = $rawName; |
| 22 |
} |
| 23 |
|
| 24 |
$name = (string)preg_replace('/MatchingEngine$/', ' Matching', $name); |
| 25 |
$name = (string)preg_replace('/Engine$/', '', $name); |
| 26 |
$name = (string)preg_replace('/(?<=[a-z])([A-Z])/', ' $1', $name); |
| 27 |
$name = trim($name); |
| 28 |
$name = str_replace(array('Url ', 'Url'), array('URL ', 'URL'), $name); |
| 29 |
$name = str_replace('Category Tag', 'Category/Tag', $name); |
| 30 |
|
| 31 |
return $name !== '' ? $name : $rawName; |
| 32 |
} |
| 33 |
} |
| 34 |
|