jrmgx/interactive-bundle

从命令行与您的 Symfony 项目进行交互。

安装: 34

依赖者: 0

建议者: 0

安全: 0

星级: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

v1.0.1 2023-02-20 10:48 UTC

This package is auto-updated.

Last update: 2024-09-20 14:11:05 UTC


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 开发

此项目得以实现归功于