Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #37 from bestit/feature/autoconfiguration
Browse files Browse the repository at this point in the history
#31 #32 Add support for autoconfiguration
  • Loading branch information
migo315 committed Jul 5, 2018
2 parents 995b95b + 8439a74 commit 7ffd535
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
### Added
- \#26 Add feature name advice in documentation @migo315
- Add `php-mock` as dev dependency and add missing contentful configurator test @migo315
- \#31 Add support for auto configuration for `FeatureActivatorInterface` @migo315
- \#32 Add support for auto configuration for `ContectDecoratorInterface` @migo315

### Removed
- Remove unneeded models and bags (just internal stuff) @migo315
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Flagception
**Feature toggle bundle on steroids!** Flagception is a simple and powerful feature toggle system for php.
This bundle integrates the [Flagception PHP Libary](https://packagist.org/packages/flagception/flagception) for symfony 2.7 to 4.0 (and php 5.6 to php7.2).
This bundle integrates the [Flagception PHP Libary](https://packagist.org/packages/flagception/flagception) for symfony 2.7 to 4.1 (and php 5.6 to php7.2).

[![Latest Stable Version](https://poser.pugx.org/flagception/flagception-bundle/v/stable)](https://packagist.org/packages/flagception/flagception-bundle)
[![Coverage Status](https://coveralls.io/repos/github/bestit/flagception-bundle/badge.svg?branch=master)](https://coveralls.io/github/bestit/flagception-bundle?branch=master)
Expand Down
2 changes: 2 additions & 0 deletions docs/activator.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Just create a service class, implements `FeatureActivatorInterface`, tag it with
priority tag. The feature manager iterate through all activators and check the state with the `isActive` method until one activator
returns true. If an activator returns true, no further activators will be requested.

This bundle supports [autoconfiguration](https://symfony.com/blog/new-in-symfony-3-3-service-autoconfiguration) for `FeatureActivatorInterface` from Symfony 3.3.

Example class to activate all features for admins:
```php
# AdminActivator.php
Expand Down
2 changes: 2 additions & 0 deletions docs/constraint.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ For adding a global variable, just create a ContextDecorator class and implement
You have to create two methods. The `getName` method return the ContextDecorator name and the `decorate` method
will extend the context data with your variables. Remember to tag the service with `flagception.context_decorator`.

This bundle supports [autoconfiguration](https://symfony.com/blog/new-in-symfony-3-3-service-autoconfiguration) for `ContextDecoratorInterface` from Symfony 3.3.

As the feature manager may serializes context data in future (eg. for caching),
you should not store objects that cannot be serialized (like PDO objects) or you need to provide your own serialize() method.

Expand Down
12 changes: 12 additions & 0 deletions src/DependencyInjection/FlagceptionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace Flagception\Bundle\FlagceptionBundle\DependencyInjection;

use Exception;
use Flagception\Activator\FeatureActivatorInterface;
use Flagception\Bundle\FlagceptionBundle\DependencyInjection\Configurator\ActivatorConfiguratorInterface;
use Flagception\Decorator\ContextDecoratorInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
Expand Down Expand Up @@ -48,6 +50,16 @@ public function load(array $configs, ContainerBuilder $container)

$configurator->addActivator($container, $config['activators'][$name], $config['features']);
}

if (method_exists($container, 'registerForAutoconfiguration') === true) {
$container
->registerForAutoconfiguration(FeatureActivatorInterface::class)
->addTag('flagception.activator');

$container
->registerForAutoconfiguration(ContextDecoratorInterface::class)
->addTag('flagception.context_decorator');
}
}

/**
Expand Down
29 changes: 29 additions & 0 deletions tests/DependencyInjection/FlagceptionExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Flagception\Tests\FlagceptionBundle\DependencyInjection;

use Flagception\Activator\FeatureActivatorInterface;
use Flagception\Bundle\FlagceptionBundle\DependencyInjection\FlagceptionExtension;
use Flagception\Decorator\ContextDecoratorInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
Expand Down Expand Up @@ -152,4 +154,31 @@ public function testRoutingMetadataSubscriberEnabledByString()
$definition = $this->container->getDefinition('flagception.listener.routing_metadata_subscriber');
static::assertTrue($definition->hasTag('kernel.event_subscriber'));
}

/**
* Test that annotation subscriber is disabled
*
* @return void
*/
public function testAutConfiguration()
{
if (method_exists($this->container, 'registerForAutoconfiguration') === false) {
$this->markTestSkipped('Only since Symfony 3.3');
}

$config = [];

$extension = new FlagceptionExtension();
$extension->load($config, $this->container);

$activatorChildDefinition = $this->container->getAutoconfiguredInstanceof()[FeatureActivatorInterface::class];
static::assertEquals([
'flagception.activator' => [[]]
], $activatorChildDefinition->getTags());

$contextChildDefinition = $this->container->getAutoconfiguredInstanceof()[ContextDecoratorInterface::class];
static::assertEquals([
'flagception.context_decorator' => [[]]
], $contextChildDefinition->getTags());
}
}

0 comments on commit 7ffd535

Please sign in to comment.