Skip to content

Commit

Permalink
Add NoSynthesizerDefined
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Feb 18, 2017
1 parent e7fd0d6 commit c02e7b5
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 7 deletions.
36 changes: 30 additions & 6 deletions README.md
Expand Up @@ -32,6 +32,29 @@ directories and are usually named after the config they are used to synthesize.



## The configuration

The configuration is represented by a [Config][] instance, which is used as an array to access
specific configurations.

The following example demonstrates how to obtain the configuration `routes`:

```php
<?php

/* @var \ICanBoogie\Config $config */

$routing_config = $config['routes'];
```

A [NoSynthesizerDefined][] exception is thrown if there is no synthesizer defined for a
configuration. A [NoFragmentDefined][] exception is thrown if there is no fragment defined for a
configuration.





## Synthesizing a configuration

The `synthesize()` method of the [Config][] instance is used to synthesize a configuration.
Expand Down Expand Up @@ -130,7 +153,7 @@ $config = new Config($paths, [




## Caching synthesized configurations

Caching synthesized configurations removes the cost of synthesizing configurations by reusing the
Expand Down Expand Up @@ -186,8 +209,8 @@ cloned with the following command line:

## Documentation

The package is documented as part of the [ICanBoogie](http://icanboogie.org/) framework
[documentation](http://icanboogie.org/docs/). You can generate the documentation for the package
The package is documented as part of the [ICanBoogie](https://icanboogie.org/) framework
[documentation](https://icanboogie.org/docs/). You can generate the documentation for the package
and its dependencies with the `make doc` command. The documentation is generated in the `docs`
directory. [ApiGen](http://apigen.org/) is required. You can later clean the directory with
the `make clean` command.
Expand Down Expand Up @@ -222,6 +245,7 @@ The package is continuously tested by [Travis CI](http://about.travis-ci.org/).
[icanboogie/event]: https://github.com/ICanBoogie/Event
[ICanBoogie]: https://github.com/ICanBoogie

[Config]: https://icanboogie.org/api/config/1.1/class-ICanBoogie.Config.html
[Storage]: https://icanboogie.org/api/storage/2.0/class-ICanBoogie.Storage.Storage.html
[NoFragmentDefined]: https://icanboogie.org/api/config/master/class-ICanBoogie.NoFragmentDefined.html
[Config]: https://icanboogie.org/api/config/1.2/class-ICanBoogie.Config.html
[NoFragmentDefined]: https://icanboogie.org/api/config/1.2/class-ICanBoogie.Config.NoFragmentDefined.html
[NoSynthesizerDefined]: https://icanboogie.org/api/config/1.2/class-ICanBoogie.Config.NoSynhtesizerDefined.html
[Storage]: https://icanboogie.org/api/storage/2.0/class-ICanBoogie.Storage.Storage.html
3 changes: 2 additions & 1 deletion lib/Config.php
Expand Up @@ -12,6 +12,7 @@
namespace ICanBoogie;

use ICanBoogie\Config\NoFragmentDefined;
use ICanBoogie\Config\NoSynthesizerDefined;
use ICanBoogie\Storage\Storage;

/**
Expand Down Expand Up @@ -126,7 +127,7 @@ public function offsetGet($id)

if (empty($this->synthesizers[$id]))
{
throw new \InvalidArgumentException("There is no constructor defined to build the $id config.");
throw new NoSynthesizerDefined($id);
}

list($synthesizer, $from) = $this->synthesizers[$id] + [ 1 => $id ];
Expand Down
38 changes: 38 additions & 0 deletions lib/Config/NoSynthesizerDefined.php
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <olivier.laviale@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie\Config;

/**
* Exception thrown in attempt to build a configuration without synthesizer defined.
*/
class NoSynthesizerDefined extends \LogicException
{
/**
* @param string $id
* @param \Exception|null $previous
*/
public function __construct($id, \Exception $previous = null)
{
parent::__construct($this->format_message($id), 500, $previous);
}

/**
* @param $id
*
* @return string
*/
protected function format_message($id)
{
return "There is no synthesizer defined to build configuration `$id`."
. " (https://icanboogie.org/docs/4.0/config#declaring-synthesizers)";
}
}
10 changes: 10 additions & 0 deletions tests/ConfigTest.php
Expand Up @@ -27,6 +27,16 @@ static public function setupBeforeClass()
];
}

/**
* @expectedException \ICanBoogie\Config\NoSynthesizerDefined
*/
public function test_should_throw_exception_on_undefined_synthesizer()
{
$name = 'container';
$configs = new Config(self::$paths);
$configs[$name];
}

/**
* @expectedException \ICanBoogie\Config\NoFragmentDefined
*/
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/config01/container.php
@@ -0,0 +1,5 @@
<?php

return [

];

0 comments on commit c02e7b5

Please sign in to comment.