engwaqas / laravel-web-tinker
浏览器中的Artisan Tinker,这是一个从spite web tinker测试分支而来的个人包
Requires
- php: ^7.2|^8.1
- illuminate/cookie: ^5.8|^6.0|^7.0|^8.0
- illuminate/session: ^5.8|^6.0|^7.0|^8.0
- illuminate/support: ^5.8|^6.0|^7.0|^8.0|^9.0
- laravel/tinker: ^1.0|^2.0
Requires (Dev)
- orchestra/testbench: ^3.8|^4.0|^5.0|^6.0
- phpunit/phpunit: ^8.0|^9.0
This package is auto-updated.
Last update: 2024-09-29 06:03:10 UTC
README
Artisan的tinker命令是终端中测试应用的绝佳方式。遗憾的是,运行几行代码、进行编辑和复制粘贴代码可能会让人感到烦恼。在浏览器中测试不是更好吗?
此包将向您的应用添加一个路由,您可以在其中随心所欲地进行测试。
如果您觉得光线刺眼,也有暗黑模式。
支持我们
我们投入了大量资源来创建最好的开源包。您可以通过购买我们的付费产品来支持我们。
我们非常感谢您从家乡寄来明信片,并说明您正在使用我们的哪个包。您可以在我们的联系页面上找到我们的地址。我们将发布所有收到的明信片在我们的虚拟明信片墙上。
🚨 警告 🚨
此包可以运行任意代码。除非您知道自己在做什么,否则您不应在生产环境或任何处理真实数据的环境中安装或使用此包。
安装
您可以通过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, /* * 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以查看tinker页面。
授权
如果您想在其他环境中运行此包(我们不推荐这样做),您必须执行以下两个步骤。
- 您必须在
AuthServiceProvider中注册一个viewWebTinker能力。一个好的做法是在Laravel附带的AuthServiceProvider中这样做。
public function boot() { $this->registerPolicies(); Gate::define('viewWebTinker', function ($user = null) { // return true if access to web tinker is allowed }); }
- 您必须在
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。
安全性
如果您发现任何与安全相关的问题,请通过freek@spatie.be发送电子邮件,而不是使用问题跟踪器。
致谢
本软件包受到nova-tinker-tool软件包的启发,并使用了其中的一些代码,该软件包由Marcel Pociot提供。
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。