Skip to content

Commit

Permalink
feature #104 deprecate the sensiolabs DI service id and tag prefix (x…
Browse files Browse the repository at this point in the history
…abbuh)

This PR was merged into the 0.8-dev branch.

Discussion
----------

deprecate the sensiolabs DI service id and tag prefix

Commits
-------

e6d99cf deprecate the sensiolabs DI service id and tag prefix
  • Loading branch information
xabbuh committed Jan 31, 2021
2 parents a29e8f9 + e6d99cf commit 4bd4841
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ CHANGELOG
depend on the `qossmic/rich-model-forms-bundle` package instead.
* Deprecated the `SensioLabs` namespace, use the equivalent classes from the `Qossmic` namespace
instead.
* Deprecated all services whose id starts with `sensiolabs.`, use their equivalent ids starting
with `qossmic.` instead.
* Deprecated the `sensiolabs.rich_model_forms.exception_handler` tag, use the `qossmic.rich_model_forms.exception_handler`
tag instead.

0.7.1
-----
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ parameters:
inferPrivatePropertyTypeFromConstructor: true
paths:
- src
reportUnmatchedIgnoredErrors: false
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,27 @@ class RegisterExceptionHandlersPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition('sensiolabs.rich_model_forms.exception_handler.registry')) {
if (!$container->hasDefinition('qossmic.rich_model_forms.exception_handler.registry')) {
return;
}

$exceptionHandlerRegistry = $container->getDefinition('sensiolabs.rich_model_forms.exception_handler.registry');
$exceptionHandlerRegistry = $container->getDefinition('qossmic.rich_model_forms.exception_handler.registry');

$exceptionHandlers = [];
$strategies = [];

foreach ($container->findTaggedServiceIds('qossmic.rich_model_forms.exception_handler') as $id => $tag) {
$class = $container->getParameterBag()->resolveValue($container->getDefinition($id)->getClass());
$exceptionHandlers[$id] = new TypedReference($id, $class);

foreach ($tag as $attributes) {
$strategies[$attributes['strategy']] = $id;
}
}

foreach ($container->findTaggedServiceIds('sensiolabs.rich_model_forms.exception_handler') as $id => $tag) {
trigger_deprecation('sensiolabs-de/rich-model-forms-bundle', '0.8', sprintf('The "sensiolabs.rich_model_forms.exception_handler" tag used by the service with the id "%s" is deprecated. Use the "qossmic.rich_model_forms.exception_handler" tag instead.', $id));

$class = $container->getParameterBag()->resolveValue($container->getDefinition($id)->getClass());
$exceptionHandlers[$id] = new TypedReference($id, $class);

Expand Down
21 changes: 21 additions & 0 deletions src/Qossmic/DependencyInjection/RichModelFormsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
namespace Qossmic\RichModelForms\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Compiler\AliasDeprecatedPublicServicesPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
Expand All @@ -28,5 +30,24 @@ public function load(array $configs, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');

foreach ($container->getDefinitions() as $id => $definition) {
if (0 !== strpos($id, 'qossmic.')) {
continue;
}

$aliasId = str_replace('qossmic.', 'sensiolabs.', $id);
$alias = new Alias($id);

if (class_exists(AliasDeprecatedPublicServicesPass::class)) {
/* @phpstan-ignore-next-line */
$alias->setDeprecated('sensiolabs/rich-model-forms-bundle', '0.8', sprintf('The "%%alias_id%% alias is deprecated, use "%s" instead.', $id));
} else {
/* @phpstan-ignore-next-line */
$alias->setDeprecated(true, sprintf('Since sensiolabs/rich-model-forms-bundle 0.8: The "%%alias_id%% alias is deprecated, use "%s" instead.', $id));
}

$container->setAlias($aliasId, $alias);
}
}
}
20 changes: 10 additions & 10 deletions src/Qossmic/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@
<services>
<defaults public="false" />

<service id="sensiolabs.rich_model_forms.type_extension" class="Qossmic\RichModelForms\Extension\RichModelFormsTypeExtension">
<service id="qossmic.rich_model_forms.type_extension" class="Qossmic\RichModelForms\Extension\RichModelFormsTypeExtension">
<argument type="service" id="property_accessor" />
<argument type="service" id="sensiolabs.rich_model_forms.exception_handler.registry" />
<argument type="service" id="sensiolabs.rich_model_forms.form_exception_handler" />
<argument type="service" id="qossmic.rich_model_forms.exception_handler.registry" />
<argument type="service" id="qossmic.rich_model_forms.form_exception_handler" />
<tag name="form.type_extension" extended-type="Symfony\Component\Form\Extension\Core\Type\FormType" />
</service>

<service id="sensiolabs.rich_model_forms.form_exception_handler" class="Qossmic\RichModelForms\ExceptionHandling\FormExceptionHandler">
<argument type="service" id="sensiolabs.rich_model_forms.exception_handler.registry" />
<service id="qossmic.rich_model_forms.form_exception_handler" class="Qossmic\RichModelForms\ExceptionHandling\FormExceptionHandler">
<argument type="service" id="qossmic.rich_model_forms.exception_handler.registry" />
<argument type="service" id="translator" on-invalid="ignore" />
<argument type="string">%validator.translation_domain%</argument>
</service>

<service id="sensiolabs.rich_model_forms.exception_handler.registry" class="Qossmic\RichModelForms\ExceptionHandling\ExceptionHandlerRegistry">
<service id="qossmic.rich_model_forms.exception_handler.registry" class="Qossmic\RichModelForms\ExceptionHandling\ExceptionHandlerRegistry">
<argument>null</argument> <!-- service locator will be injected during compilation -->
<argument type="collection" /> <!-- exception handling strategies, will be injected during compilation -->
</service>

<service id="sensiolabs.rich_model_forms.exception_handler.strategy.argument_type_mismatch" class="Qossmic\RichModelForms\ExceptionHandling\ArgumentTypeMismatchExceptionHandler">
<tag name="sensiolabs.rich_model_forms.exception_handler" strategy="type_error" />
<service id="qossmic.rich_model_forms.exception_handler.strategy.argument_type_mismatch" class="Qossmic\RichModelForms\ExceptionHandling\ArgumentTypeMismatchExceptionHandler">
<tag name="qossmic.rich_model_forms.exception_handler" strategy="type_error" />
</service>

<service id="sensiolabs.rich_model_forms.exception_handler.strategy.fallback" class="Qossmic\RichModelForms\ExceptionHandling\FallbackExceptionHandler">
<tag name="sensiolabs.rich_model_forms.exception_handler" strategy="fallback" />
<service id="qossmic.rich_model_forms.exception_handler.strategy.fallback" class="Qossmic\RichModelForms\ExceptionHandling\FallbackExceptionHandler">
<tag name="qossmic.rich_model_forms.exception_handler" strategy="fallback" />
</service>
</services>
</container>
4 changes: 2 additions & 2 deletions tests/Fixtures/DependencyInjection/PublicTestAliasPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public function process(ContainerBuilder $container): void
$testAliases = [];

foreach ($container->getDefinitions() as $id => $definition) {
if (0 === strpos($id, 'sensiolabs.rich_model_forms.')) {
if (0 === strpos($id, 'qossmic.rich_model_forms.')) {
$container->setAlias('test.'.$id, new Alias($id, true));
$testAliases['test.'.$id] = $definition->getClass();
}
}

$container->setParameter('sensiolabs.rich_model_forms.test_service_aliases', $testAliases);
$container->setParameter('qossmic.rich_model_forms.test_service_aliases', $testAliases);
}
}
8 changes: 4 additions & 4 deletions tests/Integration/ServiceContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ public function testServicesCanBeBuilt(): void
{
$container = $this->bootKernel()->getContainer();

foreach ($container->getParameter('sensiolabs.rich_model_forms.test_service_aliases') as $id => $type) {
foreach ($container->getParameter('qossmic.rich_model_forms.test_service_aliases') as $id => $type) {
$this->assertInstanceOf($type, $container->get($id));
}
}

public function testArgumentTypeMismatchExceptionHandlingStrategyIsRegistered(): void
{
$container = $this->bootKernel()->getContainer();
$exceptionHandlerRegistry = $container->get('test.sensiolabs.rich_model_forms.exception_handler.registry');
$exceptionHandlerRegistry = $container->get('test.qossmic.rich_model_forms.exception_handler.registry');

$this->assertInstanceOf(ArgumentTypeMismatchExceptionHandler::class, $exceptionHandlerRegistry->get('type_error'));
}

public function testFallbackExceptionHandlingStrategyIsRegistered(): void
{
$container = $this->bootKernel()->getContainer();
$exceptionHandlerRegistry = $container->get('test.sensiolabs.rich_model_forms.exception_handler.registry');
$exceptionHandlerRegistry = $container->get('test.qossmic.rich_model_forms.exception_handler.registry');

$this->assertInstanceOf(FallbackExceptionHandler::class, $exceptionHandlerRegistry->get('fallback'));
}
Expand All @@ -51,7 +51,7 @@ public function testExceptionIsThrownIfExceptionHandlingStrategyIsNotKnown(): vo
$this->expectException(\InvalidArgumentException::class);

$container = $this->bootKernel()->getContainer();
$exceptionHandlerRegistry = $container->get('test.sensiolabs.rich_model_forms.exception_handler.registry');
$exceptionHandlerRegistry = $container->get('test.qossmic.rich_model_forms.exception_handler.registry');

$exceptionHandlerRegistry->get('unknown');
}
Expand Down

0 comments on commit 4bd4841

Please sign in to comment.