$helpers['throwError']('EIO', $fullPath); } $self->stream = $stream; $self->finished = false; }); $prototype = $WriteStream->get('prototype'); $prototype->setMethods(array('setEncoding' => function ($enc) { $self = Func::getContext(); $self->opts->set('encoding', $enc); }, 'write' => function ($data, $enc = null) use(&$helpers) { $self = Func::getContext(); if ($self->finished) { return; } $data = $data instanceof Buffer ? $data->raw : $data; write_all($self->stream, $data); }, 'end' => function () { $self = Func::getContext(); if ($self->finished) { return; } $self->finished = true; fclose($self->stream); }), true, false, true); $methods = array('isFile' => function ($path) use(&$helpers) { $fullPath = $helpers['mapPath']($path); return $helpers['isFile']($fullPath); }, 'isDir' => function ($path) use(&$helpers) { $fullPath = $helpers['mapPath']($path); return $helpers['isDir']($fullPath); }, 'copyFile' => function ($src, $dst) use(&$helpers) {
if (!$toString instanceof Func) { $toString = $value->get('toString'); } if (!$toString instanceof Func) { $toString = Object::$protoObject->get('toString'); } $value = $toString->call($value); } else { $value = to_string($value); } $output[] = $value; } return join(' ', $output) . "\n"; }; $console = new Object(); $console->set('log', new Func(function () use(&$stdout, &$toString) { if ($stdout === null) { $stdout = fopen('php://stdout', 'w'); } $output = $toString(func_get_args()); write_all($stdout, $output); })); $console->set('error', new Func(function () use(&$stderr, &$toString) { if ($stderr === null) { $stderr = fopen('php://stderr', 'w'); } $output = $toString(func_get_args()); write_all($stderr, $output); })); return $console; });