nadir2k/laravel-web-tinker

浏览器中的 Artisan Tinker

安装: 38

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 0

分支: 68

语言:JavaScript

dev-main 2024-05-13 02:31 UTC

This package is auto-updated.

Last update: 2024-09-13 03:14:07 UTC


README

Latest Version on Packagist GitHub Workflow Status Total Downloads

Artisan 的 tinker 命令是终端中与应用程序进行交互的绝佳方式。不幸的是,运行几行代码,进行编辑,以及复制粘贴代码可能会很麻烦。在浏览器中交互不是很好吗?

此包将为您的应用程序添加一个路由,您可以在其中随意进行交互。

Web tinker light

如果您觉得光线刺眼,还有暗色模式。

Web tinker dark

支持我们

我们在创建 最佳开源包 上投入了大量资源。您可以通过 购买我们的付费产品之一 来支持我们。

我们非常感激您从家乡寄给我们明信片,说明您正在使用我们的哪个包。您可以在 我们的联系页面 上找到我们的地址。我们将在 我们的虚拟明信片墙 上公布收到的所有明信片。

🚨 谨慎 🚨

此包可以运行任意代码。除非您知道自己在做什么,否则您绝对不应该在生产环境或处理真实世界数据的任何环境中安装或使用此包。

安装

您可以通过 composer 安装此包

composer require spatie/laravel-web-tinker --dev

接下来,您必须运行以下命令以发布此包中的资产。

php artisan web-tinker:install

可选地,您可以发布此包的配置文件。

php artisan vendor:publish --provider="Spatie\WebTinker\WebTinkerServiceProvider" --tag="config"

以下内容将被发布到 config/web-tinker.php

return [

    /*
     * The web tinker page will be available on this path.
     */
    'path' => '/tinker',

    /*
     * Possible values are 'auto', 'light' and 'dark'.
     */
    'theme' => 'auto',

    /*
     * By default this package will only run in local development.
     * Do not change this, unless you know what your are doing.
     */
    'enabled' => env('APP_ENV') === 'local',

   /*
    * This class can modify the output returned by Tinker. You can replace this with
    * any class that implements \Spatie\WebTinker\OutputModifiers\OutputModifier.
    */
    'output_modifier' => \Spatie\WebTinker\OutputModifiers\PrefixDateTime::class,

    /*
    * These middleware will be assigned to every WebTinker route, giving you the chance
    * to add your own middlewares to this list or change any of the existing middleware.
    */
    'middleware' => [
        Illuminate\Cookie\Middleware\EncryptCookies::class,
        Illuminate\Session\Middleware\StartSession::class,
        Spatie\WebTinker\Http\Middleware\Authorize::class,
    ],

    /*
     * If you want to fine-tune PsySH configuration specify
     * configuration file name, relative to the root of your
     * application directory.
     */
    'config_file' => env('PSYSH_CONFIG', null),
];

用法

默认情况下,此包只能在本地环境中运行。

访问您的应用程序的本地环境中的 /tinker,以查看交互页面。

授权

如果您想在其他环境中运行此程序(我们不推荐这样做),您必须执行以下两个步骤。

  1. 您必须在 AuthServiceProvider 中注册一个 viewWebTinker 能力。一个好的地方是在 Laravel 一起提供的 AuthServiceProvider 中做这件事。
public function boot()
{
    $this->registerPolicies();

    Gate::define('viewWebTinker', function ($user = null) {
        // return true if access to web tinker is allowed
    });
}
  1. 您必须将 web-tinker 配置文件中的 enabled 变量设置为 true

修改输出

您可以通过在 web-tinker 配置文件中的 output_modifier 键中指定输出修改器来修改 tinker 的输出。输出修改器是任何实现了 \Spatie\WebTinker\OutputModifiers\OutputModifier 的类。

这是该接口的外观。

namespace Spatie\WebTinker\OutputModifiers;

interface OutputModifier
{
    public function modify(string $output = ''): string;
}

此包的默认安装将使用 PrefixDataTime 输出修改器,该修改器将当前日期时间作为前缀添加到 Tinker 的输出中。

测试

composer test

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG

贡献

有关详细信息,请参阅 CONTRIBUTING

安全

如果您发现了关于安全性的错误,请通过 security@spatie.be 发送邮件,而不是使用问题跟踪器。

致谢

本软件包受到nova-tinker-tool软件包的启发,并使用了该软件包的代码,该软件包由Marcel Pociot开发。

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件