-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #390 from svycka/refactor-config
make config ready for zend-expressive and ZF
- Loading branch information
Showing
8 changed files
with
190 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,14 @@ | |
{ | ||
"name": "Jean-Marie Leroux", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Florent Blaison", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Bas Kamer", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
|
@@ -52,6 +60,10 @@ | |
"branch-alias": { | ||
"dev-master": "2.4-dev", | ||
"dev-develop": "3.0-dev" | ||
}, | ||
"zf": { | ||
"component": "ZfcRbac", | ||
"config-provider": "ZfcRbac\\ConfigProvider" | ||
} | ||
}, | ||
"scripts": { | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ZfcRbac; | ||
|
||
/** | ||
* The configuration provider for the ZfcRbac module | ||
* | ||
* @see https://docs.zendframework.com/zend-component-installer/ | ||
*/ | ||
final class ConfigProvider | ||
{ | ||
public function __invoke() | ||
{ | ||
return [ | ||
'dependencies' => $this->getDependencyConfig(), | ||
'zfc_rbac' => $this->getModuleConfig(), | ||
]; | ||
} | ||
|
||
public function getDependencyConfig(): array | ||
{ | ||
return [ | ||
'factories' => [ | ||
\ZfcRbac\Assertion\AssertionContainerInterface::class => \ZfcRbac\Container\AssertionContainerFactory::class, | ||
\ZfcRbac\Options\ModuleOptions::class => \ZfcRbac\Container\ModuleOptionsFactory::class, | ||
\ZfcRbac\Role\InMemoryRoleProvider::class => \ZfcRbac\Container\InMemoryRoleProviderFactory::class, | ||
\ZfcRbac\Role\ObjectRepositoryRoleProvider::class => \ZfcRbac\Container\ObjectRepositoryRoleProviderFactory::class, | ||
\ZfcRbac\Service\AuthorizationServiceInterface::class => \ZfcRbac\Container\AuthorizationServiceFactory::class, | ||
\ZfcRbac\Service\RoleServiceInterface::class => \ZfcRbac\Container\RoleServiceFactory::class, | ||
\ZfcRbac\Rbac::class => \Zend\ServiceManager\Factory\InvokableFactory::class, | ||
], | ||
]; | ||
} | ||
|
||
public function getModuleConfig(): array | ||
{ | ||
return [ | ||
// Assertion plugin manager | ||
'assertion_manager' => [], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,20 +21,18 @@ | |
|
||
namespace ZfcRbac; | ||
|
||
/** | ||
* Class ModuleConfig | ||
* | ||
* @author Florent Blaison <[email protected]> | ||
* @licence MIT | ||
*/ | ||
final class ModuleConfig | ||
final class Module | ||
{ | ||
public function __invoke(): array | ||
/** | ||
* Return default ZfcRbac configuration for zend-mvc applications. | ||
*/ | ||
public function getConfig() | ||
{ | ||
$config = []; | ||
$config = array_merge_recursive($config, require __DIR__ . '/../config/config.global.php'); | ||
$config = array_merge_recursive($config, require __DIR__ . '/../config/dependencies.global.php'); | ||
$provider = new ConfigProvider(); | ||
|
||
return $config; | ||
return [ | ||
'service_manager' => $provider->getDependencyConfig(), | ||
'zfc_rbac' => $provider->getModuleConfig(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ZfcRbacTest; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use ZfcRbac\ConfigProvider; | ||
|
||
/** | ||
* @covers \ZfcRbac\ConfigProvider | ||
*/ | ||
class ConfigProviderTest extends TestCase | ||
{ | ||
public function testProvidesExpectedConfiguration() | ||
{ | ||
$provider = new ConfigProvider(); | ||
$expected = [ | ||
'factories' => [ | ||
\ZfcRbac\Assertion\AssertionContainerInterface::class => \ZfcRbac\Container\AssertionContainerFactory::class, | ||
\ZfcRbac\Options\ModuleOptions::class => \ZfcRbac\Container\ModuleOptionsFactory::class, | ||
\ZfcRbac\Role\InMemoryRoleProvider::class => \ZfcRbac\Container\InMemoryRoleProviderFactory::class, | ||
\ZfcRbac\Role\ObjectRepositoryRoleProvider::class => \ZfcRbac\Container\ObjectRepositoryRoleProviderFactory::class, | ||
\ZfcRbac\Service\AuthorizationServiceInterface::class => \ZfcRbac\Container\AuthorizationServiceFactory::class, | ||
\ZfcRbac\Service\RoleServiceInterface::class => \ZfcRbac\Container\RoleServiceFactory::class, | ||
\ZfcRbac\Rbac::class => \Zend\ServiceManager\Factory\InvokableFactory::class, | ||
], | ||
]; | ||
$this->assertEquals($expected, $provider->getDependencyConfig()); | ||
} | ||
|
||
public function testProvidesExpectedModuleConfiguration() | ||
{ | ||
$provider = new ConfigProvider(); | ||
$expected = [ | ||
'assertion_manager' => [], | ||
]; | ||
$this->assertEquals($expected, $provider->getModuleConfig()); | ||
} | ||
|
||
public function testInvocationProvidesDependencyConfiguration() | ||
{ | ||
$provider = new ConfigProvider(); | ||
$expected = [ | ||
'dependencies' => $provider->getDependencyConfig(), | ||
'zfc_rbac' => $provider->getModuleConfig(), | ||
]; | ||
$this->assertEquals($expected, $provider()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,28 +22,22 @@ | |
namespace ZfcRbacTest; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use ZfcRbac\ModuleConfig; | ||
use ZfcRbac\ConfigProvider; | ||
use ZfcRbac\Module; | ||
|
||
/** | ||
* @author Bas Kamer <[email protected]> | ||
* @covers \ZfcRbac\ModuleConfig | ||
* @covers \ZfcRbac\Module | ||
*/ | ||
class ModuleConfigTest extends TestCase | ||
class ModuleTest extends TestCase | ||
{ | ||
public function testCanBeInvoked(): void | ||
public function testProvidesExpectedConfiguration() | ||
{ | ||
$moduleConfig = new ModuleConfig(); | ||
|
||
static::assertTrue(is_callable($moduleConfig)); | ||
} | ||
|
||
public function testGetArrayWith(): void | ||
{ | ||
$moduleConfig = new ModuleConfig(); | ||
$config = $moduleConfig->__invoke(); | ||
|
||
$this->assertInternalType('array', $config); | ||
$this->assertArrayHasKey('zfc_rbac', $config); | ||
$this->assertArrayHasKey('dependencies', $config); | ||
$provider = new ConfigProvider(); | ||
$module = new Module(); | ||
$expected = [ | ||
'service_manager' => $provider->getDependencyConfig(), | ||
'zfc_rbac' => $provider->getModuleConfig(), | ||
]; | ||
$this->assertEquals($expected, $module->getConfig()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters