gpt4 book ai didi

php - 中未找到自动加载 PSR-4 命名空间接口(interface)

转载 作者:行者123 更新时间:2023-12-04 16:53:18 25 4
gpt4 key购买 nike

{ 
"autoload": {

"psr-4": {
"Acme\\": "src"
}
}
}

我的 composer.json 文件
namespace Acme;

Interface Responds
{
public function userRegisteredSuccessfuly();

public function userRegisteredunSuccessfuly();
}

接口(interface)位于 C:\xampp\htdocs\bootcamp\src\respondstouserregistration.php
<?php 
namespace Acme;

class RegisterUser
{
public function execute(array $data, Responds $listener) //data
{
var_dump('registering the user.');
$listener->userRegisteredSuccessfuly();
}
}

在我引用的接口(interface)响应的 RegisterUser 中, registeruser 也位于 src
<?php 
namespace Acme;

class AuthController implements Responds
{
protected $registration;

public function __construct(RegisterUser $registration)
{
$this->registration = $registration;
}

public function register()
{
$this->registration->execute([], $this);
}

public function userRegisteredSuccessfuly()
{
var_dump('created successfuly. redirect somewhere.');
}


public function userRegisteredunSuccessfuly()
{
var_dump('created unsuccessfuly. redirect back.');
}

}

在这个类中,我实现了响应接口(interface)。

AuthController 也位于 C:\xampp\htdocs\bootcamp\src\authcontroller.php

现在我的错误是

PHP Fatal error: Interface 'Acme\Responds' not found in C:\xampp\htdocs\bootcamp\src\authcontroller.php How can i make the Authcontroller locate the php file where the interface is?

最佳答案

PSR-4 自动加载假定您的类名与文件名匹配。所以你的 Interface Responds预计在responds.php文件,不在 respondstouserregistration.php文件。重命名文件,或将您的界面重命名为 Interface Respondstouserregistration

关于php - 中未找到自动加载 PSR-4 命名空间接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44862585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com