]> Raphaël G. Git Repositories - packbundle/blob - RapsysPackBundle.php
b01358556302493da2a228b29bcb9f6b4c1b908a
[packbundle] / RapsysPackBundle.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys PackBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\PackBundle;
13
14 use Rapsys\PackBundle\DependencyInjection\RapsysPackExtension;
15
16 use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
17 use Symfony\Component\HttpKernel\Bundle\Bundle;
18
19 /**
20 * {@inheritdoc}
21 */
22 class RapsysPackBundle extends Bundle {
23 /**
24 * {@inheritdoc}
25 */
26 public function getContainerExtension(): ?ExtensionInterface {
27 //Return created container extension
28 return $this->createContainerExtension();
29 }
30
31 /**
32 * Return bundle alias
33 *
34 * @return string The bundle alias
35 */
36 public static function getBundleAlias(): string {
37 //With namespace
38 if ($npos = strrpos(static::class, '\\')) {
39 //Set name pos
40 $npos++;
41
42 //With single namespace
43 $nspos = strpos(static::class, '\\');
44 //Without namespace
45 } else {
46 //Set name pos
47 $npos = 0;
48 }
49
50 //With trailing bundle
51 if (substr(static::class, -strlen('Bundle'), strlen('Bundle')) === 'Bundle') {
52 //Set bundle pos
53 $bpos = strlen(static::class) - $npos - strlen('Bundle');
54 //Without bundle
55 } else {
56 //Set bundle pos
57 $bpos = strlen(static::class) - $npos;
58 }
59
60 //With namespace
61 if ($npos) {
62 //Return prefixed class name
63 return strtolower(substr(static::class, 0, $nspos).'/'.substr(static::class, $npos, $bpos));
64 }
65
66 //Return class name
67 return strtolower(substr(static::class, $npos, $bpos));
68 }
69
70 /**
71 * Return alias
72 *
73 * @return string The alias
74 */
75 public static function getAlias(): string {
76 //With namespace
77 if ($npos = strrpos(static::class, '\\')) {
78 //Set name pos
79 $npos++;
80 //Without namespace
81 } else {
82 $npos = 0;
83 }
84
85 //With trailing bundle
86 if (substr(static::class, -strlen('Bundle'), strlen('Bundle')) === 'Bundle') {
87 //Set bundle pos
88 $bpos = strlen(static::class) - $npos - strlen('Bundle');
89 //Without bundle
90 } else {
91 //Set bundle pos
92 $bpos = strlen(static::class) - $npos;
93 }
94
95 //Return lowercase bundle alias
96 return strtolower(substr(static::class, $npos, $bpos));
97 }
98
99 /**
100 * Return bundle version
101 *
102 * @return string The bundle version
103 */
104 public static function getVersion(): string {
105 //Return version
106 return '0.5.1';
107 }
108 }