Non-existent service

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
MarkDHamill
Registered User
Posts: 3781
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Non-existent service

Post by MarkDHamill » Sat May 25, 2019 3:58 pm

So I used the skeleton extension to create the files for my new extension. It creates a default /acp/main_module.php program as follows which has been working fine:

Code: Select all

<?php
/**
 *
 * Filter by country. An extension for the phpBB Forum Software package.
 *
 * @copyright (c) 2019, Mark D. Hamill, https://www.phpbbservices.com
 * @license GNU General Public License, version 2 (GPL-2.0)
 *
 */

namespace phpbbservices\filterbycountry\acp;

/**
 * Filter by country ACP module.
 */
class main_module
{
	public $page_title;
	public $tpl_name;
	public $u_action;

	/**
	 * Main ACP module
	 *
	 * @param int    $id   The module ID
	 * @param string $mode The module mode (for example: manage or settings)
	 * @throws \Exception
	 */
	public function main($id, $mode)
	{
		global $phpbb_container;

		/** @var \phpbbservices\filterbycountry\controller\acp_controller $acp_controller */
		$acp_controller = $phpbb_container->get('phpbbservices.filterbycountry.controller.acp');

		/** @var \phpbb\language\language $language */
		$language = $phpbb_container->get('language');

		// Load a template from adm/style for our ACP page
		$this->tpl_name = 'acp_filterbycountry_body';

		// Set the page title for our ACP page
		$this->page_title = $language->lang('ACP_FILTERBYCOUNTRY_TITLE');

		// Make the $u_action url available in our ACP controller
		$acp_controller->set_page_url($this->u_action);

		// Load the display options handle in our ACP controller
		$acp_controller->display_options();
	}
}
Suddenly it stopped working. I get:
Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "phpbbservices.filterbycountry.controller.acp". in /Applications/XAMPP/xamppfiles/apps/phpbb/htdocs/vendor/symfony/dependency-injection/ContainerBuilder.php:809 Stack trace: #0 /Applications/XAMPP/xamppfiles/apps/phpbb/htdocs/vendor/symfony/dependency-injection/ContainerBuilder.php(455): Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition('phpbbservices.f...') #1 /Applications/XAMPP/xamppfiles/apps/phpbb/htdocs/ext/phpbbservices/filterbycountry/acp/main_module.php(34): Symfony\Component\DependencyInjection\ContainerBuilder->get('phpbbservices.f...') #2 /Applications/XAMPP/xamppfiles/apps/phpbb/htdocs/includes/functions_module.php(676): phpbbservices\filterbycountry\acp\main_module->main('\\phpbbservices\\...', 'settings') #3 /Applications/xampp/xamppfiles/apps/phpbb/htdocs/adm/index.php(82): p_master->load_active() #4 {main} thrown in /Applications/XAMPP/xamppfiles/apps/phpbb/htdocs/vendor/symfony/dependency-injection/ContainerBuilder.php on line 809
It's getting tripped up here:

Code: Select all

		$acp_controller = $phpbb_container->get('phpbbservices.filterbycountry.controller.acp');
But the service is there in my services.yml file and I even validated it with an online YAML validator. The full file is below.

Code: Select all

imports:
    - { resource: parameters.yml }
services:
    phpbbservices.filterbycountry.controller.acp:
        class: phpbbservices\filterbycountry\controller\acp_controller
        arguments:
            - '@config'
            - '@language'
            - '@log'
            - '@request'
            - '@template'
            - '@user'
    phpbbservices.filterbycountry.common:
        class: phpbbservices\filterbycountry\core\common
        arguments:
            - '@language'
            - '%core.root_path%'
            - '@config'
            - '@log'
    phpbbservices.filterbycountry.listener:
        class: phpbbservices\filterbycountry\event\main_listener
        arguments:
            - '@language'
            - '@request'
            - '%core.root_path%'
            - '%core.php_ext%'
            - '@config'
            - '@log'
            - '@user'
            - '@service_container'
            - '@config_text'
            - '@phpbbservices.filterbycountry.core.common'
        tags:
            - { name: event.listener }
    phpbbservices.filterbycountry.service:
        class: phpbbservices\filterbycountry\service
        arguments:
            - '@user'
            - '%phpbbservices.filterbycountry.tables.filterbycountry_table%'
    phpbbservices.filterbycountry.cron.task.cron_task:
        class: phpbbservices\filterbycountry\cron\task\update_country_database
        arguments:
            - '@config'
            - '@phpbbservices.filterbycountry.common'
            - '@log'
        calls:
            - [set_name, [cron.task.update_country_database]]
        tags:
            - { name: cron.task }
I've been trying to get away from using global $phpbb_container in another program, so I added the @service_container variable for another program which works fine. I did try removing it but it doesn't seem to make a difference.

Yes, I have purged the cache multiple times so I don't think that's the issue. Any ideas are appreciated.
Get the latest versions of my Digests and Smartfeed extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.

User avatar
mrgoldy
Jr. Extension Validator
Posts: 1040
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: Non-existent service

Post by mrgoldy » Sun May 26, 2019 12:53 pm

Probably because your listener has a service dependency on an non existing service: - '@phpbbservices.filterbycountry.core.common', the "core" has to be out of it. This means that there is an "container exception" and the service container is build without any extensions, hence the acp controller can not be found.
phpBB Studio / ''Proud member of the Studio"

User avatar
MarkDHamill
Registered User
Posts: 3781
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: Non-existent service

Post by MarkDHamill » Sun May 26, 2019 1:40 pm

Unfortunately, that isn't it. I think the issue is related to injecting the phpbb container into services.yml because it worked before then. On another extension I was advised to do this because they don't like me using $phpbb_container global variable, so I thought I'd be proactive in this one.

Taking it out didn't fix the issue unfortunately. I also found dated topics like this one that suggest in the ACP you must use the $phpbb_container global variable.

viewtopic.php?f=461&t=2370906

I think I'm going to have to recover my files from before these edits, reapply the changes line by line and see where it breaks.
Get the latest versions of my Digests and Smartfeed extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.

User avatar
david63
Registered User
Posts: 16068
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Non-existent service

Post by david63 » Sun May 26, 2019 1:51 pm

That link which is saying that you need to use globals was referring to using it in a module which, from what I can see, you are doing and that makes it OK.

What I would suggest though is that you move away from doing processing in modules and use controllers - it will save you haveing to make the changes in the future.
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
MarkDHamill
Registered User
Posts: 3781
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: Non-existent service

Post by MarkDHamill » Sun May 26, 2019 1:56 pm

It would be helpful if the skeleton extension was updated to use this approach.
Get the latest versions of my Digests and Smartfeed extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.

User avatar
mrgoldy
Jr. Extension Validator
Posts: 1040
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: Non-existent service

Post by mrgoldy » Mon May 27, 2019 7:31 am

The skeleton extension uses that approach.
VSE and I updated it not too long ago.
phpBB Studio / ''Proud member of the Studio"

Post Reply

Return to “Extension Writers Discussion”