Skip to content

Commit

Permalink
Remove WebauthnStimulusExtension and refactor WebauthnStimulusBundle
Browse files Browse the repository at this point in the history
This commit removes the WebauthnStimulusExtension file as it is no longer necessary. Instead, the necessary methods to check AssetMapperAvailability and prepend extensions have been moved to the WebauthnStimulusBundle file. This refactoring simplifies our codebase by reducing redundant components and enhancing the readability of the code.
  • Loading branch information
Spomky committed Jul 12, 2024
1 parent cc3f703 commit 66000ed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 60 deletions.
51 changes: 0 additions & 51 deletions src/stimulus/src/DependencyInjection/WebauthnStimulusExtension.php

This file was deleted.

38 changes: 29 additions & 9 deletions src/stimulus/src/WebauthnStimulusBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,40 @@

namespace Webauthn\Stimulus;

use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Webauthn\Stimulus\DependencyInjection\WebauthnStimulusExtension;
use function dirname;
use Symfony\Component\AssetMapper\AssetMapperInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;

final class WebauthnStimulusBundle extends Bundle
final class WebauthnStimulusBundle extends AbstractBundle
{
public function getContainerExtension(): ExtensionInterface
public function prependExtension(ContainerConfigurator $container, ContainerBuilder $builder): void
{
return new WebauthnStimulusExtension();
if (! $this->isAssetMapperAvailable($builder)) {
return;
}

$builder->prependExtensionConfig('framework', [
'asset_mapper' => [
'paths' => [
__DIR__ . '/../../assets/dist' => '@web-auth/webauthn-stimulus',
],
],
]);
}

public function getPath(): string
private function isAssetMapperAvailable(ContainerBuilder $container): bool
{
return dirname(__DIR__);
if (! interface_exists(AssetMapperInterface::class)) {
return false;
}

// check that FrameworkBundle is installed
$bundlesMetadata = $container->getParameter('kernel.bundles_metadata');
if (! isset($bundlesMetadata['FrameworkBundle'])) {
return false;
}

return is_file($bundlesMetadata['FrameworkBundle']['path'] . '/Resources/config/asset_mapper.php');
}
}

0 comments on commit 66000ed

Please sign in to comment.