| 1 |
<?php |
| 2 |
/** |
| 3 |
* Various utility functions used through the Faust plugin. |
| 4 |
* |
| 5 |
* @package FaustWP |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WPE\FaustWP\Utilities; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Converts string to camelCase. Added to ensure that fields are compliant with the GraphQL spec. |
| 16 |
* |
| 17 |
* @param string $str The string to be converted to camelCase. |
| 18 |
* @param array $preserved_chars The characters to preserve. |
| 19 |
* |
| 20 |
* @credit http://www.mendoweb.be/blog/php-convert-string-to-camelcase-string/ |
| 21 |
* |
| 22 |
* @return string camelCase'd string |
| 23 |
*/ |
| 24 |
function camelcase( $str, $preserved_chars = array() ) { |
| 25 |
/* Convert non-alpha and non-numeric characters to spaces. */ |
| 26 |
$str = preg_replace( '/[^a-z0-9' . implode( '', $preserved_chars ) . ']+/i', ' ', $str ); |
| 27 |
$str = trim( $str ); |
| 28 |
|
| 29 |
/* Uppercase the first character of each word. */ |
| 30 |
$str = ucwords( $str ); |
| 31 |
$str = str_replace( ' ', '', $str ); |
| 32 |
|
| 33 |
return lcfirst( $str ); |
| 34 |
} |
| 35 |
|