Development Wiki

Dependency list

From phpBB Development Wiki

(Redirected from Depencencies)

Dependencies are variables (mostly objects) which can be passed to listener-classes and controller-classes. Which variables are passed, is defined in .yml files, which are read by the Symfony framework. Dependencies can include services and parameters. For an extension, such a coupled .yml-file and listener-class could look as follows:


        class: myvendor\myext\event\listener
            - @config
            - @template
            - @user
            - @controller.helper
            - %core.root_path%
            - %core.php_ext%


class listener implements EventSubscriberInterface
   * Constructor
   * @param \phpbb\config                 $config            Config object
   * @param \phpbb\template               $template          Template object
   * @param \phpbb\user                   $user              User object
   * @param \phpbb\controller\helper      $helper            Controller helper object
   * @param string                        $root_path         phpBB root path
   * @param string                        $php_ext           phpEx
   public function __construct(\phpbb\config\config $config, \phpbb\template\template $template, \phpbb\user $user, \phpbb\controller\helper $helper, $root_path, $php_ext)
      $this->config = $config;
      $this->template = $template;
      $this->user = $user;
      $this->helper = $helper;
      $this->root_path = $root_path;
      $this->php_ext = $php_ext;

Note that the order of the dependencies must be the same in the arguments-list in services.yml and in the constructor in listener.php. The passing of dependencies in this way replaces the need of using global $var; in most cases.

Overview of dependencies available in phpBB

The table below provides an overview of the most common dependencies used in phpBB. Note that most of these are defined in the .yml files in the config directory which can be found in the phpbb root, most notably the services.yml file.

Identifier Namespace+classname Equivalent global variable Added in Release Explanation
@auth \phpbb\auth\auth  ? The auth object
@dbal.conn \phpbb\db\driver\factory $db  ? The database object
@cache \phpbb\cache\service  ? The cache object
@config \phpbb\config\config $config  ? The config object (also accessible as array)
@controller.helper \phpbb\controller\helper  ? The helper object, helpful for controller classes
%core.root_path% $phpbb_root_path  ? The phpBB root path. Is defined in phpbb/di/container_builder.php
%core.php_ext% $php_ext  ? The php-ext. Is defined in phpbb/di/container_builder.php
@request \phpbb\request\request  ? The request object
@template \phpbb\template\template $template  ? The template object
@user \phpbb\user $user  ? The user object
@captcha.factory \phpbb\captcha\factory  ? The captcha factory object