namespace Symfony\Component\HttpKernel\Bundle;
-use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\Console\Application;
*/
abstract class Bundle implements BundleInterface
{
- /**
- * @var ContainerInterface
- */
- protected $container;
+ use ContainerAwareTrait;
+
protected $name;
protected $extension;
protected $path;
+ private $namespace;
/**
* Boots the Bundle.
{
}
- /**
- * Sets the container.
- *
- * @param ContainerInterface|null $container A ContainerInterface instance or null
- */
- public function setContainer(ContainerInterface $container = null)
- {
- $this->container = $container;
- }
-
/**
* Returns the bundle's container extension.
*
*/
public function getNamespace()
{
- $class = get_class($this);
+ if (null === $this->namespace) {
+ $this->parseClassName();
+ }
- return substr($class, 0, strrpos($class, '\\'));
+ return $this->namespace;
}
/**
*/
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;
}
/**
return new $class();
}
}
+
+ private function parseClassName()
+ {
+ $pos = strrpos(static::class, '\\');
+ $this->namespace = false === $pos ? '' : substr(static::class, 0, $pos);
+ if (null === $this->name) {
+ $this->name = false === $pos ? static::class : substr(static::class, $pos + 1);
+ }
+ }
}