找不到 Laravel 4 工作台类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18499393/
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
Laravel 4 workbench class not found
提问by Ray
I'm trying to develop a package in laravel 4 - my first attempt at a package. I found a couple of tutorials which I've tried to follow:
我正在尝试在 laravel 4 中开发一个包 - 我第一次尝试包。我找到了一些我试图遵循的教程:
http://jasonlewis.me/article/laravel-4-develop-packages-using-the-workbench
and
和
http://culttt.com/2013/06/24/creating-a-laravel-4-package/
and of course in the official documentation.
当然在官方文档中。
I've followed the basic structure to create the framework. However on loading the app I get a class not found error. This relates directly to the serviceprovider I have placed in the app.php file.
我遵循了基本结构来创建框架。但是在加载应用程序时,我收到了一个找不到类的错误。这与我放置在 app.php 文件中的 serviceprovider 直接相关。
here's my entry in the providers array:
这是我在 providers 数组中的条目:
'Longestdrive\Calendar\CalendarServiceProvider'
My folder structure is:
我的文件夹结构是:
laravel/workbench/longestdrive/calendar/src/Longestdrive/Calendar
My service provider has the following entries:
我的服务提供商有以下条目:
<?php namespace Longestdrive\Calendar;
use Illuminate\Support\ServiceProvider;
class CalendarServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
$this->package('longestdrive/calendar');
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
//
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array();
}
}
I've double checked to spelling and ran a composer dump-autoload both from the root of the project and the root of the package.
我仔细检查了拼写,并从项目的根目录和包的根目录运行了 Composer dump-autoload。
I've run out of ideas for solving the class not found any ideas where I've gone wrong?
我已经用完了解决课程的想法没有找到任何我出错的想法?
The line producing the error is this one:
产生错误的行是这样的:
C:\wamp\www\googleapi\laravel\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php
Any help appreciated
任何帮助表示赞赏
Thanks
谢谢
Update: I ran a composer update as suggested in the workbench/package folder with a response nothing to update. I then ran composer at the root of the project and an error was produced:
更新:我按照工作台/包文件夹中的建议运行了 Composer 更新,但没有任何要更新的响应。然后我在项目的根目录运行 composer 并产生了一个错误:
[RuntimeException]
Error Output: PHP Fatal error: Class 'Longestdrive\Calendar\CalendarServiceProvider' not found
in C:\wamp\www\googleapi\laravel\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRe
pository.php on line 123
I probably posted the wrong error line earlier. The full exception response is:
我可能早些时候发布了错误的错误行。完整的异常响应是:
Class 'Longestdrive\Calendar\CalendarServiceProvider' not found
THe error extract:
错误摘录:
* @param \Illuminate\Foundation\Application $app
* @param string $provider
* @return \Illuminate\Support\ServiceProvider
*/
public function createProvider(Application $app, $provider)
{
return new $provider($app);
}
which I assume relates to the service provider loader not finding the CalendarServiceProvider?
我认为这与未找到 CalendarServiceProvider 的服务提供程序加载程序有关?
回答by Andrew Holt
I found that running composer install from within the workbench/[vendor]/[package] folder solved the problem.
我发现从 workbench/[vendor]/[package] 文件夹中运行 composer install 解决了这个问题。
回答by ilpaijin
I encountered the same error, so I went deeper on its flow to knew what happens.
我遇到了同样的错误,所以我更深入地了解它的流程以了解会发生什么。
So dissecting a little bit basically, in the bootstrap phase, when bootstrap/autoload.php
is loaded it runs at the end:
所以基本上剖析一下,在引导阶段,bootstrap/autoload.php
加载时它会在最后运行:
if (is_dir($workbench = __DIR__.'/../workbench'))
{
Illuminate\Workbench\Starter::start($workbench);
}
This requires EVERYworkbench/vendor/package/**/**/**/autoload.php
he found (by using Symfony Finder Component)
这需要他找到的每一个workbench/vendor/package/**/**/**/autoload.php
(通过使用 Symfony Finder 组件)
$finder->in($path)->files()->name('autoload.php')->depth('<= 3');
That's importantbecause it's expecting to find workbench/vendor/package/vendor/autoload.php
.
这很重要,因为它期望找到workbench/vendor/package/vendor/autoload.php
.
Successively in bootstrap/start.php
it gets the 'providers' defined in config/app.php
and try to load each of them:
依次在bootstrap/start.php
其中获取定义的“提供者”config/app.php
并尝试加载它们中的每一个:
$providers = $config['providers'];
$app->getProviderRepository()->load($app, $providers);
and then in ProviderRepository.php
然后在 ProviderRepository.php
foreach ($providers as $provider)
{
$instance = $this->createProvider($app, $provider);
so we'll end up with:
所以我们最终会得到:
public function createProvider(Application $app, $provider)
{
return new $provider($app);
where it tried to create an instance of a class isn't really autoloaded. And so that's why the exception thrown!
它试图创建一个类的实例的地方并没有真正自动加载。这就是抛出异常的原因!
In conclusion...
综上所述...
As @Ray said, by removing his Service from
'providers' => array(
no error is thrown causereturn new $myServiceDeclaredInProviderArray($app);
never fires for that service.As @Andrew Holt said
正如@Ray 所说,通过从不
'providers' => array(
抛出错误中删除他的服务return new $myServiceDeclaredInProviderArray($app);
,该服务永远不会触发。正如@Andrew Holt 所说
I found that running composer install from within the workbench/[vendor]/[package] folder solved the problem.
我发现从 workbench/[vendor]/[package] 文件夹中运行 composer install 解决了这个问题。
He's absolutely right because this create the autoload vendor dir and files, and everything works as we expect it to because it finds the autoload files:
他是绝对正确的,因为这会创建自动加载供应商目录和文件,并且一切都按我们预期的那样工作,因为它找到了自动加载文件:
$finder->in($path)->files()->name('autoload.php')->depth('<= 3');
- Me
php artisan dump-autoload
works as well if you remove the service from the providers array
- 我
php artisan dump-autoload
如果您从 providers 数组中删除服务,也可以正常工作
回答by edpaez
In addition to @ilpaijin's and @Andrew Holt's answer, there sometimes comes the need (when there's a new version of Laravel) to run composer update
within the workbench/vendor/package
folder.
除了@ilpaijin和@Andrew Holt的回答之外,有时还需要(当有新版本的 Laravel 时)composer update
在workbench/vendor/package
文件夹中运行。
Also, as noted here, the composer.json
within the package must require the same version of illuminate/support
as the one required of laravel/framework
in the project root's composer.json
.
此外,如上所述这里,在composer.json
包内必须要求相同版本illuminate/support
的所需的一个laravel/framework
项目根的composer.json
。
Thanks to @bisciinote that one should use:
感谢@biscii注意,应该使用:
"illuminate/support": "4.1.x"
instead of
代替
"illuminate/support": "4.x"