laravel 拉拉维尔 | ReflectionException - 类不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24972620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:51:57  来源:igfitidea点击:

Laravel | ReflectionException - Class does not exist

phplaravellaravel-4packagecomposer-php

提问by Krynble

I created a package in the Laravel 4 workbench and it worked like a charm on my machine. Everything loaded as expected but now on another machine I'm getting the Class not found exception.

我在 Laravel 4 工作台中创建了一个包,它在我的机器上就像一个魅力。一切都按预期加载,但现在在另一台机器上,我发现 Class not found 异常。

What I have:

我拥有的:

composer.json (root)

composer.json(根)

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

Please note that the workbench directory is listed.

请注意工作台目录已列出。

Inside the workbench directory I have the vendor and package folders: workbench/krynble/contenter

在工作台目录中,我有供应商和包文件夹:workbench/krynble/contenter

Inside is the regular package structure but the most important is that there is another composer.json file (created when the package was generated):

里面是常规的包结构,但最重要的是还有另一个 composer.json 文件(在包生成时创建):

"autoload": {
    "classmap": [
        "src/migrations"
    ],
    "psr-0": {
        "Krynble\Contenter\": "src/"
    }
},

So inside of it I followed the steps to create the Service Provider cited in the documentation

所以在里面我按照步骤来创建文档中引用的服务提供者

workbench/krynble/contenter/src/Krynble/Contenter/ContenterSerivceProvider.php (also generated automaticaly) and left it as created, with only the boot method as follows:

workbench/krynble/contenter/src/Krynble/Contenter/ContenterSerivceProvider.php(也是自动生成的)并将其保留为已创建,只有启动方法如下:

public function boot()
{
    $this->package('krynble/contenter');
}

register:

登记:

public function register()
{
    //
}

provides:

提供:

public function provides()
{
    return array();
}

Added this service provider to my app.php in the providers list and invoking a die() in the boot function shows it's being called.

将此服务提供者添加到我的 app.php 的提供者列表中,并在启动函数中调用 die() 显示它正在被调用。

Last, I created my utility class:

最后,我创建了我的实用程序类:

workbench/krynble/contenter/src/Krynble/Contenter/Services/Mappers/MediaMapperSerivce.php

工作台/krynble/contenter/src/Krynble/Contenter/Services/Mappers/MediaMapperSerivce.php

<?

namespace Krynble\Contenter\Services\Mappers;
class MediaMapperService {
...
}

Finally, in my controller:

最后,在我的控制器中:

<?php

use Krynble\Contenter\Services\Mappers\MediaMapperService;

class MediaController extends BaseController {

    private $mediaMapperService;


    public function __construct(MediaMapperService $mediaMapperService)
    {
        $this->mediaMapperService = $mediaMapperService;
    }

Nice! It worked on my machine (vagrant box with ubuntu)! But on the mac notebook it's not working (so I discarded the case-sensitive thing).

好的!它在我的机器上工作(带有 ubuntu 的流浪盒)!但是在 mac 笔记本上它不起作用(所以我丢弃了区分大小写的东西)。

Any clues? Any way to debug? I'm going nuts, thrown die() in every point and can't seem to find the source.

有什么线索吗?有什么办法调试吗?我快疯了,在每一点上都抛出了 die() 并且似乎找不到来源。

Am I supposed to add something in the provides method in my service provider? If so, why did it work on my machine without adding this?

我应该在我的服务提供者的提供方法中添加一些东西吗?如果是这样,为什么不添加它就可以在我的机器上运行?

回答by Krynble

After a log of digging, I found out the problem was the weirdest of all: the short_open_tag setting in local computer was set to 1 and was set to 0 in my QA environment.

在挖掘日志后,我发现问题是最奇怪的:本地计算机中的 short_open_tag 设置设置为 1,而在我的 QA 环境中设置为 0。

The file wasn't being parsed (but no error raised) and I was getting the class does not exist message.

文件没有被解析(但没有出现错误),我收到了类不存在的消息。