我在创建自定义sumfony 4服务时遇到问题:我在子文件夹src / CustumService中创建了一个自定义类UtilasteurService。但是,当我运行命令php bin/console debug:autowiring
时,出现以下错误。
预期在文件中找到类“ App \ CustumService \ UtilisateurService” “ C:\ wamp \ www \ semges_api \ src / CustumService \ UtilisateurService.php” 从资源“ ../src/*”导入服务时,但不是 找到了!检查与资源一起使用的名称空间前缀。
请参阅下面的service.yml文件和UtilisateurService文件。
#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);
}
}
有人可以帮助我了解问题所在吗?
答案 0 :(得分:0)
您的设置没有问题。也许尝试使用php bin/console cache:clear
清除缓存,然后重试?
为我工作:
Autowirable Services
====================
The following classes & interfaces can be used as type-hints when autowiring:
------------------------------------------------------------------------------------
App\Controller\IndexController
App\CustumService\UtilisateurService
答案 1 :(得分:0)
Greattttttttt谢谢大家。我通过执行以下命令解决了我的问题:composer dump-autoload
我通过阅读此问题的解决方案来获得此解决方案:Symfony4 Error loading classes custom folder "Expected to find class... but it was not found"