0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-12-23 07:11:52 +00:00
phpv8/samples/debug_callback_line_processor.php

37 lines
605 B
PHP
Raw Normal View History

2013-10-12 20:51:23 +00:00
<?php
class LineProcessor {
protected $_processor;
public function readLineLoop() {
$fh = fopen('php://stdin', 'r');
$p = $this->_processor;
while(($line = fgets($fh))) {
echo $p($line);
}
}
public function setProcessor($p) {
$this->_processor = $p;
}
}
$v8 = new V8Js();
$v8->lp = new LineProcessor();
$v8->startDebugAgent('LineProcessor', 9222, V8Js::DEBUG_AUTO_BREAK_NEVER);
$JS = <<< EOT
print("Hello LineProcessor User!\\n");
PHP.lp.setProcessor(function (foo) {
return foo.toUpperCase();
});
PHP.lp.readLineLoop();
EOT;
$v8->executeString($JS, 'processor.js');