本文整理汇总了PHP中Func::construct方法的典型用法代码示例。如果您正苦于以下问题:PHP Func::construct方法的具体用法?PHP Func::construct怎么用?PHP Func::construct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Func
的用法示例。
在下文中一共展示了Func::construct方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: catch
}
$flags = $append ? FILE_APPEND : 0;
$data = $data instanceof Buffer ? $data->raw : $data;
try {
$result = file_put_contents($fullPath, $data, $flags);
} catch (Exception $e) {
$helpers['handleException']($e, $fullPath);
}
//fallback for if set_error_handler didn't do it's thing
if ($result === false) {
$helpers['throwError']('EIO', $fullPath);
}
}, 'createReadStream' => function ($path, $opts = null) use(&$helpers, &$ReadStream) {
return $ReadStream->construct($path, $opts);
}, 'createWriteStream' => function ($path, $opts = null) use(&$helpers, &$WriteStream) {
return $WriteStream->construct($path, $opts);
});
$helpers = array('basePath' => getcwd(), 'ERR_MAP' => array('EACCES' => "EACCES, permission denied", 'EBADF' => "EBADF, bad file descriptor", 'EEXIST' => "EEXIST, file already exists", 'EIO' => "EIO, input/output error", 'ENOENT' => "ENOENT, no such file or directory", 'ENOTDIR' => "ENOTDIR, not a directory", 'ENOTEMPTY' => "ENOTEMPTY, directory not empty", 'EPERM' => "EPERM, operation not permitted", 'EISDIR' => "EISDIR, is a directory"), 'throwError' => function ($code, $paths = array(), $framesToPop = 0) use(&$helpers) {
$message = $helpers['ERR_MAP'][$code];
$paths = is_array($paths) ? $paths : array($paths);
foreach ($paths as $path) {
$message .= " '" . $helpers['reverseMapPath']($path) . "'";
}
$err = Error::create($message, $framesToPop + 1);
$err->set('code', $code);
throw new Ex($err);
}, 'handleException' => function ($ex, $paths = array()) use(&$helpers) {
$message = $ex->getMessage();
$paths = is_array($paths) ? $paths : array($paths);
//get the error message with the path(s) removed. this prevents words
// in the path from effecting our parsing below.
示例2: join
Test::assert('arguments length', $arguments->get('length') === 1.0);
Test::assert('arguments -> args', join(',', $arguments->args) === 'foo');
Test::assert('this is global', $self === $Array);
});
$fn->call($Array, 'foo');
});
Test::suite('Object.create', function () use($Object) {
$Animal = new Func(function () {
});
$Animal->get('prototype')->set('speak', new Func(function () {
return 'hi';
}));
$Dog = new Func(function () {
});
$Dog->set('prototype', $Object->callMethod('create', $Animal->get('prototype')));
$dog = $Dog->construct();
Test::assert('has method', $dog->get('speak') instanceof Func);
Test::assert('method call', $dog->callMethod('speak') === 'hi');
Test::assert('proto inherit', _instanceof($dog, $Dog));
Test::assert('proto inherit parent', _instanceof($dog, $Animal));
Test::assert('proto inherit top', _instanceof($dog, $Object));
$Thing = new Func(function () {
});
Test::assert('proto not instance foreign', !_instanceof($dog, $Thing));
$Dog->get('prototype')->set('speak', new Func(function () {
return 'woof';
}));
Test::assert('method override', $dog->callMethod('speak') === 'woof');
$animal = $Animal->construct();
Test::assert('method still on parent', $animal->callMethod('speak') === 'hi');
});