use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Process\ExecutableFinder;
+use Rapsys\PackBundle\RapsysPackBundle;
+
/**
* This is the class that validates and merges configuration from your app/config files.
*
*/
public function getConfigTreeBuilder(): TreeBuilder {
//Get TreeBuilder object
- $treeBuilder = new TreeBuilder('rapsys_pack');
+ $treeBuilder = new TreeBuilder(RapsysPackBundle::getAlias());
//Get ExecutableFinder object
$finder = new ExecutableFinder();
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
+use Rapsys\PackBundle\RapsysPackBundle;
+
/**
* This is the class that loads and manages your bundle configuration.
*
* {@inheritdoc}
*/
public function getAlias(): string {
- return 'rapsys_pack';
+ return RapsysPackBundle::getAlias();
}
}
use Symfony\Component\HttpKernel\Config\FileLocator;
use Twig\Extension\AbstractExtension;
-use Rapsys\PackBundle\Util\SluggerUtil;
use Rapsys\PackBundle\Parser\TokenParser;
+use Rapsys\PackBundle\RapsysPackBundle;
+use Rapsys\PackBundle\Util\SluggerUtil;
/**
* {@inheritdoc}
* {@inheritdoc}
*/
public function getAlias(): string {
- return 'rapsys_pack';
+ return RapsysPackBundle::getAlias();
}
}
namespace Rapsys\PackBundle;
+use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpKernel\Bundle\Bundle;
/**
* {@inheritdoc}
*/
-class RapsysPackBundle extends Bundle {}
+class RapsysPackBundle extends Bundle {
+ /**
+ * Return bundle alias
+ *
+ * @return string The bundle alias
+ */
+ public function getAlias(): string {
+ //With namespace
+ if ($npos = strrpos(static::class, '\\')) {
+ //Set name pos
+ $npos++;
+ //Without namespace
+ } else {
+ $npos = 0;
+ }
+
+ //With trailing bundle
+ if (substr(static::class, -strlen('Bundle'), strlen('Bundle')) === 'Bundle') {
+ //Set bundle pos
+ $bpos = strlen(static::class) - $npos - strlen('Bundle');
+ //Without bundle
+ } else {
+ //Set bundle pos
+ $bpos = strlen(static::class) - $npos;
+ }
+
+ //Return underscored lowercase bundle alias
+ return Container::underscore(substr(static::class, $npos, $bpos));
+ }
+}