2017 © Pedro Peláez
 

library binary-driver

A set of tools to build binary drivers

image

alchemy/binary-driver

A set of tools to build binary drivers

  • Thursday, April 19, 2018
  • by bburnichon
  • Repository
  • 8 Watchers
  • 49 Stars
  • 1,199,419 Installations
  • PHP
  • 25 Dependents
  • 0 Suggesters
  • 27 Forks
  • 13 Open issues
  • 16 Versions
  • 10 % Grown

The README.md

Binary Driver

Binary-Driver is a set of PHP tools to build binary drivers., (*1)

Build Status, (*2)

Why ?

You may wonder Why building a library while I can use exec or symfony/process ?., (*3)

Here is a simple answer :, (*4)

  • If you use exec, passthru, system, proc_open or any low level process handling in PHP, you should have a look to symfony/process component that will provide an OO portable, testable and secure interface to deal with this. It seems easy at first approach, but if you look at this component unit tests, you will see that handling process in a simple interface can easily become a nightmare., (*5)

  • If you already use symfony/process, and want to build binary drivers, you will always have the same common set of methods and objects to configure, log, debug, and generate processes. This library is a base to implement any binary driver with this common set of needs., (*6)

AbstractBinary

AbstractBinary provides an abstract class to build a binary driver. It implements BinaryInterface., (*7)

Implementation example :, (*8)

use Alchemy\BinaryDriver\AbstractBinary;

class LsDriver extends AbstractBinary
{
    public function getName()
    {
        return 'ls driver';
    }
}

$parser = new LsParser();

$driver = Driver::load('ls');
// will return the output of `ls -a -l`
$parser->parse($driver->command(array('-a', '-l')));

Binary detection troubleshooting

If you are using Nginx with PHP-fpm, executable detection may not work because of an empty $_ENV['path']. To avoid having an empty PATH environment variable, add the following line to your fastcgi_params config file (replace /your/current/path/ with the output of printenv PATH) :, (*9)

fastcgi_param    PATH    /your/current/path

Logging

You can log events with a Psr\Log\LoggerInterface by passing it in the load method as second argument :, (*10)

$logger = new Monolog\Logger('driver');
$driver = Driver::load('ls', $logger);

Listeners

You can add custom listeners on processes. Listeners are built on top of Evenement and must implement Alchemy\BinaryDriver\ListenerInterface., (*11)

use Symfony\Component\Process\Process;

class DebugListener extends EventEmitter implements ListenerInterface
{
    public function handle($type, $data)
    {
        foreach (explode(PHP_EOL, $data) as $line) {
            $this->emit($type === Process::ERR ? 'error' : 'out', array($line));
        }
    }

    public function forwardedEvents()
    {
        // forward 'error' events to the BinaryInterface
        return array('error');
    }
}

$listener = new DebugListener();

$driver = CustomImplementation::load('php');

// adds listener
$driver->listen($listener);

$driver->on('error', function ($line) {
    echo '[ERROR] ' . $line . PHP_EOL;
});

// removes listener
$driver->unlisten($listener);

Bundled listeners

The debug listener is a simple listener to catch stderr and stdout outputs ; read the implementation for customization., (*12)

use Alchemy\BinaryDriver\Listeners\DebugListener;

$driver = CustomImplementation::load('php');
$driver->listen(new DebugListener());

$driver->on('debug', function ($line) {
    echo $line;
});

ProcessBuilderFactory

ProcessBuilderFactory ease spawning processes by generating Symfony [Process] (http://symfony.com/doc/master/components/process.html) objects., (*13)

use Alchemy\BinaryDriver\ProcessBuilderFactory;

$factory = new ProcessBuilderFactory('/usr/bin/php');

// return a Symfony\Component\Process\Process
$process = $factory->create('-v');

// echoes '/usr/bin/php' '-v'
echo $process->getCommandLine();

$process = $factory->create(array('-r', 'echo "Hello !";'));

// echoes '/usr/bin/php' '-r' 'echo "Hello !";'
echo $process->getCommandLine();

Configuration

A simple configuration object, providing an ArrayAccess and IteratorAggregate interface., (*14)

use Alchemy\BinaryDriver\Configuration;

$conf = new Configuration(array('timeout' => 0));

echo $conf->get('timeout');

if ($conf->has('param')) {
    $conf->remove('param');
}

$conf->set('timeout', 20);

$conf->all();

Same example using the ArrayAccess interface :, (*15)

use Alchemy\BinaryDriver\Configuration;

$conf = new Configuration(array('timeout' => 0));

echo $conf['timeout'];

if (isset($conf['param'])) {
    unset($conf['param']);
}

$conf['timeout'] = 20;

License

This project is released under the MIT license., (*16)

The Versions

19/04 2018

dev-SILEX2

dev-SILEX2

A set of tools to build binary drivers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicolas Le Goff

driver binary

19/04 2018

4.1.0

4.1.0.0

A set of tools to build binary drivers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicolas Le Goff

driver binary

30/01 2017

dev-master

9999999-dev

A set of tools to build binary drivers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicolas Le Goff

driver binary

02/03 2016

1.6.0

1.6.0.0

A set of tools to build binary drivers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicolas Le Goff

driver binary

21/06 2013

1.5.0

1.5.0.0

A set of tools to build binary drivers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicolas Le Goff

driver binary

23/05 2013

1.4.1

1.4.1.0

A set of tools to build binary drivers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicolas Le Goff

driver binary

11/05 2013

1.4.0

1.4.0.0

A set of tools to build binary drivers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nicolas Le Goff

driver binary

26/04 2013

1.3.4

1.3.4.0

A set of tools to build binary drivers

  Sources   Download

MIT

The Requires

 

by Nicolas Le Goff

driver binary

26/04 2013

1.3.3

1.3.3.0

A set of tools to build binary drivers

  Sources   Download

MIT

The Requires

 

by Nicolas Le Goff

driver binary

26/04 2013

1.3.2

1.3.2.0

A set of tools to build binary drivers

  Sources   Download

MIT

The Requires

 

by Nicolas Le Goff

driver binary

24/04 2013

1.3.1

1.3.1.0

A set of tools to build binary drivers

  Sources   Download

MIT

The Requires

 

by Nicolas Le Goff

driver binary

24/04 2013

1.3.0

1.3.0.0

A set of tools to build binary drivers

  Sources   Download

MIT

The Requires

 

by Nicolas Le Goff

driver binary

24/04 2013

1.2.1

1.2.1.0

A set of tools to build binary drivers

  Sources   Download

MIT

The Requires

 

by Nicolas Le Goff

driver binary

24/04 2013

1.2.0

1.2.0.0

A set of tools to build binary drivers

  Sources   Download

MIT

The Requires

 

by Nicolas Le Goff

driver binary

24/04 2013

1.1.0

1.1.0.0

A set of tools to build binary drivers

  Sources   Download

MIT

The Requires

 

by Nicolas Le Goff

driver binary

23/04 2013

1.0.0

1.0.0.0

A set of tools to build binary drivers

  Sources   Download

MIT

The Requires

 

by Nicolas Le Goff

driver binary