File tree 4 files changed +14
-27
lines changed
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
2
2
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.
9
4
10
5
## Setup
11
6
@@ -21,17 +16,9 @@ There is a Makefile in place to simplify common tasks.
21
16
22
17
___
23
18
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 `
33
20
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
35
22
single-dimensional array. Array keys are combined using a dot to separate
36
23
levels of the array. For instance:
37
24
Original file line number Diff line number Diff line change 1
1
{
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 " ,
4
4
"type" : " library" ,
5
5
"license" : " MIT" ,
6
6
"autoload" : {
7
- "psr-4" : {"Sil\\ PhpUtils \\ " : " src/" }
7
+ "psr-4" : {"Sil\\ PhpArrayDotNotation \\ " : " src/" }
8
8
},
9
9
"require" : {
10
10
"php" : " >=7.0"
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
- namespace Sil \PhpUtils \ Arrays ;
3
+ namespace Sil \PhpArrayDotNotation ;
4
4
5
- class ArrayCollapse
5
+ class DotNotation
6
6
{
7
7
/**
8
8
* Recursively collapse a multi-dimensional array into a single-dimensional array.
@@ -27,14 +27,14 @@ class ArrayCollapse
27
27
* @param string $parentKey array key associated with $childArray in the parent array
28
28
* @return array
29
29
*/
30
- public static function arrayCollapseRecursive ($ childArray , $ parentKey = '' )
30
+ public static function collapse ($ childArray , $ parentKey = '' )
31
31
{
32
32
$ newArray = [];
33
33
34
34
foreach ($ childArray as $ key => $ value ) {
35
35
$ combinedKey = (empty ($ parentKey ) ? '' : $ parentKey . '. ' ) . $ key ;
36
36
if (is_array ($ value )) {
37
- $ newArray = array_merge ($ newArray , self ::arrayCollapseRecursive ($ value , $ combinedKey ));
37
+ $ newArray = array_merge ($ newArray , self ::collapse ($ value , $ combinedKey ));
38
38
} else {
39
39
$ newArray [$ combinedKey ] = $ value ;
40
40
}
Original file line number Diff line number Diff line change 1
1
<?php
2
- namespace Sil \PhpUtils \tests ;
2
+ namespace Sil \PhpArrayDotNotation \tests ;
3
3
4
4
use PHPUnit \Framework \TestCase ;
5
- use Sil \PhpUtils \ Arrays \ ArrayCollapse ;
5
+ use Sil \PhpArrayDotNotation \ DotNotation ;
6
6
7
7
class ArrayCollapseTest extends TestCase
8
8
{
@@ -25,7 +25,7 @@ public function testArrayCollapse()
25
25
];
26
26
27
27
// Act
28
- $ actualOutput = ArrayCollapse:: arrayCollapseRecursive ($ input );
28
+ $ actualOutput = DotNotation:: collapse ($ input );
29
29
30
30
// Assert
31
31
$ this ->assertEquals ($ expectedOutput , $ actualOutput );
You can’t perform that action at this time.
0 commit comments