[扩展推荐] 使用 Laravel Executor 简化应用程序的安装和更新
Laravel Executor 是 Ash Allen 的一个软件包,可简化你在安装或更新 Web 应用程序时的运行代码和命令。
该软件包提供了可以从 artisan 命令行运行的 「executor」类。一个基本的示例是在从远程存储库中提取项目的最新版本,然后运行以下命令:
<?php
namespace App\Executor;
use AshAllenDesign\LaravelExecutor\Classes\Executor;
class AppUpdate extends Executor
{
public function run(): Executor
{
return $this->simpleDesktopNotification('Starting Executor', 'Starting the AppUpdate Executor.')
->runExternal('composer install')
->runArtisan('migrate')
->runArtisan('cache:clear')
->completeNotification();
}
}
该命令将运行 composer 安装,执行 artisan migrations 迁移,清除缓存并通过桌面通知来告知用户。
您可以通过 artisan 命令行触发 executor。使用上面的示例,它看起来像这样:
php artisan executor:app-update
这是项目的 readme 文件里通过命令行运行 executor 的视觉效果:
如果您在代码中需要调用 executor,可以使用 run()
方法:
(new AppInstall())->run();
Learn More
您可以在 GitHub 上 ash-jc-allen/laravel-executor 了解有关此软件包的更多信息,包括完整的安装说明,查看源代码。
本文中的所有译文仅用于学习和交流目的,转载请务必注明文章译者、出处、和本文链接
我们的翻译工作遵照 CC 协议,如果我们的工作有侵犯到您的权益,请及时联系我们。