]> Raphaël G. Git Repositories - packbundle/commitdiff
Move alias generation in RapsysPackBundle::getAlias
authorRaphaël Gertz <git@rapsys.eu>
Wed, 11 Aug 2021 18:33:30 +0000 (20:33 +0200)
committerRaphaël Gertz <git@rapsys.eu>
Wed, 11 Aug 2021 18:33:30 +0000 (20:33 +0200)
DependencyInjection/Configuration.php
DependencyInjection/RapsysPackExtension.php
Extension/PackExtension.php
RapsysPackBundle.php

index 0265db3833bedf535d3998bb61150571041b51f4..7217e98d3d5f7dc340f9f3d57c1bc56d4780da98 100644 (file)
@@ -15,6 +15,8 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder;
 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.
  *
@@ -28,7 +30,7 @@ class Configuration implements ConfigurationInterface {
         */
        public function getConfigTreeBuilder(): TreeBuilder {
                //Get TreeBuilder object
-               $treeBuilder = new TreeBuilder('rapsys_pack');
+               $treeBuilder = new TreeBuilder(RapsysPackBundle::getAlias());
 
                //Get ExecutableFinder object
                $finder = new ExecutableFinder();
index 5bf30085f86d8137382d80a1d16946ff9cd43462..94b9fadf9cf4b180655fb88f2a12e23d7272f75f 100644 (file)
@@ -14,6 +14,8 @@ namespace Rapsys\PackBundle\DependencyInjection;
 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.
  *
@@ -46,6 +48,6 @@ class RapsysPackExtension extends Extension {
         * {@inheritdoc}
         */
        public function getAlias(): string {
-               return 'rapsys_pack';
+               return RapsysPackBundle::getAlias();
        }
 }
index 118de0c1a96006682189b29c58e94db0b1bbf455..48f93cd3b584caa87005d5fed8affe832d15ee19 100644 (file)
@@ -16,8 +16,9 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 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}
@@ -95,6 +96,6 @@ class PackExtension extends AbstractExtension {
         * {@inheritdoc}
         */
        public function getAlias(): string {
-               return 'rapsys_pack';
+               return RapsysPackBundle::getAlias();
        }
 }
index 260ce22420a1ecc50f1f57ae2453b4a68586378c..ca879af6cfdc39050e1166ea57907c1ae2a65e81 100644 (file)
 
 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));
+    }
+}