minor #20117 [HttpKernel] Parse bundle name+namespace at once (ro0NL)
This PR was merged into the 3.2-dev branch.
Discussion
----------
[HttpKernel] Parse bundle name+namespace at once
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | comma-separated list of tickets fixed by the PR, if any
| License | MIT
| Doc PR | reference to the documentation PR, if any
Commits
-------
81b2922
parse bundle name+namespace at once
This commit is contained in:
commit
f54cfd66c5
@ -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