Skip to content

Commit 734bfd5

Browse files
committed
Merge branch 'hotfix/19-config-provider' into release-1.0.0
Close #19
2 parents de78a91 + 492caff commit 734bfd5

File tree

4 files changed

+96
-39
lines changed

4 files changed

+96
-39
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ All notable changes to this project will be documented in this file, in reverse
2929

3030
### Removed
3131

32-
- Nothing.
32+
- [#19](https://github.com/zendframework/zend-expressive-authorization/pull/19)
33+
removes the file `config/authorization.php` and merges its contents into the
34+
`Zend\Expressive\Authorization\ConfigProvider` class.
3335

3436
### Fixed
3537

config/authorization.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/ConfigProvider.php

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,46 @@ public function __invoke() : array
1818
{
1919
return [
2020
'dependencies' => $this->getDependencies(),
21-
'authorization' => include __DIR__ . '/../config/authorization.php'
21+
'authorization' => $this->getAuthorizationConfig(),
22+
];
23+
}
24+
25+
/**
26+
* Returns the configuration for the AuthorizationInterface adapter
27+
*/
28+
public function getAuthorizationConfig() : array
29+
{
30+
return [
31+
/**
32+
* Example using ZendAcl:
33+
*
34+
* 'roles' => [
35+
* // insert the role with parent (if any)
36+
* // e.g. 'editor' => ['admin'] (admin is parent of editor)
37+
* ],
38+
* 'resources' => [
39+
* // an array of resources, as string
40+
* ],
41+
* 'allow' => [
42+
* // for each role allow some resources
43+
* // e.g. 'admin' => ['admin.pages']
44+
* ],
45+
* 'deny' => [
46+
* // for each role deny some resources
47+
* // e.g. 'admin' => ['admin.pages']
48+
* ],
49+
*
50+
* Example using ZendRbac:
51+
*
52+
* 'roles' => [
53+
* // insert the role with parent (if any)
54+
* // e.g. 'editor' => ['admin'] (admin is parent of editor)
55+
* ],
56+
* 'permissions' => [
57+
* // for each role insert one or more permissions
58+
* // e.g. 'admin' => ['admin.pages']
59+
* ],
60+
*/
2261
];
2362
}
2463

@@ -28,8 +67,13 @@ public function __invoke() : array
2867
public function getDependencies() : array
2968
{
3069
return [
70+
'aliases' => [
71+
// Provide an alias for the AuthorizationInterface based on the adapter you are using.
72+
// AuthorizationInterface::class => ZendAcl::class,
73+
// AuthorizationInterface::class => ZendRbac::class,
74+
],
3175
'factories' => [
32-
AuthorizationMiddleware::class => AuthorizationMiddlewareFactory::class
76+
AuthorizationMiddleware::class => AuthorizationMiddlewareFactory::class,
3377
],
3478
];
3579
}

test/ConfigProviderTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-expressive-authorization for the canonical source repository
4+
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-expressive-authorization/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace ZendTest\Expressive\Authorization;
11+
12+
use PHPUnit\Framework\TestCase;
13+
use Zend\Expressive\Authorization\AuthorizationMiddleware;
14+
use Zend\Expressive\Authorization\ConfigProvider;
15+
16+
class ConfigProviderTest extends TestCase
17+
{
18+
/** @var ConfigProvider */
19+
private $provider;
20+
21+
protected function setUp()
22+
{
23+
$this->provider = new ConfigProvider();
24+
}
25+
26+
public function testProviderDefinesExpectedFactoryServices()
27+
{
28+
$config = $this->provider->getDependencies();
29+
$factories = $config['factories'];
30+
31+
$this->assertArrayHasKey(AuthorizationMiddleware::class, $factories);
32+
}
33+
34+
public function testInvocationReturnsArrayWithDependencies()
35+
{
36+
$config = ($this->provider)();
37+
38+
$this->assertInternalType('array', $config);
39+
$this->assertArrayHasKey('authorization', $config);
40+
$this->assertInternalType('array', $config['authorization']);
41+
42+
$this->assertArrayHasKey('dependencies', $config);
43+
$this->assertInternalType('array', $config['dependencies']);
44+
$this->assertArrayHasKey('aliases', $config['dependencies']);
45+
$this->assertArrayHasKey('factories', $config['dependencies']);
46+
}
47+
}

0 commit comments

Comments
 (0)