Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved interfaces and naming #18

Merged
merged 10 commits into from
Oct 18, 2015
17 changes: 13 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,31 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 0.3.0 TBD
## 0.3.0 (2015-10-18)

### Added

* [#8](https://github.com/sandrokeil/interop-config/issues/8): Introducing HasOptionalOptions Interface
* [#9](https://github.com/sandrokeil/interop-config/issues/9): Introducing HasDefaultOptions Interface
* [#9](https://github.com/sandrokeil/interop-config/issues/9): Introducing ProvidesDefaultOptions interface
* [#13](https://github.com/sandrokeil/interop-config/issues/13): Support for recursive mandatory options check
* `canRetrieveOptions()` to `ConfigurationTrait` to perform the options check without throwing an exception
* `optionsWithFallback()` to `ConfigurationTrait` which uses default options if config can not be retrieved
* OptionNotFoundException and MandatoryOptionNotFoundException extends OutOfBoundsException instead of RuntimeException
* Check if retrieved options are an array or an instance of ArrayAccess
* Benchmark suite
* Updated documentation

### Deprecated

* Nothing

### Removed

* Nothing
* `HasConfig` interface, was renamed to `RequiresConfig`
* `HasContainer` interface, was renamed to `RequiresContainerId`
* `HasMandatoryOptions` interface, was renamed to `RequiresMandatoryOptions`
* `HasDefaultOptions` interface, was renamed to `ProvidesDefaultOptions`
* `ObtainsOptions` interface, was merged in `RequiresConfig`
* `OptionalOptions` interface, can be achieved via `ProvidesDefaultOptions`

### Fixed

Expand Down
40 changes: 29 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

> You want to configure your factories?

> You want to check automatically for mandatory params?
> You want to reduce your factory boilerplate code?

> You want to check automatically for mandatory options?

> You want to have an uniform config structure?

Expand All @@ -24,7 +26,7 @@ and to create configuration files.

> Please join the discussion about the [PSR config proposal](https://github.com/php-fig/fig-standards/pull/620).

* **Well tested.** Besides unit test and continuous integration/inspection this solution is also ~~ready for production use~~.
* **Well tested.** Besides unit test and continuous integration/inspection this solution is also ready for production use.
* **Framework agnostic** This PHP library does not depends on any framework but you can use it with your favourite framework.
* **Every change is tracked**. Want to know whats new? Take a look at [CHANGELOG.md](https://github.com/sandrokeil/interop-config/blob/master/CHANGELOG.md)
* **Listen to your ideas.** Have a great idea? Bring your tested pull request or open a new issue. See [CONTRIBUTING.md](CONTRIBUTING.md)
Expand Down Expand Up @@ -65,11 +67,11 @@ the logic to retrieve the options from a configuration. See documentation for mo

```php
use Interop\Config\ConfigurationTrait;
use Interop\Config\HasMandatoryOptions;
use Interop\Config\HasContainerId;
use Interop\Config\RequiresContainerId;
use Interop\Config\RequiresMandatoryOptions;
use Interop\Container\ContainerInterface;

class MyDBALConnectionFactory implements HasMandatoryOptions, HasContainerId
class MyDBALConnectionFactory implements RequiresContainerId, RequiresMandatoryOptions
{
use ConfigurationTrait;

Expand All @@ -78,7 +80,7 @@ class MyDBALConnectionFactory implements HasMandatoryOptions, HasContainerId
// get options for doctrine.connection.orm_default
$options = $this->options($container->get('config'));

// mandatory options check is automatically done by MandatoryOptionsInterface
// mandatory options check is automatically done by RequiresMandatoryOptions

$driverClass = $options['driverClass'];
$params = $options['params'];
Expand Down Expand Up @@ -125,7 +127,7 @@ class MyDBALConnectionFactory implements HasMandatoryOptions, HasContainerId
*/
public function mandatoryOptions()
{
return ['driverClass', 'params'];
return ['params' => ['user', 'password', 'dbname']];
}
}
```
Expand All @@ -139,22 +141,38 @@ Put the following into your composer.json

{
"require": {
"sandrokeil/interop-config": "1.0.x-dev"
"sandrokeil/interop-config": "^0.3"
}
}

## Documentation
For the latest online documentation you can visit [http://sandrokeil.github.io/interop-config/](http://sandrokeil.github.io/interop-config/ "Latest interop-config documentation").

Documentation is [in the doc tree](doc/), and can be compiled using [bookdown](http://bookdown.io) and [Docker](https://www.docker.com/)

```console
$ docker run -i -t=false --rm -v $(pwd):/app sandrokeil/bookdown doc/bookdown.json
$ docker run -i -t=false --rm -p 8080:8080 -v $(pwd):/app php:5.6-cli php -S 0.0.0.0:8080 -t /app/doc/html
$ docker run -it --rm -v $(pwd):/app sandrokeil/bookdown doc/bookdown.json
$ docker run -it --rm -p 8080:8080 -v $(pwd):/app php:5.6-cli php -S 0.0.0.0:8080 -t /app/doc/html
```

or make sure bookdown is installed globally via composer and `$HOME/.composer/vendor/bin` is on your `$PATH`.

```console
$ bookdown doc/bookdown.json
$ php -S 0.0.0.0:8080 -t doc/html/ # then browse to http://localhost:8080/
$ php -S 0.0.0.0:8080 -t doc/html/
```

Then browse to [http://localhost:8080/](http://localhost:8080/)

## Benchmarks
The benchmarks uses [PHPBench](https://github.com/phpbench/phpbench) and can be started by the following command:

```console
$ ./vendor/bin/phpbench run --report=aggregate
```

or with Docker

```console
$ docker run --rm -it --volume $(pwd):/app sandrokeil/php:5.6-cli php ./vendor/bin/phpbench run --report=aggregate
```
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use InteropTest\Config\TestAsset\ConnectionDefaultOptionsConfiguration;

/**
* @beforeMethod classSetUp
* @BeforeMethods({"classSetUp"})
*/
class HasDefaultOptions
class ProvidesDefaultOptions
{
private $config;

Expand All @@ -32,8 +32,8 @@ public function classSetUp()
/**
* Retrieve options
*
* @revs 1000
* @iterations 10
* @Revs(10000)
* @Iterations(10)
*/
public function benchOptions()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use InteropTest\Config\TestAsset\ConnectionConfiguration;

/**
* @beforeMethod classSetUp
* @BeforeMethods({"classSetUp"})
*/
class HasConfigBench
class RequiresConfigBench
{
private $config;

Expand All @@ -32,8 +32,8 @@ public function classSetUp()
/**
* Retrieve options
*
* @revs 1000
* @iterations 10
* @Revs(10000)
* @Iterations(10)
*/
public function benchOptions()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use InteropTest\Config\TestAsset\ConnectionContainerIdConfiguration;

/**
* @beforeMethod classSetUp
* @BeforeMethods({"classSetUp"})
*/
class HasContainerId
class RequiresContainerId
{
private $config;

Expand All @@ -32,8 +32,8 @@ public function classSetUp()
/**
* Retrieve options
*
* @revs 1000
* @iterations 10
* @Revs(10000)
* @Iterations(10)
*/
public function benchOptions()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use InteropTest\Config\TestAsset\ConnectionMandatoryConfiguration;

/**
* @beforeMethod classSetUp
* @BeforeMethods({"classSetUp"})
*/
class HasMandatoryOptions
class RequiresMandatoryOptions
{
private $config;

Expand All @@ -32,8 +32,8 @@ public function classSetUp()
/**
* Retrieve options
*
* @revs 1000
* @iterations 10
* @Revs(10000)
* @Iterations(10)
*/
public function benchOptions()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use InteropTest\Config\TestAsset\ConnectionMandatoryContainerIdConfiguration;

/**
* @beforeMethod classSetUp
* @BeforeMethods({"classSetUp"})
*/
class HasMandatoryOptionsContainerId
class RequiresMandatoryOptionsContainerId
{
private $config;

Expand All @@ -32,8 +32,8 @@ public function classSetUp()
/**
* Retrieve options
*
* @revs 1000
* @iterations 10
* @Revs(10000)
* @Iterations(10)
*/
public function benchOptions()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use InteropTest\Config\TestAsset\ConnectionMandatoryRecursiveContainerIdConfiguration;

/**
* @beforeMethod classSetUp
* @BeforeMethods({"classSetUp"})
*/
class HasMandatoryOptionsRecursiveContainerId
class RequiresMandatoryOptionsRecursiveContainerId
{
private $config;

Expand All @@ -32,8 +32,8 @@ public function classSetUp()
/**
* Retrieve options
*
* @revs 1000
* @iterations 10
* @Revs(10000)
* @Iterations(10)
*/
public function options()
{
Expand Down
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"phpunit/phpunit": "~4.8",
"phpunit/php-invoker": "~1.1",
"squizlabs/php_codesniffer": "~2.3",
"phpbench/phpbench": "dev-master"
"phpbench/phpbench": "^0.5",
"tobiju/bookdown-bootswatch-templates": "1.0.x-dev"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand All @@ -57,12 +58,14 @@
},
"archive": {
"exclude": [
".coveralls.yml",
".scrutinizer.yml",
".travis.yml",
"benchmark",
"test",
"build",
"phpbench.json.dist",
"phpunit.xml*",
".travis.yml",
".scrutinizer.yml",
".coveralls.yml"
"test"
]
}
}
Loading