Search code examples
symfonyservicesymfony-2.7

Symfony 2.7 - Service is not loaded/registered


Working on Symfony 2.7 -

I created a new service (ipad.registerchecksum) in a custom bundle and now I try to use it as an argument in another service (ipad.download_history) in another custom bundle but I get the following error :

The service "ipad.download_history" has a dependency on a non-existent service "ipad.registerchecksum".

Creation of my service :

<?php

namespace MyCompany\MyBundle2\Services;

class Registerchecksum
{

    public function sayHello()
    {
        return "Hello";
    }

}

?>

Register my class as Service :

#MyCompany\MyBundle2\Resources\Config\services.yml

services:
    ipad.registerchecksum:
        class: MyCompany\MyBundle2\Services\Registerchecksum

Load my services.yml :

<?php

namespace MyCompany\MyBundle2\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;


class MyBundle2Extension extends Extension
{

    public function load(array $configs, ContainerBuilder $container)
    {
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('datagrid/datagrids.yml');
        $loader->load('navigation.yml');
        $loader->load('services.yml');
    }

    // Please note : navigation.yml and datagrid/datagrids.yml are well loaded and work perfectly

}
?>

.. the service seems not to be registered.

  • If I test "/app/console container:debug", it doesn't appear.
  • I already clean caches (dev & prod), warmup caches too.

Solution

  • $ rm -rf app/cache/*

    #MyCompany\MyBundle2\Resources\Config\services.yml
    
    services:
        ipad.registerchecksum:
            class: MyCompany\MyBundle2\Services\Registerchecksum
    
        ipad.download_history:
            class: Your Service
            arguments: ["@ipad.registerchecksum"]