parse bundle name+namespace at once
This commit is contained in:
parent
9362b8cbda
commit
81b292280b
@ -31,6 +31,7 @@ abstract class Bundle implements BundleInterface
|
||||
protected $name;
|
||||
protected $extension;
|
||||
protected $path;
|
||||
private $namespace;
|
||||
|
||||
/**
|
||||
* Boots the Bundle.
|
||||
@ -106,9 +107,11 @@ abstract class Bundle implements BundleInterface
|
||||
*/
|
||||
public function getNamespace()
|
||||
{
|
||||
$class = get_class($this);
|
||||
if (null === $this->namespace) {
|
||||
$this->parseClassName();
|
||||
}
|
||||
|
||||
return substr($class, 0, strrpos($class, '\\'));
|
||||
return $this->namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,14 +145,11 @@ abstract class Bundle implements BundleInterface
|
||||
*/
|
||||
final public function getName()
|
||||
{
|
||||
if (null !== $this->name) {
|
||||
return $this->name;
|
||||
if (null === $this->name) {
|
||||
$this->parseClassName();
|
||||
}
|
||||
|
||||
$name = get_class($this);
|
||||
$pos = strrpos($name, '\\');
|
||||
|
||||
return $this->name = false === $pos ? $name : substr($name, $pos + 1);
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -218,4 +218,11 @@ abstract class Bundle implements BundleInterface
|
||||
return new $class();
|
||||
}
|
||||
}
|
||||
|
||||
private function parseClassName()
|
||||
{
|
||||
$pos = strrpos(static::class, '\\');
|
||||
$this->namespace = false === $pos ? '' : substr(static::class, 0, $pos);
|
||||
$this->name = false === $pos ? static::class : substr(static::class, $pos + 1);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user