File tree Expand file tree Collapse file tree 4 files changed +14
-27
lines changed Expand file tree Collapse file tree 4 files changed +14
-27
lines changed Original file line number Diff line number Diff line change 1- # SIL PHP Utilities
1+ # Array Dot Notation for PHP
22
3- A collection of utility classes share among SIL International PHP projects.
4-
5- ## Build Status
6-
7- [ ![ Scrutinizer Code Quality] ( https://scrutinizer-ci.com/g/silinternational/php-env/badges/quality-score.png?b=develop )] ( https://scrutinizer-ci.com/g/silinternational/php-utils/?branch=master )
8- [ ![ Build Status] ( https://scrutinizer-ci.com/g/silinternational/php-env/badges/build.png?b=develop )] ( https://scrutinizer-ci.com/g/silinternational/php-utils/build-status/master )
3+ A utility to use dot notation in PHP arrays.
94
105## Setup
116
@@ -21,17 +16,9 @@ There is a Makefile in place to simplify common tasks.
2116
2217___
2318
24- ## Sil/Arrays
25-
26- Utility class for manipulating arrays.
27-
28- ### Classes in Sil/Arrays namespace
29-
30- 1 . __ ArrayCollapse__ : ` use Sil\Array\ArrayCollapse; `
31-
32- ### Class ` ArrayCollapse `
19+ ### Class ` DotNotation `
3320
34- Util class containing a method to collapse a multi-dimensional array into a
21+ Util class containing a single method to collapse a multi-dimensional array into a
3522single-dimensional array. Array keys are combined using a dot to separate
3623levels of the array. For instance:
3724
Original file line number Diff line number Diff line change 11{
2- "name" : " silinternational/php-utils " ,
3- "description" : " PHP library including various utility classes " ,
2+ "name" : " silinternational/php-dot-notation " ,
3+ "description" : " PHP library for using dot notation in arrays " ,
44 "type" : " library" ,
55 "license" : " MIT" ,
66 "autoload" : {
7- "psr-4" : {"Sil\\ PhpUtils \\ " : " src/" }
7+ "psr-4" : {"Sil\\ PhpArrayDotNotation \\ " : " src/" }
88 },
99 "require" : {
1010 "php" : " >=7.0"
Original file line number Diff line number Diff line change 11<?php
22
3- namespace Sil \PhpUtils \ Arrays ;
3+ namespace Sil \PhpArrayDotNotation ;
44
5- class ArrayCollapse
5+ class DotNotation
66{
77 /**
88 * Recursively collapse a multi-dimensional array into a single-dimensional array.
@@ -27,14 +27,14 @@ class ArrayCollapse
2727 * @param string $parentKey array key associated with $childArray in the parent array
2828 * @return array
2929 */
30- public static function arrayCollapseRecursive ($ childArray , $ parentKey = '' )
30+ public static function collapse ($ childArray , $ parentKey = '' )
3131 {
3232 $ newArray = [];
3333
3434 foreach ($ childArray as $ key => $ value ) {
3535 $ combinedKey = (empty ($ parentKey ) ? '' : $ parentKey . '. ' ) . $ key ;
3636 if (is_array ($ value )) {
37- $ newArray = array_merge ($ newArray , self ::arrayCollapseRecursive ($ value , $ combinedKey ));
37+ $ newArray = array_merge ($ newArray , self ::collapse ($ value , $ combinedKey ));
3838 } else {
3939 $ newArray [$ combinedKey ] = $ value ;
4040 }
Original file line number Diff line number Diff line change 11<?php
2- namespace Sil \PhpUtils \tests ;
2+ namespace Sil \PhpArrayDotNotation \tests ;
33
44use PHPUnit \Framework \TestCase ;
5- use Sil \PhpUtils \ Arrays \ ArrayCollapse ;
5+ use Sil \PhpArrayDotNotation \ DotNotation ;
66
77class ArrayCollapseTest extends TestCase
88{
@@ -25,7 +25,7 @@ public function testArrayCollapse()
2525 ];
2626
2727 // Act
28- $ actualOutput = ArrayCollapse:: arrayCollapseRecursive ($ input );
28+ $ actualOutput = DotNotation:: collapse ($ input );
2929
3030 // Assert
3131 $ this ->assertEquals ($ expectedOutput , $ actualOutput );
You can’t perform that action at this time.
0 commit comments