8000 [HttpKernel] Parse bundle name+namespace at once by ro0NL · Pull Request #20117 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] Parse bundle name+namespace at once #20117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/Symfony/Component/HttpKernel/Bundle/Bundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ abstract class Bundle implements BundleInterface
protected $name;
protected $extension;
protected $path;
private $namespace;

/**
* Boots the Bundle.
Expand Down Expand Up @@ -106,9 +107,11 @@ public function getContainerExtension()
*/
public function getNamespace()
{
$class = get_class($this);
if (null === $this->namespace) {
$this->parseClassName();
}

return substr($class, 0, strrpos($class, '\\'));
return $this->namespace;
}

/**
Expand Down Expand Up @@ -142,14 +145,11 @@ public function getParent()
*/
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;
}

/**
Expand Down Expand Up @@ -218,4 +218,11 @@ protected function createContainerExtension()
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);
}
}
0