mtrunkat / php-libphutil-composer

Composer compatible version of Facebook's Libphutil library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Composer compatible version of Facebook's Libphutil library

This is not offical port. I created this mainly to use Futures so the rest of the library may not work correctly.

Script that I use for conversion can be found here mtrunkat/php-libphutil-composer-convertor.

For more information about Libphutil check Github repository and official documentation.

Installation

Add this (Packagist) library into you composer.json:

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

And install it via php composer.phar install or php composer.phar update.

Example use

All the classes of original library are moved into Facebook\Libphutil namespace and each function [functionname] located in some file [filename].php is converted into static method Facebook\Libphutil\Functions[filename]::[functionname].

So for example in original library you use Futures this way:

<?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;
}

But in Composer version of library you have to specify namespace for classes and convert functions into static methods:

<?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;
}

You can see that class ExecFuture in now in Facebook\Libphutil namespace and function Futures() originally located in file functions.php is now static method of class Facebook\Libphutil\Functions\functions.

About

Composer compatible version of Facebook's Libphutil library

License:Apache License 2.0


Languages

Language:PHP 100.0%