Skip to content

Commit

Permalink
Add ContainerConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Feb 19, 2017
1 parent 74c5e29 commit 16ab0a6
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 11 deletions.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,27 @@ $container = $proxy->container;



## Configuring the container

The container is configured using `container` configuration fragments. Currently, only the
[`USE_CACHING`][] constant is defined:

```php
<?php

namespace ICanBoogie\Binding\SymfonyDependencyInjection;

return [

ContainerConfig::USE_CACHING => true

];
```





----------


Expand Down Expand Up @@ -171,8 +192,9 @@ The package is continuously tested by [Travis CI](http://about.travis-ci.org/).



[ContainerProxy]: https://api.icanboogie.org/bind-symfony-dependency-injection/latest/
[documentation]: https://api.icanboogie.org/service/latest/
[ContainerProxy]: https://icanboogie.org/api/bind-symfony-dependency-injection/master/
[`USE_CACHING`]: https://icanboogie.org/api/bind-symfony-dependency-injection/master/class-ICanBoogie.Binding.SymfonyDependencyInjection.ContainerConfig.html#USE_CACHING
[documentation]: https://icanboogie.org/api/service/master/

[ICanBoogie]: https://icanboogie.org
[prototype system]: https://icanboogie.org/docs/4.0/prototypes
Expand Down
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependency",
"injection"
],
"homepage": "http://icanboogie.org/",
"homepage": "https://icanboogie.org/",
"license": "BSD-3-Clause",
"authors": [
{
Expand Down Expand Up @@ -40,19 +40,22 @@
}
},
"autoload-dev": {
"files": [
"tests/Application.php"
],
"psr-4": {
"ICanBoogie\\Binding\\SymfonyDependencyInjection\\": "tests/lib/"
}
},
"classmap": [
"tests/Application.php"
]
},
"scripts": {
"post-autoload-dump": "ICanBoogie\\Autoconfig\\Hooks::on_autoload_dump"
},
"extra": {
"icanboogie": {
"config-path": "config"
"config-path": "config",
"config-constructor": {
"container": "merge"
}
}
}
}
18 changes: 18 additions & 0 deletions config/container.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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\Binding\SymfonyDependencyInjection;

return [

ContainerConfig::USE_CACHING => false

];
29 changes: 29 additions & 0 deletions lib/ContainerConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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\Binding\SymfonyDependencyInjection;

interface ContainerConfig
{
/**
* Fragment name for the container configuration.
*/
const FRAGMENT_FOR_CONTAINER = 'container';

/**
* Whether the compiled container should be cached.
*
* **Note:** Changes to services won't apply until the compiled container is re-created.
* You can use `icanboogie clear cache` or delete the file for the compiled container to
* be updated.
*/
const USE_CACHING = 'use_caching';
}
13 changes: 11 additions & 2 deletions lib/ContainerProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@ class ContainerProxy
const SERVICE_APP = 'app';
const SERVICE_CONTAINER = 'container';
const CONFIG_FILENAME = 'services.yml';
const USE_CACHING = true;
const DONT_USE_CACHING = false;

/**
* @var Application
*/
private $app;

/**
* @var bool
*/
private $use_caching;

/**
* @var Container
*/
Expand All @@ -54,10 +61,12 @@ protected function get_container()
* @codeCoverageIgnoreStart
*
* @param Application $app
* @param bool $use_caching
*/
public function __construct(Application $app)
public function __construct(Application $app, $use_caching = self::DONT_USE_CACHING)
{
$this->app = $app;
$this->use_caching = $use_caching;
}
// @codeCoverageIgnoreEnd

Expand All @@ -80,7 +89,7 @@ private function instantiate_container()
$class = 'ApplicationContainer';
$pathname = ContainerPathname::from($app);

if (!file_exists($pathname))
if (!$this->use_caching || !file_exists($pathname))
{
$container = $this->create_container();
$this->dump_container($container, $pathname, $class);
Expand Down
5 changes: 4 additions & 1 deletion lib/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ class Hooks
*/
static public function on_app_boot(Application\BootEvent $event, Application $app)
{
ServiceProvider::define(new ContainerProxy($app));
ServiceProvider::define(new ContainerProxy(
$app,
$app->configs[ContainerConfig::FRAGMENT_FOR_CONTAINER][ContainerConfig::USE_CACHING]
));
}
// @codeCoverageIgnoreEnd

Expand Down

0 comments on commit 16ab0a6

Please sign in to comment.