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

Commit

Permalink
BC Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
basz committed Oct 15, 2012
1 parent 707b8ec commit 5a6312e
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 105 deletions.
44 changes: 6 additions & 38 deletions Module.php
@@ -1,39 +1,7 @@
<?php

namespace PhingService;

use Zend\Module\Consumer\AutoloaderProvider,
Zend\Module\Listener\ModuleResolverListener;

class Module
{

public function getConfig($env = null)
{
return include __DIR__ . '/configs/module.config.php';
}

public function getServiceConfiguration()
{
return array(
'factories' => array(
'PhingService' => function ($sm) {
$service = new \PhingService\Service();

$service->setOptions($sm->get('PhingService.serviceOptions'));
$service->setPhingOptions($sm->get('PhingService.phingOptions'));

return $service;
},
'PhingService.serviceOptions' => function ($sm) {
$config = $sm->get('config');
return new \PhingService\ServiceOptions($config['PhingService.serviceOptions']);
},
'PhingService.phingOptions' => function ($sm) {
$config = $sm->get('config');
return new \PhingService\PhingOptions($config['PhingService.phingOptions']);
},
),
);
}
}
/**
* This file is placed here for compatibility with Zendframework 2's ModuleManager.
* It allows usage of this module even without composer.
* The original Module.php is in 'src/BsbPhingService' in order to respect PSR-0
*/
require_once __DIR__ . '/src/BsbPhingService/Module.php';
11 changes: 6 additions & 5 deletions README.md
@@ -1,7 +1,7 @@
# PhingService
# BsbPhingService

## Introduction
PhingService is module for Zend Framework 2 that will enable you to run
BsbPhingService is module for Zend Framework 2 that will enable you to run
[phing](http://www.phing.info/ "Phing") build files from within ZF2 projects.

## Requirements
Expand All @@ -16,6 +16,7 @@ PLEASE USE AT YOUR OWN RISK.

* v1.0.0-beta1 - initial release
* v1.0.0-beta2 - 'composerized', updated to zf2-beta-4
* v1.0.0-beta3 - updated to zf2 2.0.0+ / namespace and configuration key changed!

[![Build Status](https://secure.travis-ci.org/basz/zf2-module-phing-service.png?branch=master)](http://travis-ci.org/basz/zf2-module-phing-service)

Expand All @@ -32,7 +33,7 @@ in your project root. This will take care of dependancies.
and then update

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

## Configuration

Expand All @@ -41,7 +42,7 @@ and then update
* Optionally copy `.../vendor/bushbaby/zf2-module-phing-service/config/module.phingservice.global.php.dist` to
`.../config/autoload/module.phingservice.global.php` to override some defaults.

## How to use PhingService
## How to use BsbPhingService
There is only one command to use which is `$Service->build($target, $phingOptions);`. The
build method returns an associative array that contains the return status of the phing
executable, the command has been issued and any output generated by phing (Both stdout and
Expand All @@ -55,7 +56,7 @@ every controller so retrieval is trivial.
public function indexAction() {
$options = array('buildFile' => __DIR__ . '/../../../data/build-example.xml');

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

if ($buildResult['returnStatus'] > 0) {
// problem
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -16,8 +16,8 @@
],
"require":{
"php": ">=5.3.3",
"phing/phing":"dev-master",
"zendframework/zendframework": "dev-master"
"phing/phing":">=2.4.12",
"zendframework/zendframework": "2.0.*"
},
"autoload": {
"psr-0": {
Expand Down
Expand Up @@ -30,19 +30,22 @@ $phingOptions = array(


return array(
'PhingService.serviceOptions' => $serviceOptions,
'PhingService.phingOptions' => $phingOptions,
'bsbphingservice' => array(
'service' => $serviceOptions,
'phing' => $phingOptions,
),

/* Enable the following section to get instant gratification at http://localhost/phingservice
*
'router' => array(
'routes' => array(
'PhingService' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'type' => 'Literal',
'options' => array(
'route' => '/phingservice',
'defaults' => array(
'controller' => 'phingservice.index',
'__NAMESPACE__' => 'BsbPhingService\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
Expand Down
25 changes: 15 additions & 10 deletions configs/module.config.php
@@ -1,20 +1,25 @@
<?php

return array(
'PhingService.serviceOptions' => array(
'phpBin' => null, /* will attempt auto-detection via exec 'which php' */
'phingPath' => null, /* will assume composer installation and attempt auto detect */
),
'PhingService.phingOptions' => array(
'bsbphingservice' => array(
'service' => array(
'phpBin' => null, /* will attempt auto-detection via exec 'which php' */
'phingPath' => null, /* will assume composer installation and attempt auto detect */
),
'phing' => array(

),
),
'controllers' => array(
'invokables' => array(
'phingservice.index' => 'PhingService\Controller\IndexController',
'BsbPhingService\Controller\Index' => 'BsbPhingService\Controller\IndexController',
),
),
'view_manager' => array(
'template_path_stack' => array(
'PhingService' => __DIR__ . '/../view',
'template_map' => array(
'bsb-phing-service/index/index' => __DIR__ . '/../view/index/index.phtml',
),
),
);
)
);


@@ -1,6 +1,6 @@
<?php

namespace PhingService\Controller;
namespace BsbPhingService\Controller;

use Zend\Mvc\Controller\AbstractActionController,
Zend\View\Model\ViewModel;
Expand All @@ -12,10 +12,9 @@ public function indexAction()
{
$options = array('buildFile' => __DIR__ . '/../../../data/build-example.xml');

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

$view = new ViewModel($buildResult);
$view->setTerminal(true);

return $view;
}
Expand Down
70 changes: 70 additions & 0 deletions src/BsbPhingService/Module.php
@@ -0,0 +1,70 @@
<?php

namespace BsbPhingService;

use Zend\Loader\AutoloaderFactory;
use Zend\Loader\StandardAutoloader;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;

use BsbPhingService\Options\Service as ServiceOptions;
use BsbPhingService\Options\Phing as PhingOptions;

class Module implements AutoloaderProviderInterface, ConfigProviderInterface, ServiceProviderInterface
{

/**
* {@inheritDoc}
*/
public function getAutoloaderConfig()
{
return array(
AutoloaderFactory::STANDARD_AUTOLOADER => array(
StandardAutoloader::LOAD_NS => array(
__NAMESPACE__ => __DIR__,
),
),
);
}

/**
* {@inheritDoc}
*/
public function getConfig($env = null)
{
return include __DIR__ . '/../../configs/module.config.php';
}

/**
* {@inheritDoc}
*/
public function getServiceConfig()
{
return array(
'aliases' => array(

),
'factories' => array(
'BsbPhingService' => function ($sm) {
$service = new Service\Phing();

$service->setOptions($sm->get('BsbPhingService.serviceOptions'));
$service->setPhingOptions($sm->get('BsbPhingService.phingOptions'));

return $service;
},
'BsbPhingService.serviceOptions' => function ($sm) {
$config = $sm->get('config');

return new ServiceOptions($config['bsbphingservice']['service']);
},
'BsbPhingService.phingOptions' => function ($sm) {
$config = $sm->get('config');

return new PhingOptions($config['bsbphingservice']['phing']);
},
),
);
}
}
@@ -1,11 +1,11 @@
<?php

namespace PhingService;
namespace BsbPhingService\Options;

use Zend\Stdlib\AbstractOptions;
use Zend\Stdlib\Parameters;

class PhingOptions extends AbstractOptions
class Phing extends AbstractOptions
{

protected $buildFile = null;
Expand Down
@@ -1,11 +1,11 @@
<?php

namespace PhingService;
namespace BsbPhingService\Options;

use Zend\Stdlib\AbstractOptions,
PhingService\Service;
use Zend\Stdlib\AbstractOptions;
use BsbPhingService\Service\Phing;

class ServiceOptions extends AbstractOptions
class Service extends AbstractOptions
{

/**
Expand All @@ -30,7 +30,7 @@ public function __construct(array $options = null)
public function setPhpBin($path = null)
{
if ($path === null) {
if (!Service::hasExec()) {
if (!Phing::hasExec()) {
throw new \RuntimeException("Not able to use PHP's exec method");
}

Expand Down
@@ -1,8 +1,11 @@
<?php

namespace PhingService;
namespace BsbPhingService\Service;

class Service
use BsbPhingService\Options\Service as ServiceOptions;
use BsbPhingService\Options\Phing as PhingOptions;

class Phing
{

/**
Expand Down
29 changes: 0 additions & 29 deletions tests/Bootstrap.php
@@ -1,10 +1,5 @@
<?php

// Set error reporting pretty high
error_reporting(E_ALL | E_STRICT);

use Zend\Loader\AutoloaderFactory;

chdir(__DIR__);
$previousDir = '.';
while (!is_dir($previousDir . DIRECTORY_SEPARATOR . 'vendor')) {
Expand All @@ -20,27 +15,3 @@

// Load composer autoloader
require_once $appRoot . '/vendor/autoload.php';

require_once (getenv('ZF2_PATH') ? : 'vendor/zendframework/zendframework/library') . '/Zend/Loader/AutoloaderFactory.php';

// setup autoloader
AutoloaderFactory::factory();

$rootPath = realpath(dirname(__DIR__));
$testsPath = "$rootPath/tests";

if (is_readable($testsPath . '/TestConfiguration.php')) {
require_once $testsPath . '/TestConfiguration.php';
} else {
require_once $testsPath . '/TestConfiguration.php.dist';
}

// load autoload of zf2 module if available

if (file_exists(__DIR__ . '/../autoload_classmap.php')) {
\Zend\Loader\AutoloaderFactory::factory(
array('Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/../autoload_classmap.php',
),
));
}
10 changes: 5 additions & 5 deletions tests/PhingServiceTest/ServiceTest.php
@@ -1,10 +1,10 @@
<?php

namespace PhingServiceTest;
namespace BsbPhingServiceTest;

use PhingService\Service,
PhingService\ServiceOptions,
PhingService\PhingOptions;
use BsbPhingService\Service\Phing;
use BsbPhingService\Options\Service as ServiceOptions;
use BsbPhingService\Options\Phing as PhingOptions;

class ServiceTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -19,7 +19,7 @@ public function setUp()
{
$so = new ServiceOptions();
$po = new PhingOptions();
$this->service = new Service($so, $po);
$this->service = new Phing($so, $po);
}

public function testOptionDiscoveryPhpBin()
Expand Down
File renamed without changes.

0 comments on commit 5a6312e

Please sign in to comment.