简体   繁体   English

“RuntimeException:尚未设置立面根”

[英]"RuntimeException: a facade root has not been set"

I'm having an issue in a Laravel Zero project I'm working on.我在我正在处理的 Laravel 零项目中遇到问题。 I'm working on a command that handles direct file transfers between 2 disks—1 SFTP and another local.我正在处理一个处理 2 个磁盘(1 个 SFTP 和另一个本地磁盘)之间的直接文件传输的命令。

I have configured both correctly and tested that I'm able to transfer files between them using the Storage code below.我已经正确配置并测试了我能够使用下面的Storage代码在它们之间传输文件。 My issue pops up when I try to do this using the spatie/async package to create a pool of concurrent transfers (or maybe just the way I'm trying to do it).当我尝试使用spatie/async package 创建并发传输池(或者可能只是我尝试这样做的方式)来执行此操作时,会出现我的问题。

$pool = Pool::create()
        ->concurrency($limit);

$progress = $this->output->createProgressBar($file_list);

if(!Storage::disk('local')->exists($local_folder_path)) {
    Storage::disk('local')->makeDirectory($local_folder_path);
}

foreach($file_list as $filename => $remote_path) {
    $pool->add(function() use ($remote_path, $filename, $local_folder_path) {
        Storage::disk('local')
            ->writeStream(
                "{$local_folder_path}/{$filename}",
                 Storage::disk('remote')->readStream($remote_path)
            );

        return $filename;
    })->then(function($filename) use (&$progress) {
        $this->info("{$filename} downloaded");
        $progress->advance();
    })->catch(function($exception) {
        $this->error($exception);
    });
}

$pool->wait();
$progress->finish();

By the way, the error, RuntimeException: a facade root has not been set , is being printed to my console via the catch() handler for the first item in the pool.顺便说一下,错误RuntimeException: a facade root has not been set正在通过池中第一项的catch()处理程序打印到我的控制台。 I did discover that much.我确实发现了这么多。

I've searched for answers to this issue, but all of the articles and other SO/Stack Exchange postings I've come across didn't seem even similar to whatever's causing my issue.我已经搜索了这个问题的答案,但我遇到的所有文章和其他 SO/Stack Exchange 帖子似乎与导致我的问题的原因都不相似。

Thanks in advance for any help.在此先感谢您的帮助。

The problem is that your callback (child process) is running without any setup.问题是您的回调(子进程)在没有任何设置的情况下运行。

A Task is useful in situations where you need more setup work in the child process.在您需要在子进程中进行更多设置工作的情况下,任务很有用。 Because a child process is always bootstrapped from nothing, chances are you'll want to initialise eg.因为子进程总是从无到有,所以您很可能想要初始化,例如。 the dependency container before executing the task.执行任务之前的依赖容器。

The facades are setup by the kernel that runs the \LaravelZero\Framework\Bootstrap\RegisterFacades::class .外观由运行\LaravelZero\Framework\Bootstrap\RegisterFacades::class的 kernel 设置。

You can create an instance of the kernel and run the bootstrap method to have your facades setup properly.您可以创建 kernel 的实例并运行引导方法以正确设置外观。

$pool->add(function() use ($remote_path, $filename, $local_folder_path) {
        $app = require __DIR__.'/../../bootstrap/app.php';

        $kernel = $app->make(\Illuminate\Contracts\Console\Kernel::class);

        $kernel->bootstrap();

        Storage::disk('local')
            ->writeStream(
                "{$local_folder_path}/{$filename}",
                 Storage::disk('remote')->readStream($remote_path)
            );

        return $filename;
    })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误:未捕获RuntimeException:尚未设置外观根 - Fatal error: Uncaught RuntimeException: A facade root has not been set 未捕获的 RuntimeException:尚未设置外观根。 在 Facade.php:258 升级到 Laravel 时 - Uncaught RuntimeException: A facade root has not been set. in Facade.php:258 when upgrading to Laravel 7 在共享主机上使用 Laravel 项目部署错误(未捕获的 RuntimeException:尚未设置外观根) - Deploy error with Laravel project on Shared Hosting (Uncaught RuntimeException: A facade root has not been set) 设置Illuminate查询生成器-Uncaught RuntimeException:尚未设置外观根 - Setting up Illuminate query builder - Uncaught RuntimeException: A facade root has not been set 将 Laravel 从 5.7 更新到 5.8 会导致此错误:致命错误:未捕获的运行时异常:尚未设置外观根 - updating Laravel from 5.7 to 5.8 results in this error: Fatal error: Uncaught RuntimeException: A facade root has not been set 获取 RuntimeException:尚未设置外观根。 在 /var/www/html/vendor/.../Illuminate/Support/Facades/Facade.php - Getting RuntimeException: A facade root has not been set. in /var/www/html/vendor/.../Illuminate/Support/Facades/Facade.php 尚未设置外观根。 流明 - A facade root has not been set. in lumen Laravel 5.4尚未设置立面根 - Laravel 5.4 A facade root has not been set Laravel 5.7:尚未设置外观根 - Laravel 5.7: A facade root has not been set Laravel 6:尚未设置外观根 - Laravel 6 : A facade root has not been set
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM