2017-07-01 4 views
1
{ 
     "autoload": { 

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

インターフェイスはCに位置しています自動ロードPSR-4名前空間のインターフェースは

namespace Acme; 

Interface Responds 
{ 
    public function userRegisteredSuccessfuly(); 

    public function userRegisteredunSuccessfuly(); 
} 

私composer.jsonファイルに見つかりません:\ 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(); 
    } 
} 

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.'); 
    } 

} 

そしてこのクラスで私は応答インターフェースを実装しました。

は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?

答えて

2

PSR-4です。したがって、Interface Respondsresponds.phpファイルにあり、respondstouserregistration.phpファイルには含まれていません。ファイルの名前を変更するか、インターフェイス名をInterface Respondstouserregistrationに変更してください。

+0

ありがとうございます。 –