jrmgx / interactive-bundle
从命令行与您的 Symfony 项目进行交互。
v1.0.1
2023-02-20 10:48 UTC
Requires
- php: >=7.4
- ext-json: *
- psy/psysh: ^0.11
- symfony/error-handler: ^5.4|^6.0
- symfony/expression-language: ^5.4|^6.0
- symfony/finder: ^5.4|^6.0
- symfony/framework-bundle: ^5.4|^6.0
- symfony/polyfill-php80: ^1.27
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.14
- monolog/monolog: ^3.3
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.5
- symfony/symfony: ^5.4|^6.0
README
一个用于与 PsySH(php REPL)一起使用 Symfony 的包,更多信息请访问 psysh.org。
此包具体做什么?
- 启动带有应用程序依赖项的 PsySH
- 暴露辅助命令以简化应用程序的使用
快速查看
要开始
$ bin/console interactive - or - $ bin/interactive
service
辅助程序
service $your_variable_name = the_service_identifier
您不必输入完整的服务名称,辅助程序会尽力找到。
service $repo = BlogPostRepo
var_dump($repo)
object(App\Repository\BlogPostRepository) { ... }
instance
辅助程序
instance $your_variable_name = the_class_name
您不必输入完整的类名,辅助程序会尽力找到。
instance $post = BlogPost
var_dump($post)
object(App\Entity\BlogPost) { ... }
完整示例
$ bin/console interactive
This is an enhanced interactive PHP prompt for your Symfony project!
You can use those command to get class instances and services easily:
- instance $i = YourClass will give you an instance of the class
- service $s = ServiceName will give you the service
if any of those fail, you will have a prompt with a list of entries that could match,
pass *null* to be prompted from all
Psy Shell v0.11.12 (PHP 8.1.12 — cli) by Justin Hileman
> instance $post = blogPost
FOUND Class "\App\Entity\BlogPost" found for identifier: blogPost
- $post = resolved_class('\App\Entity\BlogPost');
= App\Entity\BlogPost {#8136}
> $post->setTitle('My Title')->setDate(new \DateTime())->setContent('Content');
= App\Entity\BlogPost {#8136}
> service $repo = blogpostRepository
FOUND Service "App\Repository\BlogPostRepository" found for identifier: blogpostRepository
- $repo = resolved_service('App\Repository\BlogPostRepository');
= App\Repository\BlogPostRepository {#8212}
> $repo->save($post, true);
= null
>
就是这样!您现在数据库中有一个新条目。
除此之外,它就是普通的 PsySH!您还可以 自定义它,添加自己的命令和变量。
安装
您应该使用 Composer 将此包安装到您的项目中
$ composer require --dev jrmgx/interactive-bundle
使用
$ bin/console interactive - or - $ bin/interactive
自定义 PsySH
添加自定义命令
添加自定义命令对于 PsySH 来说就像从 Psy\Command\Command
继承一样简单。
添加自定义变量
通过配置,您可以向外壳添加自定义变量。变量可以是任何类型,容器参数引用(例如 %kernel.debug%
)或服务(以 @
开头,例如 "@my_service"
)。
# config/psysh.yml psysh: variables: foo: bar router: "@router" some: [thing, else] debug: "%kernel.debug%"
现在,如果您运行 bin/interactive
然后运行 ls
,您将看到变量 $foo
、$router
、$some
和 $debug
。
> ls
Variables: $foo, $router, $some, $debug...
致谢
此包由 Jerome Gangneux 开发
此项目得以实现归功于
- Théo FIDRY:在分支之前此包的主要作者(在此处找到)
- Justin Hileman:PsySH 的作者和 PsySH 项目所有贡献者
- Adrian Palmer:领导将 PsySH 移植到 Symfony