[ticket/13740] Deduplicate container builder's checks

PHPBB3-13740
This commit is contained in:
Mate Bartus 2015-07-25 14:43:54 +02:00
parent 723337d2f6
commit e8e9193690

View file

@ -72,18 +72,9 @@ class container_factory
{ {
// Check if container was built, if not try to build it // Check if container was built, if not try to build it
if ($this->container === null) if ($this->container === null)
{
// Check whether container can be built
// We need config.php for that so let's check if it has been set up yet
if (filesize($this->phpbb_root_path . 'config.' . $this->php_ext))
{ {
$this->build_container(); $this->build_container();
} }
else
{
throw new cannot_build_container_exception();
}
}
return ($service_name === null) ? $this->container : $this->container->get($service_name); return ($service_name === null) ? $this->container : $this->container->get($service_name);
} }
@ -102,6 +93,26 @@ class container_factory
// Check if container was built, if not try to build it // Check if container was built, if not try to build it
if ($this->container === null) if ($this->container === null)
{ {
$this->build_container();
}
return $this->container->getParameter($param_name);
}
/**
* Build dependency injection container
*
* @throws \phpbb\install\exception\cannot_build_container_exception When container cannot be built
*/
protected function build_container()
{
// If the container has been already built just return.
// Although this should never happen
if ($this->container instanceof \Symfony\Component\DependencyInjection\ContainerInterface)
{
return;
}
// Check whether container can be built // Check whether container can be built
// We need config.php for that so let's check if it has been set up yet // We need config.php for that so let's check if it has been set up yet
if (filesize($this->phpbb_root_path . 'config.' . $this->php_ext)) if (filesize($this->phpbb_root_path . 'config.' . $this->php_ext))
@ -112,22 +123,6 @@ class container_factory
{ {
throw new cannot_build_container_exception(); throw new cannot_build_container_exception();
} }
}
return $this->container->getParameter($param_name);
}
/**
* Build dependency injection container
*/
protected function build_container()
{
// If the container has been already built just return.
// Although this should never happen
if ($this->container instanceof \Symfony\Component\DependencyInjection\ContainerInterface)
{
return;
}
$phpbb_config_php_file = new \phpbb\config_php_file($this->phpbb_root_path, $this->php_ext); $phpbb_config_php_file = new \phpbb\config_php_file($this->phpbb_root_path, $this->php_ext);
$phpbb_container_builder = new \phpbb\di\container_builder($this->phpbb_root_path, $this->php_ext); $phpbb_container_builder = new \phpbb\di\container_builder($this->phpbb_root_path, $this->php_ext);