Skip to content

Commit 8ce5ec4

Browse files
committed
Initial import.
0 parents  commit 8ce5ec4

File tree

10 files changed

+364
-0
lines changed

10 files changed

+364
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
composer.lock
2+
vendor

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: php
2+
3+
php:
4+
- 5.3.2
5+
- 5.3
6+
- 5.4
7+
8+
before_script:
9+
- wget -nc http://getcomposer.org/composer.phar
10+
- php composer.phar install
11+
12+
script: phpunit --coverage-text

LICENSE

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2011, Dragonfly Development Inc
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice,
8+
this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in the
11+
documentation and/or other materials provided with the distribution.
12+
* Neither the name of Dragonfly Development Inc nor the names of its
13+
contributors may be used to endorse or promote products derived from
14+
this software without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Dot Access Configuration
2+
========================
3+
4+
Given a deep data structure representing a configuration, access
5+
configuration by dot notation.
6+
7+
8+
9+
Requirements
10+
------------
11+
12+
* PHP (5.3+)
13+
* [dflydev/placeholder-resolver](https://github.com/dflydev/dflydev-placeholder-resolver) (1.*)
14+
15+
16+
Usage
17+
-----
18+
19+
20+
21+
License
22+
-------
23+
24+
This library is licensed under the New BSD License - see the LICENSE file
25+
for details.
26+
27+
28+
Community
29+
---------
30+
31+
If you have questions or want to help out, join us in the
32+
[#dflydev](irc://irc.freenode.net/#dflydev) channel on irc.freenode.net.

composer.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "dflydev/dot-access-configuration",
3+
"type": "library",
4+
"description": "Given a deep data structure representing a configuration, access configuration by dot notation.",
5+
"homepage": "https://github.com/dflydev/dot-access-configuration",
6+
"keywords": ["dot", "access", "configuration", "notation", "config", "yaml"],
7+
"license": "New BSD License",
8+
"authors": [
9+
{
10+
"name": "Dragonfly Development Inc.",
11+
"email": "[email protected]",
12+
"homepage": "http://dflydev.com"
13+
},
14+
{
15+
"name": "Beau Simensen",
16+
"email": "[email protected]",
17+
"homepage": "http://beausimensen.com"
18+
}
19+
],
20+
"require": {
21+
"php": ">=5.3.2",
22+
"symfony/yaml": ">2.0.0,<2.2",
23+
"dflydev/placeholder-resolver": "1.*"
24+
},
25+
"autoload": {
26+
"psr-0": {
27+
"Dflydev\\DotAccessConfiguration": "src"
28+
}
29+
},
30+
"extra": {
31+
"branch-alias": {
32+
"dev-master": "1.0-dev"
33+
}
34+
}
35+
}

phpunit.xml.dist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit colors="true" bootstrap="tests/bootstrap.php">
3+
<testsuites>
4+
<testsuite name="Dot Access Configuration Test Suite">
5+
<directory>./tests/Dflydev/Tests/DotAccessConfiguration</directory>
6+
</testsuite>
7+
</testsuites>
8+
9+
<filter>
10+
<whitelist>
11+
<directory>./src/Dflydev/DotAccessConfiguration/</directory>
12+
</whitelist>
13+
</filter>
14+
</phpunit>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
/*
4+
* This file is a part of dflydev/dot-access-configuration.
5+
*
6+
* (c) Dragonfly Development Inc.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Dflydev\DotAccessConfiguration;
13+
14+
interface ConfigurationInterface
15+
{
16+
/**
17+
* Append a value to a key (assumes key refers to an array value)
18+
*
19+
* @param string $key
20+
* @param mixed $value
21+
*/
22+
public function append($key, $value = null);
23+
24+
/**
25+
* Set a value for a key
26+
*
27+
* @param string $key
28+
* @param mixed $value
29+
*/
30+
public function set($key, $value = null);
31+
32+
/**
33+
* Unset a key
34+
*
35+
* @param string $key
36+
*/
37+
public function unset($key);
38+
39+
/**
40+
* Get the raw value for a key
41+
*
42+
* @param string $key
43+
* @return mixed
44+
*/
45+
public function get($key);
46+
47+
/**
48+
* Get a configuration instance for a key
49+
*
50+
* @param string $key
51+
* @return ConfigurationInterface
52+
*/
53+
public function getConfiguration($key)
54+
55+
/**
56+
* Import data into existing configuration
57+
*
58+
* @param array $data
59+
* @param bool $clobber
60+
*/
61+
public function importData(array $data, $clobber = true);
62+
63+
/**
64+
* Import data from an external configuration into existing configuration
65+
*
66+
* @param ConfigurationInterface $configuration
67+
* @param bool $clobber
68+
*/
69+
public function importConfiguration(ConfigurationInterface $configuration, $clobber = true);
70+
71+
/**
72+
* Export configuration as raw data
73+
*
74+
* @return array
75+
*/
76+
public function export();
77+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is a part of dflydev/dot-access-configuration.
5+
*
6+
* (c) Dragonfly Development Inc.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Dflydev\DotAccessConfiguration;
13+
14+
class Util
15+
{
16+
/**
17+
* Merge contents from one associtative array to another
18+
*
19+
* @param array $to
20+
* @param array $from
21+
* @param bool $clobber
22+
*/
23+
static public function mergeAssocArray($to, $from, $clobber = true)
24+
{
25+
if ( is_array($from) ) {
26+
foreach ( $from as $k => $v ) {
27+
if (!isset($to[$k])) {
28+
$to[$k] = $v;
29+
} else {
30+
$to[$k] = self::mergeAssocArray($to[$k], $v, $clobber);
31+
}
32+
}
33+
return $to;
34+
}
35+
return $clobber ? $from : $to;
36+
}
37+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
3+
/*
4+
* This file is a part of dflydev/dot-access-configuration.
5+
*
6+
* (c) Dragonfly Development Inc.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Dflydev\Tests\DotAccessConfiguration;
13+
14+
use Dflydev\DotAccessConfiguration\Util;
15+
16+
class UtilTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @dataProvider mergeAssocArrayProvider
20+
*/
21+
public function testMergeAssocArray($message, $to, $from, $clobber, $expectedResult)
22+
{
23+
$result = Util::mergeAssocArray($to, $from, $clobber);
24+
$this->assertEquals($expectedResult, $result, $message);
25+
}
26+
27+
public function mergeAssocArrayProvider()
28+
{
29+
return array(
30+
31+
array(
32+
'Clobber should replace to value with from value for strings (shallow)',
33+
// to
34+
array('a' => 'A'),
35+
// from
36+
array('a' => 'B'),
37+
// clobber
38+
true,
39+
// expected result
40+
array('a' => 'B'),
41+
),
42+
43+
array(
44+
'Clobber should replace to value with from value for strings (deep)',
45+
// to
46+
array('a' => array('b' => 'B',),),
47+
// from
48+
array('a' => array('b' => 'C',),),
49+
// clobber
50+
true,
51+
// expected result
52+
array('a' => array('b' => 'C',),),
53+
),
54+
55+
array(
56+
'Clobber should NOTreplace to value with from value for strings (shallow)',
57+
// to
58+
array('a' => 'A'),
59+
// from
60+
array('a' => 'B'),
61+
// clobber
62+
false,
63+
// expected result
64+
array('a' => 'A'),
65+
),
66+
67+
array(
68+
'Clobber should NOT replace to value with from value for strings (deep)',
69+
// to
70+
array('a' => array('b' => 'B',),),
71+
// from
72+
array('a' => array('b' => 'C',),),
73+
// clobber
74+
false,
75+
// expected result
76+
array('a' => array('b' => 'B',),),
77+
),
78+
79+
array(
80+
'Associative arrays should be combined',
81+
// to
82+
array('a' => array('b' => 'B',),),
83+
// from
84+
array('a' => array('c' => 'C',),),
85+
// clobber
86+
null,
87+
// expected result
88+
array('a' => array('b' => 'B', 'c' => 'C',),),
89+
),
90+
91+
array(
92+
'Arrays should be replaced (with clobber enabled)',
93+
// to
94+
array('a' => array('b', 'c',)),
95+
// from
96+
array('a' => array('B', 'C',),),
97+
// clobber
98+
true,
99+
// expected result
100+
array('a' => array('B', 'C',),),
101+
),
102+
103+
array(
104+
'Arrays should be NOT replaced (with clobber disabled)',
105+
// to
106+
array('a' => array('b', 'c',)),
107+
// from
108+
array('a' => array('B', 'C',),),
109+
// clobber
110+
false,
111+
// expected result
112+
array('a' => array('b', 'c',),),
113+
),
114+
);
115+
}
116+
}

tests/bootstrap.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
/*
4+
* This file is a part of dflydev/dot-access-configuration.
5+
*
6+
* (c) Dragonfly Development Inc.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
$loader = require dirname(__DIR__).'/vendor/.composer/autoload.php';
13+
$loader->add('Dflydev\\Tests\\DotAccessConfiguration', 'tests');

0 commit comments

Comments
 (0)