1
|
|
|
<?php namespace Anomaly\UsersModule\Role\Permission; |
2
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Addon\Addon; |
4
|
|
|
use Anomaly\Streams\Platform\Addon\AddonCollection; |
5
|
|
|
use Illuminate\Config\Repository; |
6
|
|
|
use Illuminate\Translation\Translator; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class PermissionFormSections |
10
|
|
|
* |
11
|
|
|
* @link http://anomaly.is/streams-platform |
12
|
|
|
* @author AnomalyLabs, Inc. <[email protected]> |
13
|
|
|
* @author Ryan Thompson <[email protected]> |
14
|
|
|
* @package Anomaly\UsersModule\Role\Permission |
15
|
|
|
*/ |
16
|
|
View Code Duplication |
class PermissionFormSections |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Handle the fields. |
21
|
|
|
* |
22
|
|
|
* @param PermissionFormBuilder $builder |
23
|
|
|
* @param AddonCollection $addons |
24
|
|
|
* @param Translator $translator |
|
|
|
|
25
|
|
|
* @param Repository $config |
26
|
|
|
*/ |
27
|
|
|
public function handle(PermissionFormBuilder $builder, AddonCollection $addons, Repository $config) |
28
|
|
|
{ |
29
|
|
|
$sections = []; |
30
|
|
|
|
31
|
|
|
$sections['streams']['title'] = 'streams::message.system'; |
32
|
|
|
|
33
|
|
|
foreach ($config->get('streams::permissions', []) as $group => $permissions) { |
34
|
|
|
$sections['streams']['fields'][] = 'streams::' . $group; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/* @var Addon $addon */ |
38
|
|
|
foreach ($addons->withConfig('permissions') as $addon) { |
39
|
|
|
|
40
|
|
|
$sections[$addon->getNamespace()]['title'] = $addon->getName(); |
41
|
|
|
$sections[$addon->getNamespace()]['description'] = $addon->getDescription(); |
42
|
|
|
|
43
|
|
|
foreach ($config->get($addon->getNamespace('permissions'), []) as $group => $permissions) { |
44
|
|
|
|
45
|
|
|
$sections[$addon->getNamespace()]['fields'][] = $addon->getNamespace($group); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$builder->setSections($sections); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.