Is Autowire Compatible with phpBB?

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
david63
Registered User
Posts: 18821
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Is Autowire Compatible with phpBB?

Post by david63 »

As I have mentioned in other topics I have been using autowire in some of my services.yml files. These have worked fine on my development board (apart from the occasional error - which I have managed to fix)

Once an extension goes into production then there are numerous errors with being incompatible with other extensions (This also applies to extensions by other authors who use autowire)

The problem arises where another extension uses a FQCN - for example (I am not criticising anyone/anything here)

Code: Select all

blitze.sitemaker.icon_picker:
        class: blitze\sitemaker\services\icon_picker
        arguments:
            - '@language'
            - '@blitze.sitemaker.util'
            - '@blitze.sitemaker.template'
This will give me this error
Exception: Cannot autowire service "david63.userdetails.data.controller": argument "$template" of method "david63\userdetails\controller\data_controller::__construct()" references interface "phpbb\template\template" but no such service exists. You should maybe alias this interface to one of these existing services: "template", "blitze.sitemaker.template".
My services.yml file is

Code: Select all

imports:
    - { resource: userdetails_constants.yml }
    - { resource: arraydata.yml }

services:
    _defaults:
        autowire: true
        bind:
            $root_path: '%core.root_path%'
            $php_ext: '%core.php_ext%'
            $tables: '%tables%'
            $ext_images_path: '%core.root_path%ext/david63/userdetails/adm/style/images'
            $select_ary: '%select_ary%'
            $constants: '%constants%'
        public: true

    david63.userdetails.data.controller:
        class: david63\userdetails\controller\data_controller

    david63.userdetails.core.functions:
        class: david63\userdetails\core\functions

    # alias to allow autowiring
    phpbb\extension\manager: '@ext.manager'
The last line being a fix (not necessarily the best way) for a similar error with extension manager.

So my questions are:
  • How should we handle these incompatibilities with other extensions?
  • Is autowire possible with the way that phpBB is configured with Symfony?
  • Is there a bug within the core of phpBB that is preventing this from working?
  • Am I not understanding how autwire works (most probable reason!)?
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
User avatar
david63
Registered User
Posts: 18821
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Re: Is Autowire Compatible with phpBB?

Post by david63 »

After many hours of searching, reading and experimenting I have found that if I list all of the services as aliases in my services.yml file I do not appear to have any compatibility problems with other extensions.

So for the benefit of anyone else using autowire I now have this at the end of the services.yml file

Code: Select all

# aliases to allow autowiring not conflicting with other extensions
    phpbb\extension\manager: '@ext.manager'
    phpbb\di\service_collection: '@profilefields.type_collection'
    phpbb\template\template: '@template'
    phpbb\config\config: '@config'
    phpbb\config\db_text: '@config_text'
    phpbb\db\driver\driver_interface: '@dbal.conn'
    phpbb\request\request: '@request'
    phpbb\pagination: '@pagination'
    phpbb\user: '@user'
    phpbb\group\helper: '@group_helper'
    phpbb\language\language: '@language'
Obviously this will need to change dependant on what is required for each extension.

I have also found that if all of the services were to be added to the services.yml file in the core (config\default\container\services.yml) then the problems with other extensions appear to be resolved.

https://tracker.phpbb.com/browse/PHPBB3-16609
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
User avatar
RMcGirr83
Former Team Member
Posts: 21821
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Is Autowire Compatible with phpBB?

Post by RMcGirr83 »

What is the benefit of using autowire? I assume there is one.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beerImage
User avatar
david63
Registered User
Posts: 18821
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Re: Is Autowire Compatible with phpBB?

Post by david63 »

RMcGirr83 wrote:
Fri Oct 02, 2020 5:42 pm
What is the benefit of using autowire? I assume there is one.
It saves having to specify all classes that you are injecting in the services file - much quicker and easier
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
Post Reply

Return to “Extension Writers Discussion”