Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

View file

@ -0,0 +1,2 @@
composer.lock
vendor

View file

@ -0,0 +1,12 @@
language: php
php:
- 5.3.3
- 5.3
- 5.4
before_script:
- wget -nc http://getcomposer.org/composer.phar
- php composer.phar install --dev
script: phpunit --coverage-text --verbose

View file

@ -0,0 +1,19 @@
Copyright (c) 2012 Dragonfly Development Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View file

@ -0,0 +1,111 @@
# Dot Access Configuration
Given a deep data structure representing a configuration, access
configuration by dot notation.
This library combines [dflydev/dot-access-data](https://github.com/dflydev/dflydev-dot-access-data)
and [dflydev/placeholder-resolver](https://github.com/dflydev/dflydev-placeholder-resolver)
to provide a complete configuration solution.
## Requirements
* PHP (5.3+)
* [dflydev/dot-access-data](https://github.com/dflydev/dflydev-dot-access-data) (1.*)
* [dflydev/placeholder-resolver](https://github.com/dflydev/dflydev-placeholder-resolver) (1.*)
* [symfony/yaml](https://github.com/symfony/Yaml) (>2,<2.2) *(suggested)*
## Usage
Generally one will use an implementation of `ConfigurationBuilderInterface`
to build `ConfigurationInterface` instances. For example, to build a Configuration
out of a YAML file, one would use the `YamlFileConfigurationBuilder`:
```php
use Dflydev\DotAccessConfiguration\YamlFileConfigurationBuilder;
$configurationBuilder = new YamlFileConfigurationBuilder('config/config.yml');
$configuration = $configurationBuilder->build();
```
Once created, the Configuration instance behaves similarly to a Data
instance from [dflydev/dot-access-data](https://github.com/dflydev/dflydev-dot-access-data).
```php
$configuration->set('a.b.c', 'ABC');
$configuration->get('a.b.c');
$configuration->set('a.b.e', array('A', 'B', 'C'));
$configuration->append('a.b.e', 'D');
```
## Custom Configurations
Configuration Builders use Configuration Factories and Placeholder Resolver
Factories behind the scenes in order to build a working configuration.
Under normal circumstances one should not need to do anything with the
Placeholder Resolver Factory. However, one may wish to extend the
default `Configuration` class or use an entirely different implementation
altogether.
In order to build instances of custom `ConfigurationInterface` implementations
with the standard builders, one would need to implement
`ConfigurationFactoryInterface` and inject it into any
`ConfigurationBuilderInterface`.
If a Configuration is declared as follows:
```php
namespace MyProject;
use Dflydev\DotAccessConfiguration\Configuration;
class MyConf extends Configuration
{
public function someSpecialMethod()
{
// Whatever you want here.
}
}
```
Create the following factory:
```php
namespace MyProject;
use Dflydev\DotAccessConfiguration\ConfigurationFactoryInterface;
class MyConfFactory implements ConfigurationFactoryInterface
{
/**
* {@inheritdocs}
*/
public function create()
{
return new MyConf;
}
}
```
To use the factory with any builder, inject it as follows:
```php
use Dflydev\DotAccessConfiguration\YamlFileConfigurationBuilder;
use MyProject\MyConfFactory;
$configurationBuilder = new YamlFileConfigurationBuilder('config/config.yml');
// Inject your custom Configuration Factory
$configurationBuilder->setConfigurationFactory(new MyConfFactory);
// Will now build instances of MyConfFactory instead of
// the standard Configuration implementation.
$configuration = $configurationBuilder->build();
```
## License
This library is licensed under the New BSD License - see the LICENSE file
for details.
## Community
If you have questions or want to help out, join us in the
[#dflydev](irc://irc.freenode.net/#dflydev) channel on irc.freenode.net.

View file

@ -0,0 +1,41 @@
{
"name": "dflydev/dot-access-configuration",
"type": "library",
"description": "Given a deep data structure representing a configuration, access configuration by dot notation.",
"homepage": "https://github.com/dflydev/dflydev-dot-access-configuration",
"keywords": ["config", "configuration"],
"license": "MIT",
"authors": [
{
"name": "Dragonfly Development Inc.",
"email": "info@dflydev.com",
"homepage": "http://dflydev.com"
},
{
"name": "Beau Simensen",
"email": "beau@dflydev.com",
"homepage": "http://beausimensen.com"
}
],
"require": {
"php": ">=5.3.2",
"dflydev/dot-access-data": "1.*",
"dflydev/placeholder-resolver": "1.*"
},
"require-dev": {
"symfony/yaml": "~2.1"
},
"suggest": {
"symfony/yaml": "Required for using the YAML Configuration Builders"
},
"autoload": {
"psr-0": {
"Dflydev\\DotAccessConfiguration": "src"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
}
}

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="tests/bootstrap.php">
<testsuites>
<testsuite name="Dot Access Configuration Test Suite">
<directory>./tests/Dflydev/DotAccessConfiguration</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/Dflydev/DotAccessConfiguration/</directory>
</whitelist>
</filter>
</phpunit>

View file

@ -0,0 +1,188 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
use Dflydev\DotAccessData\Data;
use Dflydev\PlaceholderResolver\PlaceholderResolverInterface;
use Dflydev\PlaceholderResolver\RegexPlaceholderResolver;
abstract class AbstractConfiguration implements ConfigurationInterface
{
private $placeholderResolver;
private $data;
private $exportIsDirty = true;
private $resolvedExport;
/**
* {@inheritdocs}
*/
public function getRaw($key)
{
return $this->data()->get($key);
}
/**
* {@inheritdocs}
*/
public function get($key)
{
$value = $this->getRaw($key);
if (is_object($value)) {
return $value;
}
$this->resolveValues($value);
return $value;
}
/**
* {@inheritdocs}
*/
public function set($key, $value = null)
{
$this->exportIsDirty = true;
return $this->data()->set($key, $value);
}
/**
* {@inheritdocs}
*/
public function append($key, $value = null)
{
$this->exportIsDirty = true;
return $this->data()->append($key, $value);
}
/**
* {@inheritdocs}
*/
public function exportRaw()
{
return $this->data()->export();
}
/**
* {@inheritdocs}
*/
public function export()
{
if ($this->exportIsDirty) {
$this->resolvedExport = $this->data()->export();
$this->resolveValues($this->resolvedExport);
$this->exportIsDirty = false;
}
return $this->resolvedExport;
}
/**
* {@inheritdocs}
*/
public function exportData()
{
return new Data($this->export());
}
/**
* {@inheritdocs}
*/
public function importRaw($imported = null, $clobber = true)
{
$this->exportIsDirty = true;
if (null !== $imported) {
$this->data()->import($imported, $clobber);
}
}
/**
* {@inheritdocs}
*/
public function import(ConfigurationInterface $imported, $clobber = true)
{
return $this->importRaw($imported->exportRaw(), $clobber);
}
/**
* {@inheritdocs}
*/
public function resolve($value = null)
{
if (null === $value) {
return null;
}
return $this->placeholderResolver()->resolvePlaceholder($value);
}
/**
* {@inheritdocs}
*/
public function setPlaceholderResolver(PlaceholderResolverInterface $placeholderResolver)
{
$this->placeholderResolver = $placeholderResolver;
return $this;
}
/**
* Resolve values
*
* For objects, do nothing. For strings, resolve placeholder.
* For arrays, call resolveValues() on each item.
*
* @param mixed $input
*/
protected function resolveValues(&$input = null)
{
if (is_array($input)) {
foreach ($input as $idx => $value) {
$this->resolveValues($value);
$input[$idx] = $value;
}
} else {
if (!is_object($input)) {
$input = $this->placeholderResolver()->resolvePlaceholder($input);
}
}
}
/**
* Data
*
* @return Data
*/
protected function data()
{
if (null === $this->data) {
$this->data = new Data;
}
return $this->data;
}
/**
* Placeholder Resolver
*
* @return PlaceholderResolverInterface
*/
protected function placeholderResolver()
{
if (null === $this->placeholderResolver) {
$this->placeholderResolver = new RegexPlaceholderResolver(new ConfigurationDataSource($this), '%', '%');
}
return $this->placeholderResolver;
}
}

View file

@ -0,0 +1,94 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
abstract class AbstractConfigurationBuilder implements ConfigurationBuilderInterface
{
private $configurationFactory;
private $placeholderResolverFactory;
/**
* Set Configuration Factory
*
* @param ConfigurationFactoryInterface $configurationFactory
*
* @return AbstractConfigurationBuilder
*/
public function setConfigurationFactory(ConfigurationFactoryInterface $configurationFactory)
{
$this->configurationFactory = $configurationFactory;
return $this;
}
/**
* Configuration Factory
*
* @return ConfigurationFactoryInterface
*/
protected function configurationFactory()
{
if (null === $this->configurationFactory) {
$this->configurationFactory = new ConfigurationFactory;
}
return $this->configurationFactory;
}
/**
* {@inheritdocs}
*/
public function build()
{
$configuration = $this->configurationFactory()->create();
if (null !== $this->placeholderResolverFactory) {
$placeholderResolver = $this->placeholderResolverFactory->create($configuration);
$configuration->setPlaceholderResolver($placeholderResolver);
}
$this->internalBuild($configuration);
return $configuration;
}
/**
* Set Placeholder Resolver Factory
*
* @param PlaceholderResolverFactoryInterface $placeholderResolverFactory
*/
public function setPlaceholderResolverFactory(PlaceholderResolverFactoryInterface $placeholderResolverFactory)
{
$this->placeholderResolverFactory = $placeholderResolverFactory;
}
/**
* Called to reconfigure the specified Configuration Builder to be similar to this instance
*
* @param AbstractConfigurationBuilder $configurationBuilder
*/
public function reconfigure(AbstractConfigurationBuilder $configurationBuilder)
{
if (null !== $this->placeholderResolverFactory) {
$configurationBuilder->setPlaceholderResolverFactory($this->placeholderResolverFactory);
}
$configurationBuilder->setConfigurationFactory($this->configurationFactory());
}
/**
* Internal build
*
* @param ConfigurationInterface $configuration
*/
abstract protected function internalBuild(ConfigurationInterface $configuration);
}

View file

@ -0,0 +1,35 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
use Dflydev\PlaceholderResolver\DataSource\DataSourceInterface;
abstract class AbstractPlaceholderResolverFactory implements PlaceholderResolverFactoryInterface
{
/**
* {@inheritdocs}
*/
public function create(ConfigurationInterface $configuration)
{
return $this->createInternal($configuration, new ConfigurationDataSource($configuration));
}
/**
* Internal create
*
* @param ConfigurationInterface $configuration
* @param DataSourceInterface $dataSource
*
* @return PlaceholderResolverInterface
*/
abstract protected function createInternal(ConfigurationInterface $configuration, DataSourceInterface $dataSource);
}

View file

@ -0,0 +1,25 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
class Configuration extends AbstractConfiguration
{
/**
* Constructor
*
* @param array|null $config
*/
public function __construct(array $config = null)
{
$this->importRaw($config);
}
}

View file

@ -0,0 +1,22 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
interface ConfigurationBuilderInterface
{
/**
* Build a Configuration
*
* @return ConfigurationInterface
*/
public function build();
}

View file

@ -0,0 +1,67 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
use Dflydev\PlaceholderResolver\DataSource\DataSourceInterface;
class ConfigurationDataSource implements DataSourceInterface
{
private $configuration;
/**
* Constructor
*
* @param ConfigurationInterface $configuration
*/
public function __construct(ConfigurationInterface $configuration)
{
$this->setConfiguration($configuration);
}
/**
* {@inheritdoc}
*/
public function exists($key, $system = false)
{
if ($system) {
return false;
}
return null !== $this->configuration->getRaw($key);
}
/**
* {@inheritdoc}
*/
public function get($key, $system = false)
{
if ($system) {
return null;
}
return $this->configuration->getRaw($key);
}
/**
* Set Configuration
*
* @param ConfigurationInterface $configuration
*
* @return ConfigurationDataSource
*/
public function setConfiguration(ConfigurationInterface $configuration)
{
$this->configuration = $configuration;
return $this;
}
}

View file

@ -0,0 +1,23 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
class ConfigurationFactory implements ConfigurationFactoryInterface
{
/**
* {@inheritdocs}
*/
public function create()
{
return new Configuration;
}
}

View file

@ -0,0 +1,22 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
interface ConfigurationFactoryInterface
{
/**
* Create a Configuration
*
* @return ConfigurationInterface
*/
public function create();
}

View file

@ -0,0 +1,111 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
use Dflydev\DotAccessData\Data;
use Dflydev\PlaceholderResolver\PlaceholderResolverInterface;
interface ConfigurationInterface
{
/**
* Get a value (with placeholders unresolved)
*
* @param string $key
*
* @return mixed
*/
public function getRaw($key);
/**
* Get a value (with placeholders resolved)
*
* @param string $key
*
* @return mixed
*/
public function get($key);
/**
* Set a value
*
* @param string $key
* @param mixed $value
*/
public function set($key, $value = null);
/**
* Append a value
*
* Will force key to be an array if it is only a string
*
* @param string $key
* @param mixed $value
*/
public function append($key, $value = null);
/**
* Export configuration data as an associtaive array (with placeholders unresolved)
*
* @return array
*/
public function exportRaw();
/**
* Export configuration data as an associtaive array (with placeholders resolved)
*
* @return array
*/
public function export();
/**
* Underlying Data representation
*
* Will have all placeholders resolved.
*
* @return Data
*/
public function exportData();
/**
* Import another Configuration
*
* @param array $imported
* @param bool $clobber
*/
public function importRaw($imported, $clobber = true);
/**
* Import another Configuration
*
* @param ConfigurationInterface $imported
* @param bool $clobber
*/
public function import(ConfigurationInterface $imported, $clobber = true);
/**
* Resolve placeholders in value from configuration
*
* @param string|null $value
*
* @return string
*/
public function resolve($value = null);
/**
* Set Placeholder Resolver
*
* @param PlaceholderResolver $placeholderResolver
*
* @return ConfigurationInterface
*/
public function setPlaceholderResolver(PlaceholderResolverInterface $placeholderResolver);
}

View file

@ -0,0 +1,26 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
use Dflydev\PlaceholderResolver\DataSource\DataSourceInterface;
use Dflydev\PlaceholderResolver\RegexPlaceholderResolver;
class PlaceholderResolverFactory extends AbstractPlaceholderResolverFactory
{
/**
* {@inheritdocs}
*/
protected function createInternal(ConfigurationInterface $configuration, DataSourceInterface $dataSource)
{
return new RegexPlaceholderResolver($dataSource, '%', '%');
}
}

View file

@ -0,0 +1,26 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
use Dflydev\PlaceholderResolver\PlaceholderResolverInterface;
interface PlaceholderResolverFactoryInterface
{
/**
* Configuration
*
* @param ConfigurationInterface $configuration
*
* @return PlaceholderResolverInterface
*/
public function create(ConfigurationInterface $configuration);
}

View file

@ -0,0 +1,54 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
use Psr\Log\InvalidArgumentException;
use Symfony\Component\Yaml\Yaml;
class YamlConfigurationBuilder extends AbstractConfigurationBuilder
{
/**
* YAML input string
*
* @var string
*/
protected $input;
/**
* Constructor
*
* @param string|null $input
*/
public function __construct($input = null)
{
$this->input = $input;
}
/**
* {@inheritdocs}
*/
public function internalBuild(ConfigurationInterface $configuration)
{
if (null !== $this->input) {
try{
$yml = Yaml::parse($this->input, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
} catch (\Exception $e) {
throw new InvalidArgumentException($e->getMessage(), 0, $e);
}
if (is_string($yml))
{
throw(new \InvalidArgumentException('Yaml could not be parsed, parser detected a string.'));
}
$configuration->importRaw($yml);
}
}
}

View file

@ -0,0 +1,85 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
use Dflydev\DotAccessData\Util as DotAccessDataUtil;
use Symfony\Component\Yaml\Yaml;
class YamlFileConfigurationBuilder extends AbstractConfigurationBuilder
{
/**
* YAML Configuration Filenames
*
* @var array
*/
private $yamlConfigurationFilenames;
/**
* Constructor
*
* @param array $yamlConfigurationFilenames
*/
public function __construct(array $yamlConfigurationFilenames)
{
$this->yamlConfigurationFilenames = $yamlConfigurationFilenames;
}
/**
* {@inheritdocs}
*/
public function internalBuild(ConfigurationInterface $configuration)
{
$config = array();
$imports = array();
foreach ($this->yamlConfigurationFilenames as $yamlConfigurationFilename) {
if (file_exists($yamlConfigurationFilename)) {
$config = DotAccessDataUtil::mergeAssocArray($config, Yaml::parse(file_get_contents($yamlConfigurationFilename)));
if (isset($config['imports'])) {
foreach ((array) $config['imports'] as $file) {
if (0 === strpos($file, '/')) {
// Absolute path
$imports[] = $file;
} else {
if ($realpath = realpath(dirname($yamlConfigurationFilename).'/'.$file)) {
$imports[] = $realpath;
}
}
}
}
}
}
if ($imports) {
$importsBuilder = new static($imports);
// We want to reconfigure the imports builder to have the
// same basic configuration as this instance.
$this->reconfigure($importsBuilder);
$configuration->import($importsBuilder->build());
$internalImports = $configuration->get('imports');
} else {
$internalImports = null;
}
$configuration->importRaw($config);
if ($internalImports) {
foreach ((array) $internalImports as $import) {
$configuration->append('imports', $import);
}
}
return $configuration;
}
}

View file

@ -0,0 +1,89 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
class AbstractConfigurationBuilderTest extends \PHPUnit_Framework_TestCase
{
public function testPlaceholderResolver()
{
$placeholderResolver = $this->getMock('Dflydev\PlaceholderResolver\PlaceholderResolverInterface');
$placeholderResolverFactory = $this->getMock('Dflydev\DotAccessConfiguration\PlaceholderResolverFactoryInterface');
$placeholderResolverFactory
->expects($this->once())
->method('create')
->will($this->returnValue($placeholderResolver))
;
$configurationBuilder = $this->getMockForAbstractClass('Dflydev\DotAccessConfiguration\AbstractConfigurationBuilder');
$configurationBuilder
->expects($this->once())
->method('internalBuild')
;
$configurationBuilder->setPlaceholderResolverFactory($placeholderResolverFactory);
$configurationBuilder->build();
}
public function testReconfigure()
{
$configuration000 = $this->getMock('Dflydev\DotAccessConfiguration\ConfigurationInterface');
$configuration000
->expects($this->exactly(2))
->method('get')
->with($this->equalTo('foo'))
->will($this->returnValue('FOO'))
;
$configuration001 = $this->getMock('Dflydev\DotAccessConfiguration\ConfigurationInterface');
$configuration001
->expects($this->exactly(2))
->method('get')
->with($this->equalTo('bar'))
->will($this->returnValue('BAR'))
;
$placeholderResolver = $this->getMock('Dflydev\PlaceholderResolver\PlaceholderResolverInterface');
$placeholderResolverFactory = $this->getMock('Dflydev\DotAccessConfiguration\PlaceholderResolverFactoryInterface');
$placeholderResolverFactory
->expects($this->exactly(2))
->method('create')
->will($this->returnValue($placeholderResolver))
;
$configurationFactory = $this->getMock('Dflydev\DotAccessConfiguration\ConfigurationFactoryInterface');
$configurationFactory
->expects($this->exactly(2))
->method('create')
->will($this->onConsecutiveCalls($configuration000, $configuration001));
;
$configurationBuilder = $this->getMockForAbstractClass('Dflydev\DotAccessConfiguration\AbstractConfigurationBuilder');
$configurationBuilder->setPlaceholderResolverFactory($placeholderResolverFactory);
$configurationBuilder->setConfigurationFactory($configurationFactory);
$reconfiguredConfigurationBuilder = $this->getMockForAbstractClass('Dflydev\DotAccessConfiguration\AbstractConfigurationBuilder');
$configurationBuilder->reconfigure($reconfiguredConfigurationBuilder);
$configurationTest000 = $configurationBuilder->build();
$configurationTest001 = $reconfiguredConfigurationBuilder->build();
$this->assertEquals('FOO', $configuration000->get('foo'));
$this->assertEquals('FOO', $configurationTest000->get('foo'));
$this->assertEquals('BAR', $configuration001->get('bar'));
$this->assertEquals('BAR', $configurationTest001->get('bar'));
}
}

View file

@ -0,0 +1,39 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
class ConfigurationDataSourceTest extends \PHPUnit_Framework_TestCase
{
public function test()
{
$configuration = $this->getMock('Dflydev\DotAccessConfiguration\Configuration');
$configuration
->expects($this->any())
->method('getRaw')
->will($this->returnValueMap(array(
array('foo', 'bar'),
array('foo', null, true),
array('foo', 'bar', false),
)))
;
$dataSource = new ConfigurationDataSource($configuration);
$this->assertEquals('bar', $dataSource->get('foo'));
$this->assertTrue($dataSource->exists('foo'));
$this->assertEquals('bar', $dataSource->get('foo', false));
$this->assertTrue($dataSource->exists('foo', false));
$this->assertNull($dataSource->get('foo', true));
$this->assertFalse($dataSource->exists('foo', true));
}
}

View file

@ -0,0 +1,21 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
class ConfigurationFactoryTest extends \PHPUnit_Framework_TestCase
{
public function testCreate()
{
$configurationFactory = new ConfigurationFactory;
$configuration = $configurationFactory->create();
}
}

View file

@ -0,0 +1,175 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
class ConfigurationTest extends \PHPUnit_Framework_TestCase
{
protected function getTestData()
{
return array(
'a' => array(
'b' => array(
'c' => 'ABC',
),
),
'abc' => '%a.b.c%',
'abcd' => '%a.b.c.d%',
'some' => array(
'object' => new ConfigurationTestObject('some.object'),
'other' => array(
'object' => new ConfigurationTestObject('some.other.object'),
),
),
'object' => new ConfigurationTestObject('object'),
'an_array' => array('hello'),
);
}
protected function runBasicTests($configuration)
{
$this->assertEquals('ABC', $configuration->get('a.b.c'), 'Direct access by dot notation');
$this->assertEquals('ABC', $configuration->get('abc'), 'Resolved access');
$this->assertEquals('%a.b.c.d%', $configuration->get('abcd'), 'Unresolved access');
$this->assertEquals('object', $configuration->get('object')->key);
$this->assertEquals('some.object', $configuration->get('some.object')->key);
$this->assertEquals('some.other.object', $configuration->get('some.other.object')->key);
$this->assertEquals(array('hello'), $configuration->get('an_array'));
$this->assertEquals('This is ABC', $configuration->resolve('This is %a.b.c%'));
$this->assertNull($configuration->resolve());
}
public function testGet()
{
$configuration = new Configuration($this->getTestData());
$this->runBasicTests($configuration);
}
public function testAppend()
{
$configuration = new Configuration($this->getTestData());
$configuration->append('a.b.c', 'abc');
$configuration->append('an_array', 'world');
$this->assertEquals(array('ABC', 'abc'), $configuration->get('a.b.c'));
$this->assertEquals(array('hello', 'world'), $configuration->get('an_array'));
}
public function testExportRaw()
{
$configuration = new Configuration($this->getTestData());
// Start with "known" expected value.
$expected = $this->getTestData();
$this->assertEquals($expected, $configuration->exportRaw());
// Simulate change on an object to ensure that objects
// are being handled correctly.
$expected['object']->key = 'object (modified)';
// Make the same change in the object that the
// configuration is managing.
$configuration->get('object')->key = 'object (modified)';
$this->assertEquals($expected, $configuration->exportRaw());
}
public function testExport()
{
$configuration = new Configuration($this->getTestData());
// Start with "known" expected value.
$expected = $this->getTestData();
// We have one replacement that is expected to happen.
// It should be represented in the export as the
// resolved value!
$expected['abc'] = 'ABC';
$this->assertEquals($expected, $configuration->export());
// Simulate change on an object to ensure that objects
// are being handled correctly.
$expected['object']->key = 'object (modified)';
// Make the same change in the object that the
// configuration is managing.
$configuration->get('object')->key = 'object (modified)';
$this->assertEquals($expected, $configuration->export());
// Test to make sure that set will result in setting
// a new value and also that export will show this new
// value. (tests "export is dirty" functionality)
$configuration->set('abc', 'ABCD');
$expected['abc'] = 'ABCD';
$this->assertEquals($expected, $configuration->export());
}
public function testExportData()
{
$configuration = new Configuration($this->getTestData());
$data = $configuration->exportData();
// The exportData call should return data filled with
// resolved data.
$this->assertEquals('ABC', $data->get('abc'));
}
public function testImportRaw()
{
$configuration = new Configuration();
$configuration->importRaw($this->getTestData());
$this->runBasicTests($configuration);
}
public function testImport()
{
$configuration = new Configuration();
$configuration->import(new Configuration($this->getTestData()));
$this->runBasicTests($configuration);
}
public function testSetPlaceholderResolver()
{
$placeholderResolver = $this->getMock('Dflydev\PlaceholderResolver\PlaceholderResolverInterface');
$placeholderResolver
->expects($this->once())
->method('resolvePlaceholder')
->with($this->equalTo('foo'))
->will($this->returnValue('bar'))
;
$configuration = new Configuration;
$configuration->setPlaceholderResolver($placeholderResolver);
$this->assertEquals('bar', $configuration->resolve('foo'));
}
}
class ConfigurationTestObject
{
public $key;
public function __construct($key)
{
$this->key = $key;
}
}

View file

@ -0,0 +1,22 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
class PlaceholderResolverFactoryTest extends \PHPUnit_Framework_TestCase
{
public function testCreate()
{
$configuration = $this->getMock('Dflydev\DotAccessConfiguration\Configuration');
$placeholderResolverFactory = new PlaceholderResolverFactory;
$placeholderResolver = $placeholderResolverFactory->create($configuration);
}
}

View file

@ -0,0 +1,34 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
class YamlConfigurationBuilderTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
if (!class_exists('Symfony\Component\Yaml\Yaml')) {
$this->markTestSkipped('The Symfony2 YAML library is not available');
}
}
public function testBuild()
{
$configurationBuilder = new YamlConfigurationBuilder;
$configuration = $configurationBuilder->build();
}
public function testBuildWithData()
{
$configurationBuilder = new YamlConfigurationBuilder('foo: bar');
$configuration = $configurationBuilder->build();
}
}

View file

@ -0,0 +1,38 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dflydev\DotAccessConfiguration;
class YamlFileConfigurationBuilderTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
if (!class_exists('Symfony\Component\Yaml\Yaml')) {
$this->markTestSkipped('The Symfony2 YAML library is not available');
}
}
public function testBuilder()
{
$configurationBuilder = new YamlFileConfigurationBuilder(array(__DIR__.'/fixtures/yamlFileConfigurationBuilderTest-testBuilder.yml'));
$configuration = $configurationBuilder->build();
$this->assertEquals('C', $configuration->get('a.b.c'));
$this->assertEquals('C0', $configuration->get('a0.b0.c0'));
$this->assertEquals('C1', $configuration->get('a1.b1.c1'));
$this->assertEquals(array(
'yamlFileConfigurationBuilderTest-testBuilder-import-level0.yml',
'/tmp/testing-this-file-should-not-exist.yml',
'yamlFileConfigurationBuilderTest-testBuilder-import-level1.yml',
), $configuration->get('imports'));
}
}

View file

@ -0,0 +1,6 @@
imports:
- yamlFileConfigurationBuilderTest-testBuilder-import-level1.yml
a0:
b0:
c0: C0

View file

@ -0,0 +1,7 @@
imports:
- yamlFileConfigurationBuilderTest-testBuilder-import-level0.yml
- /tmp/testing-this-file-should-not-exist.yml
a:
b:
c: C

View file

@ -0,0 +1,13 @@
<?php
/*
* This file is a part of dflydev/dot-access-configuration.
*
* (c) Dragonfly Development Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
$loader = require dirname(__DIR__).'/vendor/autoload.php';