2014-04-14 52 views
0

我知道这个问题lil有点旧,但我仍然找不到合适的解决方案。我一直在搜索互联网几天,并尝试几种解决方案,检查我的文件路径,更新composer.json,然后dump-autoload它,但仍然没有运气。我仍然收到以下错误:Laravel ReflectionException错误:库不存在

ReflectionException 
Class Cribbb\Storage\User\EUserRepository does not exist 

这是我的代码。

控制器(应用程序/控制器/ UsersControllers.php):

<?php 

use Cribbb\Storage\User\IUserRepository as User; 

class UsersController extends \BaseController { 

    /** 
    * Display a listing of the resource. 
    * 
    * @return Response 
    */ 

    public function __construct(User $user) 
    { 
     $this->user = $user; 
    } 
?> 

接口(LIB/Cribbb /存储/用户/ IUserRepository.php):

<?php 

namespace Cribbb\Storage\User; 

interface IUserRepository{ 

    public function all(); 
    public function find($id); 
    public function create($input); 
} 

?> 

的信息库(LIB /Cribbb/Storage/User/EUserRepository.php):

<?php 

namepsace Cribbb\Storage\User; 

use User; 

class EUserRepository implements IUserRepository 
{ 

    public function all() 
    { 
     return User::all(); 
    } 

    public function find($id) 
    { 
     return User::find($id); 
    } 

    public function create($input) 
    { 
     return User::create($input); 
    } 



} 

?> 

的服务提供商(LIB/Cribbb /存储/ StorageServiceProv ider.php):

<?php 

namespace Cribbb\Storage; 

use Illuminate\Support\ServiceProvider; 

class StorageServiceProvider extends ServiceProvider { 

    public function register() 
    { 
    $this->app->bind(
     'Cribbb\Storage\User\IUserRepository', 
     'Cribbb\Storage\User\EUserRepository' 
    ); 
    } 

} ?> 

我也包括在应用程序/配置/ app.php如下服务提供商:

'providers' => array(
... 
'Cribbb\Storage\StorageServiceProvider' 
); 

和我添加的应用/ lib中composer.json:

"autoload": { 
     "classmap": [ 
      "app/commands", 
      "app/controllers", 
      "app/models", 
      "app/database/migrations", 
      "app/database/seeds", 
      "app/tests/TestCase.php", 
      "app/lib" 
     ] 
    } 

关于这个的奇怪部分是,虽然IUserRepository和EUserRepository位于同一个文件夹中,但Laravel仅检测IUserRepository。看来无法找到EUserRepository。 我错过重要的事情吗?任何建议家伙?

+0

你有没有复选文件名? –

+0

是的。我已经仔细检查过它们。我甚至创建了一个新文件,用不同的名称命名它们,并将其与EUserRepository一起放入同一个文件夹中,并将其绑定到服务提供者中。和拉拉维尔仍然抛出同样的错误。 – under5hell

+0

嗨菲利普!为什么不将该文件夹注册为PSR-0或PSR-4? – hannesvdvreken

回答

1
namepsace Cribbb\Storage\User; 

它应该是命名空间吗?

编辑

资源库(LIB/Cribbb /存储/用户/ EUserRepository.php)有一个错字:

<?php 

namepsace Cribbb\Storage\User; 

因为你没有使用自动加载它只是作为加载类\EUserRepository 。 (根范围)

+0

不,不应该。我把StorageServiceProvider.php放在lib/Cribbb/Storage /中,而我的仓库和接口放在lib/Cribbb/Storage/User中。无论如何,我试过你的建议。将命名空间更改为Cribbb \ Storage \ User,laravel扔我“找不到serviceprovider”错误。然后我将文件移动到lib/Cribbb/Storage/User,在app/config/app.php中更新'providers'aaray,dump-autoload,但仍然没有运气。 :( – under5hell

+0

你在lib/Cribbb /存储/用户/ EUserRepository.php – veelasky

+2

(@veelasky你可以编辑答案是一个更具体的回答问题(可能提到文件,它是一个事实)) – alexrussell

相关问题