/** * Test that words camelize * @return void */ public function testCamelCase() { // Original text $original = 'mojo_pollo'; // Convert to camel $result = $this->stringHelper->camelCase($original); // Expected string $expected = 'mojoPollo'; // Test $this->assertEquals($result, $expected); }
/** * Will camelize all keys found in a array or multi dimensional array * * @param array $originalArray the source * @param string $morphTo camel | snake * @return array the final array with the camielize keys */ public static function morphKeys($originalArray, $morphTo = 'camel') { // New array with the morphed keys $newArray = []; // Iterate through each items foreach ($originalArray as $key => $value) { // If $value is an array in itself, re-run through this function if (is_array($value)) { $value = static::morphKeys($value, $morphTo); } // Set new key $newKey = ''; switch ($morphTo) { // Camel case case 'camel': $newKey = StringHelper::camelCase($key); break 1; // Snake case // Snake case case 'snake': $newKey = StringHelper::snakeCase($key); break 1; } // Set array line $newArray[$newKey] = $value; } // Return new array return $newArray; }