From: Raphaƫl Gertz Date: Wed, 11 Aug 2021 18:41:43 +0000 (+0200) Subject: Generate alias from class name X-Git-Tag: 0.2.0~67 X-Git-Url: https://git.rapsys.eu/userbundle/commitdiff_plain/c26a8dae7bf279375e16134131983f50307f45a2?ds=inline Generate alias from class name --- diff --git a/RapsysUserBundle.php b/RapsysUserBundle.php index c083bb0..b347c51 100644 --- a/RapsysUserBundle.php +++ b/RapsysUserBundle.php @@ -2,6 +2,36 @@ namespace Rapsys\UserBundle; +use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpKernel\Bundle\Bundle; -class RapsysUserBundle extends Bundle {} +class RapsysUserBundle 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)); + } +}