vaibhavpandeyvpz/prayog
Composer 安装命令:
composer require --dev vaibhavpandeyvpz/prayog
包简介
A dead simple, minimal REPL (Read-Evaluate-Print-Loop) for PHP 8.2+
关键字:
README 文档
README
A dead simple, minimal REPL (Read-Evaluate-Print-Loop) for PHP 8.2+.
Features
- 🎯 Dead Simple - Minimal codebase with clear, focused classes
- 🧩 Modular - Clean separation of concerns
- 🎨 Modern - Built with PHP 8.2+ features (typed properties, enums, match expressions)
- 🎨 Colorful - Syntax-highlighted output
- 📝 History - Command history support via readline
- 📄 Multiline Support - Automatic detection and explicit backslash continuation
- 🔧 Extensible - Easy to customize and extend
Requirements
- PHP 8.2 or higher
ext-readlineextension
Installation
Install via Composer:
composer require vaibhavpandeyvpz/prayog
Or add to your composer.json:
{
"require": {
"vaibhavpandeyvpz/prayog": "^1.0"
}
}
Then run:
composer install
Usage
Basic Usage
./bin/prayog
Or if installed via Composer:
vendor/bin/prayog
Programmatic Usage
<?php use Prayog\Config; use Prayog\Repl; // Create a custom configuration $config = new Config( prompt: 'myapp> ', historyFile: '/path/to/history', colorOutput: true, welcomeMessage: "Welcome to MyApp REPL!\nPHP " . PHP_VERSION, ); // Create and start the REPL $repl = new Repl($config); // Optionally set initial variables $repl->setVariable('app', $myApp); $repl->setVariables(['user' => $user, 'db' => $db]); // Start the REPL $repl->start();
Examples
prayog> $x = 42 int(42) prayog> $name = "Prayog" string(6) "Prayog" prayog> $numbers = [1, 2, 3, 4, 5] array(5) [0 => 1, 1 => 2, 2 => 3, ...] prayog> array_sum($numbers) int(15) prayog> class Calculator { *> public function add($a, $b) { *> return $a + $b; *> } *> } prayog> $calc = new Calculator() object(Calculator) prayog> $calc->add(10, 20) int(30) prayog> exit
Multiline Input
Prayog supports multiline input in two ways:
- Automatic Detection - The REPL automatically detects incomplete statements (unbalanced braces, brackets, parentheses) and continues reading:
prayog> if ($x > 0) { *> echo "Positive"; *> }
- Backslash Continuation - Use a backslash (
\) at the end of a line to explicitly continue on the next line:
prayog> $result = $a + \ *> $b + \ *> $c int(15)
Configuration
The Config class allows you to customize the REPL behavior:
prompt(string, default:'prayog> ') - The prompt string displayed before each inputhistoryFile(string|null, default:null) - Path to history file. Ifnull, uses~/.prayog_historycolorOutput(bool, default:true) - Enable/disable colored outputwelcomeMessage(string|null, default:null) - Custom welcome message. Ifnull, shows default message
Example with custom welcome message:
$config = new Config( prompt: 'myapp> ', welcomeMessage: "MyApp Interactive Shell\nVersion 1.0.0\n", ); $repl = new Repl($config);
Testing
The library includes comprehensive test coverage. To run the tests:
# Install development dependencies composer install # Run tests vendor/bin/phpunit # Run tests with coverage (requires xdebug) XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text
Test Coverage
The test suite includes:
- 110 tests covering all components
- 79% code coverage (core logic at 100%)
- Tests for Config, Evaluator, Formatter, ReadlineInput, and Repl classes
- Integration tests and edge case handling
Architecture
The library is organized into clean, focused modules:
Repl- Main REPL class that orchestrates the read-eval-print loopConfig- Configuration with sensible defaultsInput\ReadlineInput- Handles readline input and historyEvaluator- Evaluates PHP code and manages variable scopeOutput\Formatter- Formats output with syntax highlighting
All classes are designed to be extensible - you can extend any class to customize behavior.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE file for details.
vaibhavpandeyvpz/prayog 适用场景与选型建议
vaibhavpandeyvpz/prayog 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「debug」 「cli」 「testing」 「console」 「shell」 「development」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vaibhavpandeyvpz/prayog 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vaibhavpandeyvpz/prayog 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vaibhavpandeyvpz/prayog 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Debug your SimpleBus EventBus and CommandBus
nice output for debug functions for PHP 5.3
Testing Suite For Lumen like Laravel does.
Analysis module for finding problematical shop data.
Twig extensions for Tracy Debugger
The PHP SDK for Checkmango
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 38
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-02