承接 jonathrg/repl-breakpoint 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jonathrg/repl-breakpoint

Composer 安装命令:

composer require jonathrg/repl-breakpoint

包简介

Inject a REPL anywhere in your PHP script

README 文档

README

ReplBreakpoint lets you start a REPL at any point in a PHP script and gives you access to the state of execution at that point.

Install

composer require jonathrg/repl-breakpoint

Usage

Here we define a variable and a function, and then call repl(get_defined_vars()).

// File: examples/simple_example.php
<?php
require_once __DIR__.'/../vendor/autoload.php';
use function ReplBreakpoint\repl;

$a = 2;
function sq($x) { return $x * $x; }

repl(get_defined_vars());

Execute the script with PHP, and a REPL will be started on line 8. It has access to the variables we defined in the parent script:

$ php examples/simple_example.php
REPL launched
To exit, write "exit" or press Ctrl+C.
> $a
2
> [$a, $a+2]
[2, 4]
> sq($a)
4

A variable called $_ANS always keeps track of the last result:

> $_ANS
4

Multiline code

Multiline code is fine: input is automatically buffered if the parentheses are unbalanced...

> function cube($x) {
    return sq($x)*$x;
    }

> cube($_ANS)
64

... or whenever you end a line with \ or /.

> $_ANS \

> -2
62

Options

Printer

You can swap out the function ReplBreakpoint uses to print results. Just add it as an option in your code:

// File: examples/simple_example.php
...
repl(get_defined_vars(), ['printer' => 'print_r']);

Results are now printed with print_r.

$ php examples/simple_example.php
REPL launched
To exit, write "exit" or press Ctrl+C.
> $a
2
> [$a, $a+2]
Array
(
    [0] => 2
    [1] => 4
)

Any function which takes one parameter (the value to be printed) is OK.

Function name, file name and line number

Provide repl() with a file and a line number to have it printed at the start of the session:

// File: examples/simple_example.php
...
repl(get_defined_vars(), ['file' => __FILE__, 'line' => __LINE__, 'function' => __FUNCTION__]);

Run it (we called repl() outside of a function context, so no function is shown):

$ php examples/simple_example.php
REPL launched in file path\to\examples\simple_example.php on line 8
To exit, write "exit" or press Ctrl+C.
> 

Or just set the 'quiet' flag to skip the info altogether:

// File: examples/simple_example.php
...
repl(get_defined_vars(), ['quiet' => true]);

Run it:

$ php examples/simple_example.php
>

Error handler and shutdown function

By default, repl() will try to just echo the error and carry on. You can override this behaviour by providing your own callbacks as 'error_handler' and 'shutdown_function' options. The callback must be compatible with set_error_handler and register_shutdown_function, respectively.

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-06-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固