[feature/twig] Attempt to automatically set style dir for ext controllers

Extension authors can change it themselves if necessary

PHPBB3-11598
This commit is contained in:
Nathaniel Guse 2013-07-04 11:08:36 -05:00
parent 81f27fd87e
commit 2fb48d60f1
2 changed files with 28 additions and 2 deletions

View file

@ -79,7 +79,7 @@ services:
arguments:
- @user
- @service_container
- @ext.finder
- @style
cron.task_collection:
class: phpbb_di_service_collection

View file

@ -37,16 +37,24 @@ class phpbb_controller_resolver implements ControllerResolverInterface
*/
protected $container;
/**
* phpbb_style object
* @var phpbb_style
*/
protected $style;
/**
* Construct method
*
* @param phpbb_user $user User Object
* @param ContainerInterface $container ContainerInterface object
* @param phpbb_style $style
*/
public function __construct(phpbb_user $user, ContainerInterface $container)
public function __construct(phpbb_user $user, ContainerInterface $container, phpbb_style $style)
{
$this->user = $user;
$this->container = $container;
$this->style = $style;
}
/**
@ -80,6 +88,24 @@ class phpbb_controller_resolver implements ControllerResolverInterface
$controller_object = $this->container->get($service);
/*
* If this is an extension controller, we'll try to automatically set
* the style paths for the extension (the ext author can change them
* if necessary).
*/
$controller_dir = explode('_', get_class($controller_object));
// 0 phpbb, 1 ext, 2 vendor, 3 extension name, ...
if ($controller_dir[1] === 'ext')
{
$controller_style_dir = 'ext/' . $controller_dir[2] . '/' . $controller_dir[3] . '/styles';
if (is_dir($controller_style_dir))
{
$this->style->set_style(array($controller_style_dir, 'styles'));
}
}
return array($controller_object, $method);
}