Skip to content

Commit 5914efc

Browse files
committed
Fix config container reader for:
[section] group.name = name
1 parent 77237b8 commit 5914efc

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

src/Onion/Command/BuildCommand.php

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function execute($arguments = array())
6666
else
6767
$logger->warn( '* doc/ directory not found.',1 );
6868

69+
6970
$logger->info( 'Configuring package.ini' );
7071
$config = new PackageConfigReader($logger);
7172
$config->readAsPackageXml();

src/Onion/ConfigContainer.php

+19-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@
1111
namespace Onion;
1212
use Exception;
1313

14+
15+
/**
16+
* ini config container provides an interface for retrive strucutre config value
17+
*
18+
* [section]
19+
* name = value
20+
*
21+
* $config->get('section.name');
22+
*
23+
*
24+
* [section]
25+
* name.subname = value
26+
*
27+
* $config->get('section.name.subname')
28+
*
29+
*/
1430
class ConfigContainer
1531
{
1632
public $array;
@@ -37,7 +53,7 @@ function __isset($k)
3753

3854
function has( $refstr )
3955
{
40-
$paths = explode('.',$refstr);
56+
$paths = explode('.',$refstr,2);
4157
$ref = & $this->array;
4258
foreach( $paths as $p ) {
4359
if( ! isset( $ref[ $p ] ) )
@@ -49,7 +65,7 @@ function has( $refstr )
4965

5066
function set( $refstr , $v )
5167
{
52-
$paths = explode('.',$refstr);
68+
$paths = explode('.',$refstr,2);
5369
$ref = & $this->array;
5470
foreach( $paths as $p ) {
5571
if( ! isset( $ref[ $p ] ) ) {
@@ -65,7 +81,7 @@ function set( $refstr , $v )
6581

6682
function get( $refstr )
6783
{
68-
$paths = explode('.',$refstr);
84+
$paths = explode('.',$refstr,2);
6985
$ref = $this->array;
7086
foreach( $paths as $path ) {
7187
if( isset($ref[$path]) ) {

src/Onion/PackageConfigReader.php

+17-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@
1717
use Onion\ConfigContainer;
1818
use Onion\SpecUtils;
1919

20+
/**
21+
*
22+
* package ini file reader:
23+
*
24+
* $reader = new PackageIniReader;
25+
* $pkginfo = $reader->read( 'file.ini' );
26+
*
27+
* $pkginfo->get( 'config' );
28+
* $pkginfo->get( 'config.name' );
29+
* $pkginfo->get( 'section.name' );
30+
*
31+
* $pkgxml = new PackageXmlGenerator( $pkginfo );
32+
* $pkgxml->generate();
33+
*
34+
*/
2035
class PackageConfigReader
2136
{
2237
public $file;
@@ -430,6 +445,7 @@ function generatePackageXml()
430445
die( $e->getMessage() );
431446
}
432447
}
433-
434448
}
435449

450+
451+

tests/Onion/ConfigContainerTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function test()
55
{
66
$config = new \Onion\ConfigContainer(array(
77
'key' => array(
8-
'subkey' => array( 'hash' => 1 ),
8+
'subkey.hash' => 1
99
)
1010
));
1111
ok( $config );
@@ -23,7 +23,6 @@ function test()
2323

2424
ok( ! $config->has('non') );
2525
ok( $config->has('key') );
26-
ok( $config->has('key.subkey') );
2726
ok( $config->has('key.subkey2') );
2827
ok( $config->has('key.subkey.hash3') );
2928
}

0 commit comments

Comments
 (0)