JBZoo\Utils\Str::splitCamelCase PHP Method

splitCamelCase() public static method

Convert camel case to human readable format
public static splitCamelCase ( string $input, string $separator = '_', boolean $toLower = true ) : string
$input string
$separator string
$toLower boolean
return string
    public static function splitCamelCase($input, $separator = '_', $toLower = true)
    {
        $original = $input;
        $output = preg_replace(array('/(?<=[^A-Z])([A-Z])/', '/(?<=[^0-9])([0-9])/'), '_$0', $input);
        $output = preg_replace('#_{1,}#', $separator, $output);
        $output = trim($output);
        if ($toLower) {
            $output = strtolower($output);
        }
        if (strlen($output) == 0) {
            return $original;
        }
        return $output;
    }

Usage Example

コード例 #1
0
ファイル: CovCatcher.php プロジェクト: jbzoo/phpunit
 /**
  * @param null|string $testName
  * @return string
  */
 protected function _getPrefix($testName = null)
 {
     if (null === $testName) {
         $objects = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT);
         foreach ($objects as $object) {
             if (isset($object['object']) && $object['object'] instanceof \PHPUnit_Framework_TestCase) {
                 $testName = $object['class'] . '_' . $object['function'];
                 break;
             }
         }
     }
     $testName = str_replace(__NAMESPACE__ . '\\', '', $testName);
     $testName = Str::splitCamelCase($testName, '_', true);
     $testName = preg_replace('/^test_/', '', $testName);
     $testName = preg_replace('/_test$/', '', $testName);
     $testName = str_replace('_test_test_', '_', $testName);
     $testName = str_replace(array('/', '\\', '_', '-'), '', $testName);
     $testName = strtolower($testName);
     if (!$testName) {
         $testName = uniqid('', true);
         $testName = str_replace('.', '', $testName);
     }
     return $testName;
 }
All Usage Examples Of JBZoo\Utils\Str::splitCamelCase