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

Commit

Permalink
Merge pull request #200 from KiwiJuicer/implement-zend-component-inst…
Browse files Browse the repository at this point in the history
…aller-support

Implement zend component installer support by adding ConfigProvider
  • Loading branch information
neilime authored Oct 24, 2017
2 parents 0a6ce92 + b3962a7 commit c1a4a9a
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
},
"zf": {
"config-provider": "TwbBundle\\ConfigProvider"
}
}
}
78 changes: 78 additions & 0 deletions src/TwbBundle/ConfigProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
namespace TwbBundle;

/**
* The configuration provider for the TwbBundle module
*
* @see https://docs.zendframework.com/zend-component-installer/
*/
class ConfigProvider
{
/**
* Path to the module config
*
* @const string
*/
const MODULE_CONFIG_PATH = __DIR__ . '/../../config/module.config.php';

/**
* The module config ZF2/3
*
* @var array
*/
protected $moduleConfig;

/**
* Returns the configuration array
*
* To add a bit of a structure, each section is defined in a separate
* method which returns an array with its configuration.
*
* @return array
* @throws \InvalidArgumentException
*/
public function __invoke()
{
if (!file_exists(self::MODULE_CONFIG_PATH)) {
throw new \InvalidArgumentException('Wrong path to module config file. File or directory does not exist: ' . self::MODULE_CONFIG_PATH);
}

$this->moduleConfig = require self::MODULE_CONFIG_PATH;

return [
'twbbundle' => $this->getTwbBundleOptions(),
'dependencies' => $this->getDependencies(),
'view_helpers' => $this->getViewHelpers()
];
}

/**
* Returns twb bundle options
*
* @return array
*/
protected function getTwbBundleOptions()
{
return array_key_exists('twbbundle', $this->moduleConfig) ? $this->moduleConfig['twbbundle'] : [];
}

/**
* Returns dependencies (former server_manager)
*
* @return array
*/
protected function getDependencies()
{
return array_key_exists('service_manager', $this->moduleConfig) ? $this->moduleConfig['service_manager'] : [];
}

/**
* Returns view helpers
*
* @return array
*/
protected function getViewHelpers()
{
return array_key_exists('view_helpers', $this->moduleConfig) ? $this->moduleConfig['view_helpers'] : [];
}
}
43 changes: 43 additions & 0 deletions tests/TwbBundleTest/ConfigProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace TwbBundleTest;

use TwbBundle\ConfigProvider;

/**
* Config Provider Test
*
* @package TwbBundleTest
*/
class ConfigProviderTest extends \PHPUnit_Framework_TestCase
{
/**
* The zend-component config provider
*
* @var \TwbBundle\ConfigProvider
*/
protected $configProvider;

/**
* @see \PHPUnit_Framework_TestCase::setUp()
*/
public function setUp()
{
$this->configProvider = new ConfigProvider();
}

/**
* Tests valid return values
*/
public function testInvokeReturnValues()
{
$config = $this->configProvider->__invoke();

$this->assertArrayHasKey('twbbundle', $config);
$this->assertArrayHasKey('dependencies', $config);
$this->assertArrayHasKey('view_helpers', $config);

$this->assertNotEmpty($config['twbbundle']);
$this->assertNotEmpty($config['dependencies']);
$this->assertNotEmpty($config['view_helpers']);
}
}

0 comments on commit c1a4a9a

Please sign in to comment.