Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Latest commit

 

History

History
107 lines (75 loc) · 4.55 KB

README.md

File metadata and controls

107 lines (75 loc) · 4.55 KB

BsbPhingService

Introduction

BsbPhingService is module for Zend Framework 2 that will enable you to execute phing build files from within ZF2 projects.

Requirements

changelog

Latest Stable Version Total Downloads Latest Unstable Version License

[Build Status](Build Status) Code Coverage Scrutinizer Code Quality Dependency Status


Installation

Using Composer

The recommended way to get a working copy of this project is to modify your composer.json in your project root. This will take care of dependencies.

"require":{
    "bushbaby/zf2-module-phing-service":"~2.0",
 },

and then update

cd /to/your/project/directory
./composer.phar update -v

Configuration

  • Open ./configs/application.config.php and add 'BsbPhingService' to the 'modules' parameter to register the module within your application.
  • Optionally copy ./vendor/bushbaby/zf2-module-phing-service/config/bsbphingservice.global.php.dist to ./config/autoload/bsbphingservice.global.php to override some defaults.

How to use BsbPhingService

There is only one command to use which is $service->build($target, $phingOptions);.

As of version 2.0.0 an instance of the Symfony Process component is returned when you call 'build'.

$process = $phingService->build('target', array('buildFile' => 'build.xml'));
$process->getOutput();

A third argument 'immediate' has been added to build which allows you retrieve a configured but unexecuted Process instance for whenever you need to do more advanced process management. Such as getting realtime feedback or asynchronously running the build.

$process = $phingService->build('target', array('buildFile' => 'build.xml'), false);
$process->run(function ($type, $buffer) {
    if (Process::ERR === $type) {
        echo 'ERR > '.$buffer;
    } else {
        echo 'OUT > '.$buffer;
    }
});

See the official documentation of Symfony Process component.

Controller example

You can create an instance of the Service manually, however it is recommended to retrieve an configured instance from the ServiceLocator. The ServiceLocator is available in every controller so retrieval is trivial.

public function indexAction() {
    $options = array('buildFile' => __DIR__ . '/../../../data/build-example.xml');

    $buildResult = $this->getServiceLocator()->get('BsbPhingService')->build('show-defaults dist', $options);

    if ($buildResult->getExitCode() > 0) {
  	    // problem
        echo $buildResult->getCommandline();
        echo $buildResult->getErrorOutput();
    } else {
        // yeah
        echo $buildResult->getOutput();
    }

    $view = new ViewModel(array('process'=>$buildResult));

    return $view;
}

To get a quick taste you can enable the defined route in module.conf.php and point your browser at http://yourhost/phingservice to get an working example.