BsbPhingService is module for Zend Framework 2 that will enable you to execute phing build files from within ZF2 projects.
- Zend Framework 2 >=2.0
- Phing >=2.4.13
- The ability to execute commandline programs from PHP via proc_open.
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
- 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.
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.
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.