tareqas / psym
Symfony 和 PHP 的 REPL
Requires
- php: >=7.2
- ext-json: *
- ext-tokenizer: *
- jetbrains/phpstorm-stubs: @dev
- phpstan/phpdoc-parser: ^1.30
- psy/psysh: ^0.11
Requires (Dev)
- doctrine/orm: ^2.19
- friendsofphp/php-cs-fixer: ^3.4
- mockery/mockery: ^1.3
- phpunit/phpunit: ^8.0
- symfony/framework-bundle: ^5.4
- symfony/runtime: ^5.4
README
Symfony 和 PHP 的 REPL
pSym 适用于 Symfony 项目内外。当在 Symfony 项目中使用时,它提供额外的功能,如访问变量如 $kernel、$container、$doctrine 和 $em。此外,所有注册的 项目命令 也变得可访问。
当安装了 Doctrine 时,lse 命令和 table()、sql() 和 dql() 函数可用。
函数 html() 以及诸如 自动完成、自动建议 和 文档和签名 等功能是 通用的。
安装
要安装它,请在您偏好的位置使用 composer create-project 创建项目。它支持 PHP 版本 >=7.2,并且与 Symfony 版本 4、5、6 和 7 兼容。
# 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 ?
自动完成和自动建议
要获取建议,请按 TAB 键。
注意:有时您可能需要先按
空格,然后按TAB。
# press TAB for suggestion $kernel-> # it also works with method chaining $kernel->getBundle()-> # press TAB for completion $kernel->getBund
文档和签名
您可以查看 函数、属性 和 方法 的 PHPDoc 文档和签名。
# press TAB to display the phpDoc and signature for getBundle $kernel->getBundle
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()
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()
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 构建的。




