php / composer 未加载界面

php / composer not loading interface

我现在已经用头撞墙 3/4 天了,就是看不出我的方法有什么错误。

我正在创建(或试图创建!)一个简单的包,其中包含几个 类 和 1 个接口。这是在 github https://github.com/dnorth98/victoropsnotifier

但基本上,有以下目录结构:

victoropsnotifer
    src
        Signiant
            VictorOpsNotifier
                Transport.php
                VictorOpsNotifier.php

交通很简单:

<?php
    namespace Signiant\VictorOpsNotifer;
     interface Transport
     {
          // must POST the $message to the VictorOps REST endpoint
          public function send(Messages\Message $message);
     }

而 VictorOpsNotifier 的开头是

<?php
    namespace Signiant\VictorOpsNotifer;
    use GuzzleHttp\Client;

    class VictorOpsNotifer implements Transport
    {
         protected $endpoint_url;
         :
         :

当我尝试使用

实例化新对象时出现问题
<?php
    require_once 'vendor/autoload.php';

    use Signiant\VictorOpsNotifier\Messages\CustomMessage;
    use Signiant\VictorOpsNotifier\VictorOpsNotifier;

    $voConfig = ['routing_key' => 'test',
                 'endpoint_url' => 'https://goo'];

    $voHandle = new VictorOpsNotifier($voConfig);

我回来了

PHP Fatal error:  Interface 'Signiant\VictorOpsNotifer\Transport' not found in /tmp/djn/tests/vendor/signiant/
victoropsnotifier/src/Signiant/VictorOpsNotifier/VictorOpsNotifier.php on line 8
PHP Stack trace:
PHP   1. {main}() /tmp/djn/tests/test.php:0
PHP   2. spl_autoload_call() /tmp/djn/tests/test.php:12
PHP   3. Composer\Autoload\ClassLoader->loadClass() /tmp/djn/tests/test.php:0
PHP   4. Composer\Autoload\includeFile() /tmp/djn/tests/vendor/composer/ClassLoader.php:301
PHP   5. include() /tmp/djn/tests/vendor/composer/ClassLoader.php:412

我到底错过了什么? Composer 从我的 github 存储库中找到了正确的包,并且所有内容都在 vendor 文件夹中并且看起来不错。看起来命名空间匹配...所以出于某种原因,它只是没有加载包含接口的 Transport.php 文件。

class VictorOpsNotifer implements \Signiant\VictorOpsNotifer\Transport{}

尝试在您的界面之前添加命名空间。

好像是打错了:

namespace Signiant\VictorOpsNotifer;
                                 ^ no `i` in here

但是

use Signiant\VictorOpsNotifier\VictorOpsNotifier;
                           ^ but here it is

与 class 名称相同。

此外,您将命名空间 Signiant 声明为 src/,但它实际上是 src/Signiant

顺便说一句,这个包不需要声明为psr-0,最好使用psr-4 insetad。没什么大不了的,只是为了一致性。

P.S。奇怪的是它抱怨界面,虽然它不应该在它碰到 class 之前必须这样做,而且它肯定不能在出现错字时碰到 class。

P.P.S 您可以通过使用适当的 IDE、PHPStorm 等轻松避免这些拼写错误。只要有拼写错误,它就会突出显示 class 的名称缺失(而且我什至没有开始谈论自动完成)。