christophrumpel/laravel-command-file-picker
Composer 安装命令:
composer require christophrumpel/laravel-command-file-picker
包简介
This package lets a user pick a file or class from a list during a Laravel command.
README 文档
README
This package lets you show a list of files or classes to choose from during a Laravel command.
Reasons You Might Need This Package
While using Laravel commands, you may need to run them on specific files or classes. Let's say you want to run some actions on one of your Laravel models. In the past, you may have passed a class or file as an argument to the command. This works, but it is quite cumbersome and leads to typing mistakes.
This package will make it easy for the user by prompting a list of files or classes. (like in the screenshot above) The user can then easily select one, and you can use it inside your command.
Installation
You can install the package via composer:
composer require christophrumpel/laravel-command-file-picker
Usage
Load Classes
To show the user a list of classes, you need to use the package's trait called PicksClasses. Just add it to one of your Laravel commands. (Be aware that you have to create your Laravel commands yourself.)
<?php use Illuminate\Console\Command; class MyLaravelCommand extends Command { use PicksClasses; //... }
After that you are able to show the user a list of files to choose from by calling the new askToPickClasses method:
$modelClass = $this->askToPickClasses(base_path('app/Models'));
This will show the user all the classes and give you back a collection. This collection can contain the one chosen model or all of them if you have use the All option. If you just need Laravel models, you can also load them like:
$models = $this->askToPickModels();
It will automatically look for models under your app/Models path.
Load Files
To show the user a list of files, you need to use the package's trait called PicksFiles. Just add it to one of your Laravel commands.
<?php use Illuminate\Console\Command; class MyLaravelCommand extends Command { use PicksFiles; //... }
After that you are able to show the user a list of files to choose from by calling the new askToPickFiles method. As a parameter you provide a directory path.
$files = $this->askToPickFiles(base_path('app/Models'));
This will show the user all the files and give you back a collection. This collection can contain the chosen file or all of them if you haven chosen the All option.
Filter Loaded Files
Sometimes you do not want to show all found files or classes to the user. This is when you can use a filter callable to define what results to leave out. Here is an example.
$files = $this->askToPickFiles(base_path('app/Models'), function(array $fileInfo) { return rand(0,1); });
The second param is the filter callable which gets passed to Laravel's collection filter method. It lets you loop over all files and define what to keep in the files list and what to leave out. In our example, the decision will be random. Take note that the $fileInfo variable will be an array with some details about the current file like path. In case of a model or class it will contain the class name and file path.
The filtered result will then be shown to user during the Laravel command.
Remove "All" option
If you want to remove the All option when showing a list, you can do so with an extra parameter:
$files = $this->askToPickFiles(base_path('app/Models'), $filterCallable, $showAllOption);
Testing
composer test
Changelog
Please see CHANGELOG for more information about what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security-related issues, please email christoph@christoph-rumpel.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.
christophrumpel/laravel-command-file-picker 适用场景与选型建议
christophrumpel/laravel-command-file-picker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 77.63k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2020 年 01 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「christophrumpel」 「laravel-command-file-picker」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 christophrumpel/laravel-command-file-picker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 christophrumpel/laravel-command-file-picker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 christophrumpel/laravel-command-file-picker 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package adds missing livewire test assertions.
This package sits on top of Laravel factories and provides you with dedicated factory classes for every model.
This is a PHP package for working with the Marvel developer API.
统计信息
- 总下载量: 77.63k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-01-20