0

I've a problem with creation of a custom sumfony 4 service: I've created a custom class UtilasteurService in sub-folder src/CustumService. But when i run the command php bin/console debug:autowiring I've the following error.

Expected to find class "App\CustumService\UtilisateurService" in file "C:\wamp\www\semges_api\src/CustumService\UtilisateurService.php" while im porting services from resource "../src/*", but it was not found! Check the namespace prefix used with the resource.

See below my service.yml file and UtilisateurService file.

#service.yml

parameters:
    locale: 'en'
services:
      _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
        public: false       # Allows optimizing the container by removing unused services; this also means

    App\:
        resource: '../src/*'
        exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'

    App\Controller\:
        resource: '../src/Controller'
        tags: ['controller.service_arguments']

#src/CustumService\UtilisateurService.php

namespace App\CustumService;

use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;

class UtilisateurService
{
    private $passwd;

    public function __construct($motdepasse)
    {
      $this->paswd=$motdepasse;
    }

    public function encodePassword($motdepasse )
    {
        return $this->passwordEncoder->encodePassword($motdepasse);
    }
}

Can somebody help me to understand what is wrong?

SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
aubin115
  • 87
  • 2
  • 7
  • Does this answer your question? [Symfony4 Error loading classes custom folder "Expected to find class... but it was not found"](https://stackoverflow.com/questions/47954510/symfony4-error-loading-classes-custom-folder-expected-to-find-class-but-it-w) – James Dec 23 '21 at 23:38

2 Answers2

2

Greattttttttt thank you to all. I've solved my problem by executig this command: composer dump-autoload

I get this solution by reading the solution of this problem : Symfony4 Error loading classes custom folder "Expected to find class... but it was not found"

Regards

aubin115
  • 87
  • 2
  • 7
0

There's nothing wrong with your setup. Maybe try to clear the cache with php bin/console cache:clear and then try again?

Works for me:

Autowirable Services
====================

 The following classes & interfaces can be used as type-hints when autowiring:

 ------------------------------------------------------------------------------------
  App\Controller\IndexController
  App\CustumService\UtilisateurService
symques
  • 46
  • 7
  • Thank you @symques. Even when i want to execute the clear command,php bin/console cache:clear i've the same error – aubin115 Sep 08 '18 at 14:26