Skip to content

Commit

Permalink
Merge pull request #10 from 21TORR/next
Browse files Browse the repository at this point in the history
Properly set up `Extension::getConfiguration()`
  • Loading branch information
apfelbox authored Oct 23, 2024
2 parents 323b46f + a0483c1 commit 3541a44
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2.3.1
=====

* (improvement) Properly set up `Extension::getConfiguration()` for the extensions.


2.3.0
=====

Expand Down
18 changes: 15 additions & 3 deletions src/Bundle/BundleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Torr\BundleHelpers\Bundle;

use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -28,8 +29,9 @@ public function __construct (
}

/**
* @inheritDoc
*
*/
#[\Override]
public function load (array $configs, ContainerBuilder $container) : void
{
$configDir = "{$this->bundle->getPath()}/config";
Expand All @@ -42,8 +44,9 @@ public function load (array $configs, ContainerBuilder $container) : void
}

/**
* @inheritDoc
*
*/
#[\Override]
public function getAlias () : string
{
if (null !== $this->alias)
Expand All @@ -53,7 +56,7 @@ public function getAlias () : string

$className = \get_class($this->bundle);

if ('Bundle' !== substr($className, -6))
if (!str_ends_with($className, 'Bundle'))
{
throw new BundleHelpersException(sprintf(
"The bundle does not follow the naming convention; you must pass an explicit alias. Its name should end on 'Bundle', but it is '%s'.",
Expand All @@ -68,4 +71,13 @@ public function getAlias () : string

return Container::underscore($classBaseName);
}

/**
*
*/
#[\Override]
public function getConfiguration (array $config, ContainerBuilder $container) : ?ConfigurationInterface
{
return null;
}
}
12 changes: 11 additions & 1 deletion src/Bundle/ConfigurableBundleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,23 @@ public function __construct (
}

/**
* @inheritDoc
*
*/
#[\Override]
public function load (array $configs, ContainerBuilder $container) : void
{
parent::load($configs, $container);

$config = $this->processConfiguration($this->config, $configs);
($this->callback)($config, $container);
}

/**
*
*/
#[\Override]
public function getConfiguration (array $config, ContainerBuilder $container) : ?ConfigurationInterface
{
return $this->config;
}
}

0 comments on commit 3541a44

Please sign in to comment.