Skip to content

Commit

Permalink
Deprecated BundleExtension and ConfigurableBundleExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Eichinger committed Jul 1, 2020
1 parent 89f443c commit 56e61ed
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 70 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
7.13.2 (unreleased)
======

* (deprecation) Deprecate `BundleExtension` and `ConfigurableBundleExtension`. Please use the respective versions from `becklyn/rad-bundles` instead.


7.13.1
======

Expand Down
1 change: 1 addition & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* The entity usage integration was removed. Migrate to `becklyn/entity-admin`.
* `StatsCounter::log()` was removed. Use `StatsCounter::debug/warning/critical()` instead.
* The `InvalidSortOperationException` exception was removed. There is no replacement.
* The classes `BundleExtension` and `ConfigurableBundleExtension` have been removed. Please use the respective versions from `becklyn/rad-bundles` instead.


6.x to 7.0
Expand Down
98 changes: 55 additions & 43 deletions src/Bundle/BundleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,83 @@

namespace Becklyn\RadBundle\Bundle;

use Becklyn\RadBundles\Bundle\BundleExtension as NewBundleExtension;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;

/**
* Base class to use in your bundle to easily create an extension.
*/
class BundleExtension extends Extension
if (\class_exists(NewBundleExtension::class))
{
/** @var BundleInterface */
private $bundle;


/** @var string|null */
private $alias;


/**
*/
public function __construct (
BundleInterface $bundle,
?string $alias = null
)
class BundleExtension extends NewBundleExtension
{
$this->bundle = $bundle;
$this->alias = $alias;
}

}
else
{
/**
* @inheritDoc
* Base class to use in your bundle to easily create an extension.
*
* @deprecated Please use the version from `becklyn/rad-bundles` instead.
*/
public function load (array $configs, ContainerBuilder $container) : void
class BundleExtension extends Extension
{
// first try Symfony 5+ structure
$configDir = "{$this->bundle->getPath()}/config";
/** @var BundleInterface */
private $bundle;


// then fall back to legacy structure
if (!\is_dir($configDir))
/** @var string|null */
private $alias;


/**
*/
public function __construct (
BundleInterface $bundle,
?string $alias = null
)
{
$configDir = "{$this->bundle->getPath()}/Resources/config";
$this->bundle = $bundle;
$this->alias = $alias;
}

if (\is_file("{$configDir}/services.yaml"))
/**
* @inheritDoc
*/
public function load (array $configs, ContainerBuilder $container) : void
{
$loader = new YamlFileLoader($container, new FileLocator($configDir));
$loader->load("services.yaml");
// first try Symfony 5+ structure
$configDir = "{$this->bundle->getPath()}/config";

// then fall back to legacy structure
if (!\is_dir($configDir))
{
$configDir = "{$this->bundle->getPath()}/Resources/config";
}

if (\is_file("{$configDir}/services.yaml"))
{
$loader = new YamlFileLoader($container, new FileLocator($configDir));
$loader->load("services.yaml");
}
}
}


/**
* @inheritDoc
*/
public function getAlias ()
{
if (null !== $this->alias)
/**
* @inheritDoc
*/
public function getAlias ()
{
return $this->alias;
}
if (null !== $this->alias)
{
return $this->alias;
}

// use default naming convention
$basename = \preg_replace('/Bundle$/', '', $this->bundle->getName());
return Container::underscore($basename);
// use default naming convention
$basename = \preg_replace('/Bundle$/', '', $this->bundle->getName());
return Container::underscore($basename);
}
}
}
67 changes: 40 additions & 27 deletions src/Bundle/ConfigurableBundleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,55 @@

namespace Becklyn\RadBundle\Bundle;

use Becklyn\RadBundles\Bundle\ConfigurableBundleExtension as NewConfigurableBundleExtension;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;

final class ConfigurableBundleExtension extends BundleExtension
if (\class_exists(NewBundleExtension::class))
{
/** @var ConfigurationInterface */
private $configuration;

/** @var callable */
private $configurator;


/**
*/
public function __construct (
BundleInterface $bundle,
ConfigurationInterface $configuration,
callable $configurator,
?string $alias = null
)
class ConfigurableBundleExtension extends NewConfigurableBundleExtension
{
parent::__construct($bundle, $alias);
$this->configuration = $configuration;
$this->configurator = $configurator;
}


}
else
{
/**
* @inheritDoc
* @deprecated Please use the version from `becklyn/rad-bundles` instead.
*/
public function load (array $configs, ContainerBuilder $container) : void
final class ConfigurableBundleExtension extends BundleExtension
{
parent::load($configs, $container);

$config = $this->processConfiguration($this->configuration, $configs);
($this->configurator)($config, $container);
/** @var ConfigurationInterface */
private $configuration;

/** @var callable */
private $configurator;


/**
*/
public function __construct (
BundleInterface $bundle,
ConfigurationInterface $configuration,
callable $configurator,
?string $alias = null
)
{
parent::__construct($bundle, $alias);
$this->configuration = $configuration;
$this->configurator = $configurator;
}


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

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

0 comments on commit 56e61ed

Please sign in to comment.