Skip to content

Commit 5efe2dc

Browse files
committed
parse bundle name+namespace at once
1 parent bf51709 commit 5efe2dc

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

Bundle/Bundle.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ abstract class Bundle implements BundleInterface
3131
protected $name;
3232
protected $extension;
3333
protected $path;
34+
private $namespace;
3435

3536
/**
3637
* Boots the Bundle.
@@ -106,9 +107,11 @@ public function getContainerExtension()
106107
*/
107108
public function getNamespace()
108109
{
109-
$class = get_class($this);
110+
if (null === $this->namespace) {
111+
$this->parseClassName();
112+
}
110113

111-
return substr($class, 0, strrpos($class, '\\'));
114+
return $this->namespace;
112115
}
113116

114117
/**
@@ -142,14 +145,11 @@ public function getParent()
142145
*/
143146
final public function getName()
144147
{
145-
if (null !== $this->name) {
146-
return $this->name;
148+
if (null === $this->name) {
149+
$this->parseClassName();
147150
}
148151

149-
$name = get_class($this);
150-
$pos = strrpos($name, '\\');
151-
152-
return $this->name = false === $pos ? $name : substr($name, $pos + 1);
152+
return $this->name;
153153
}
154154

155155
/**
@@ -218,4 +218,11 @@ protected function createContainerExtension()
218218
return new $class();
219219
}
220220
}
221+
222+
private function parseClassName()
223+
{
224+
$pos = strrpos(static::class, '\\');
225+
$this->namespace = false === $pos ? '' : substr(static::class, 0, $pos);
226+
$this->name = false === $pos ? static::class : substr(static::class, $pos + 1);
227+
}
221228
}

0 commit comments

Comments
 (0)