[3.1a3] Extension problems

General discussion of development ideas and the approaches taken in the 3.x branch of phpBB. The current feature release of phpBB 3 is 3.3/Proteus.
Forum rules
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.3.x. If you need support for phpBB 3.3.x please visit the 3.3.x Support Forum on phpbb.com.

If you have questions regarding writing extensions please post in Extension Writers Discussion to receive proper guidance from our staff and community.
..::Frans::..
Registered User
Posts: 27
Joined: Wed Mar 01, 2006 8:20 am

[3.1a3] Extension problems

Post by ..::Frans::.. »

Trying to get the basics for the new extensions in 3.1 i am trying to re-write (not convert, yes i know but i want to grasp the real inside of the extensions part) a mod i wrote once.

Now, my extension has a main-listener. The __construct look like this:

Code: Select all

    /**
    * Constructor
    *
    * @param \phpbb\controller\helper    $helper        Controller helper object
    * @param \phpbb\template            $template    Template object
    * @param \phpbb\user                $user        User object
    * @param \phpbb\config                $conmfig    Config object
    */
    public function __construct(\phpbb\controller\helper $helper, \phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config)
    {
        $this->helper = $helper;
        $this->template = $template;
        $this->user = $user;
        $this->config = $config;
    }
 
which gives me the next error:
Catchable fatal error: Argument 4 passed to infopolitie\header_extension\event\main_listener::__construct() must be an instance of phpbb\config\config, none given in C:\wamp\www\phpbb-prep-release-3.1.0-a2\phpBB\ext\infopolitie\header_extension\event\main_listener.php on line 50
and i am really clueless as to why the config object can't be included. Now, using global $config; works flawlessly so i can get around the problem but i am stuck in understanding the resaon of this error. Anyone has an explanation?

Thnx!

User avatar
MattF
Extension Customisations
Extension Customisations
Posts: 675
Joined: Mon Mar 08, 2010 9:18 am

Re: [3.1a3] Extension problems

Post by MattF »

Did you set up the services.yml file yet?
Has an irascible disposition.

..::Frans::..
Registered User
Posts: 27
Joined: Wed Mar 01, 2006 8:20 am

Re: [3.1a3] Extension problems

Post by ..::Frans::.. »

Yes

Realisty
Registered User
Posts: 107
Joined: Sat Jan 20, 2007 3:37 pm

Re: [3.1a3] Extension problems

Post by Realisty »

Maybe i'm mistaken but isn't the problem in:

Code: Select all

* @param \phpbb\config                $conmfig    Config object
I think it should be:

Code: Select all

* @param \phpbb\config                $config    Config object

..::Frans::..
Registered User
Posts: 27
Joined: Wed Mar 01, 2006 8:20 am

Re: [3.1a3] Extension problems

Post by ..::Frans::.. »

@realisty: thanks... saw that later too but that isn't the problem besides the fact that it is a comment and therefore not part of the code... ;-)

User avatar
Marc
Development Team Leader
Development Team Leader
Posts: 185
Joined: Thu Sep 09, 2010 11:36 am
Location: Munich, Germany

Re: [3.1a3] Extension problems

Post by Marc »

It would be really helpful to have the full file and the full service definition you used.

..::Frans::..
Registered User
Posts: 27
Joined: Wed Mar 01, 2006 8:20 am

Re: [3.1a3] Extension problems

Post by ..::Frans::.. »

Solved. It took me the better part of today to figure this one out so for the good of anyone with the same error:

If you add a constant to the services.yml file AND to the construct of the listener (in my case $config), make sure that you disable the extension before doing so and enable it again after making the changes.

Thanx all for thinking with me!

regards,

User avatar
imkingdavid
Registered User
Posts: 1050
Joined: Thu Jul 30, 2009 12:06 pm

Re: [3.1a3] Extension problems

Post by imkingdavid »

That is because the Dependency Injection Container is cached on subsequent page loads to reduce load time. Enable DEBUG in your config.php file to make it stop caching it, so you don't have to keep enabling/disabling your extension or manually purging the cache.
I do custom MODs. PM for a quote!
View My: MODs | Portfolio
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.

..::Frans::..
Registered User
Posts: 27
Joined: Wed Mar 01, 2006 8:20 am

Re: [3.1a3] Extension problems

Post by ..::Frans::.. »

Thnx david, good tip! ;-)

MrR
Registered User
Posts: 7
Joined: Fri Dec 06, 2013 5:13 pm

Re: [3.1a3] Extension problems

Post by MrR »

Hey,

I seem to have a similar problem, although both services.yml and my main_listener.php seem alright to me.

config/services.yml:

Code: Select all

services:
    [...]
    robinrump.rules.listener:
        class: robinrump\rules\event\main_listener
        arguments:
            - @controller.helper
            - @template
            - @user
        tags:
            - { name: event.listener }
event/main_listener.php

Code: Select all

<?php
namespace robinrump\rules\event;

/**
* @ignore
*/
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* Event listener
*/
class main_listener implements EventSubscriberInterface
{
    /* @var \phpbb\controller\helper */
    protected $helper;

    /* @var \phpbb\template */
    protected $template;

    /* @var \phpbb\user */
    protected $user;
    
    /**
    * Constructor
    *
    * @param \phpbb\controller\helper    $helper        Controller helper object
    * @param \phpbb\template            $template    Template object
    * @param \phpbb\user                $user        User object
    */
    public function __construct(\phpbb\controller\helper $helper, \phpbb\template\template $template, \phpbb\user $user)
    {
        $this->helper = $helper;
        $this->template = $template;
        $this->user = $user;
    }
    [...]
Still, I receive the following error:
Catchable fatal error: Argument 1 passed to robinrump\rules\event\main_listener::__construct() must be an instance of phpbb\controller\helper, none given, called in /Users/robinrump/Sites/alpha/phpbb/event/extension_subscriber_loader.php on line 35 and defined in /Users/robinrump/Sites/alpha/ext/robinrump/rules/event/main_listener.php on line 38
The arguments required in the constructor are clearly declared in the services file. :S But I don't know where the error derives from. Could anyone help me, please?

Post Reply