tareqas/psym

Symfony 和 PHP 的 REPL

v1.0.2 2024-09-23 17:20 UTC

This package is auto-updated.

Last update: 2024-09-30 18:00:27 UTC


README

Symfony 和 PHP 的 REPL

pSym 适用于 Symfony 项目内外。当在 Symfony 项目中使用时,它提供额外的功能,如访问变量如 $kernel$container$doctrine$em。此外,所有注册的 项目命令 也变得可访问。

当安装了 Doctrine 时,lse 命令和 table()sql()dql() 函数可用。

函数 html() 以及诸如 自动完成自动建议文档和签名 等功能是 通用的

安装

要安装它,请在您偏好的位置使用 composer create-project 创建项目。它支持 PHP 版本 >=7.2,并且与 Symfony 版本 4567 兼容。

# The home directory might be an ideal place to install
cd ~
composer create-project tareqas/psym psym

接下来,将 your-psym-installation-path/psym/bin/ 目录添加到您系统的 PATH 中,这样您就可以直接从 shell 中运行 psym 命令。

警告:不要将其作为全局或本地包安装;它将无法工作。

命令

# list all the commands, including your project commands.
list
# or
?

自动完成和自动建议

auto-completion

要获取建议,请按 TAB 键。

注意:有时您可能需要先按 空格,然后按 TAB

# press TAB for suggestion
$kernel->
# it also works with method chaining
$kernel->getBundle()-> 
# press TAB for completion
$kernel->getBund

文档和签名

documentation and signature

您可以查看 函数属性方法 的 PHPDoc 文档和签名。

# press TAB to display the phpDoc and signature for getBundle
$kernel->getBundle 

lse

lse

lse 命令列出了由 Doctrine 管理的所有实体。

# list of of all matching tables
lse ca
# list all properties, columns, types, and default values of an entity
lse cart
# list of all matching properties for the 'cart' entity
lse cart tot

html()

function html(...$vars): void

html() 函数将变量转储并作为可浏览的 HTML 页面渲染。如果您的任何变量包含 Doctrine 对象,它将自动实例化所有代理对象。

您可以通过在最后一个参数中提供附加选项作为关联数组来调整转储。

html($var, [
    'nestedLevel' => -1, # or 'level' - how deep it should go to instantiate doctrine proxy object
    'collectionSize' => 1, # or 'size' - cut the Doctrine association collection to this specific size
    'maxString' => -1 # cut the overlong string to this specific size
])
# -1 implies no limit.

table()

function table(string $table, ?string $alias = null): EntityRepository|QueryBuilder|void

table() 函数检索给定实体的存储库。如果没有提供别名,则返回 Doctrine\ORM\EntityRepository,如果指定了别名,则返回 Doctrine\ORM\QueryBuilder

sql()

sql

function sql(string $sql, array $params = []): array|void

sql() 函数执行原始 SQL 查询,并将结果作为关联数组返回。需要 Doctrine 来使用此功能。

# press TAB to display all available tables
sql('select * from '
# press TAB to display all available columns in the 'cart' table
sql('select c. from cart c'

dql()

dql

function dql(string $dql, array $params = []): array|void

dql() 函数允许您执行 DQL 查询,并返回关联数组作为结果。

# press TAB to display all available entities
dql('select * from '
# press TAB to display all available properties in the 'Cart' entity
sql('select c. from App\Entity\Cart c'

限制:由于反斜杠(\),自动完成可能与实体类有限制。其他功能按预期工作。

更多功能

要释放全部潜力,请探索 PsySH 文档。pSym 是基于 PsySH 构建的。