mtrunkat / libphutil

此包已被废弃且不再维护。未建议替代包。

Libphutil 库的 Composer 兼容版本(非官方)。

dev-master 2014-05-13 09:28 UTC

This package is not auto-updated.

Last update: 2020-02-21 15:54:08 UTC


README

这不是官方端口。我创建此端口主要是为了使用Future,因此库的其余部分可能无法正确工作。

我使用的转换脚本可以在mtrunkat/php-libphutil-composer-convertor找到。

有关 Libphutil 的更多信息,请查看GitHub 仓库和官方文档

安装

将此库(Packagist)添加到您的 composer.json 中

{
    "require" : {
        "mtrunkat/lbphutil" : "dev-master"
    }
}

然后通过 php composer.phar installphp composer.phar update 安装。

示例使用

原始库中的所有 都已移动到 Facebook\Libphutil 命名空间,每个位于某个文件 [filename].php 中的 函数 [functionname] 都已转换为静态方法 Facebook\Libphutil\Functions[filename]::[functionname]

例如,在原始库中您这样使用 Futures

<?php
	
require_once 'path/to/libphutil/src/__phutil_library_init__.php';

$futures = array();
$futures['test a'] = new ExecFuture('ls');
$futures['test b'] = new ExecFuture('ls -l -a');
	
foreach (Futures($futures) as $dir => $future) {
    list($stdout, $stderr) = $future->resolvex();
	
    print $stdout;
}

但在库的 Composer 版本中,您必须指定类的命名空间并将函数转换为静态方法

<?php

require_once 'vendor/autoload.php';
	
use Facebook\Libphutil\ExecFuture;
use Facebook\Libphutil\Functions\functions;
	
$futures = array();
$futures['test a'] = new ExecFuture('ls');
$futures['test b'] = new ExecFuture('ls -l -a');
	
foreach (functions::Futures($futures) as $dir => $future) {
    list($stdout, $stderr) = $future->resolvex();
	
    print $stdout;
}

您可以看到类 ExecFuture 现在位于 Facebook\Libphutil 命名空间中,而原本位于 functions.php 文件中的函数 Futures() 现在是类 Facebook\Libphutil\Functions\functions 的静态方法。