mirror of
https://github.com/phpv8/v8js.git
synced 2024-11-08 18:58:41 +00:00
37 lines
605 B
PHP
37 lines
605 B
PHP
|
<?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');
|
||
|
|
||
|
|