Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
rulecontrollerfactory.php
1
<?php
2
3
namespace
Bitrix\Main\Access\Rule\Factory
;
4
5
use
Bitrix\Main\Access\AccessibleController
;
6
use
Bitrix\Main\Access\Rule\RuleFactory
;
7
use
Bitrix\Main\Access\Rule\RuleInterface
;
8
use ReflectionClass;
9
10
class
RuleControllerFactory
implements
RuleFactory
11
{
12
protected
const
SUFFIX
=
'Rule'
;
13
14
public
function
createFromAction
(
string
$action,
AccessibleController
$controller): ?
RuleInterface
15
{
16
$className = $this->
getClassName
($action, $controller);
17
if
(!$className || !class_exists($className ))
18
{
19
return
null
;
20
}
21
22
$ref =
new
ReflectionClass($className);
23
if
($ref->implementsInterface(RuleInterface::class))
24
{
25
return
$ref->newInstance($controller);
26
}
27
28
return
null
;
29
}
30
31
protected
function
getClassName
(
string
$action,
AccessibleController
$controller): ?string
32
{
33
$action = explode(
'_'
, $action);
34
$action = array_map(fn($el) => ucfirst(mb_strtolower($el)), $action);
35
36
return
$this->
getNamespace
($controller) . implode($action) . static::SUFFIX;
37
}
38
39
protected
function
getNamespace
(
AccessibleController
$controller): string
40
{
41
$class =
new
ReflectionClass($controller);
42
$namespace = $class->getNamespaceName();
43
44
return
$namespace.
'\\'
.static::SUFFIX.
'\\'
;
45
}
46
}
Bitrix\Main\Access\Rule\Factory\RuleControllerFactory
Definition
rulecontrollerfactory.php:11
Bitrix\Main\Access\Rule\Factory\RuleControllerFactory\SUFFIX
const SUFFIX
Definition
rulecontrollerfactory.php:12
Bitrix\Main\Access\Rule\Factory\RuleControllerFactory\createFromAction
createFromAction(string $action, AccessibleController $controller)
Definition
rulecontrollerfactory.php:14
Bitrix\Main\Access\Rule\Factory\RuleControllerFactory\getNamespace
getNamespace(AccessibleController $controller)
Definition
rulecontrollerfactory.php:39
Bitrix\Main\Access\Rule\Factory\RuleControllerFactory\getClassName
getClassName(string $action, AccessibleController $controller)
Definition
rulecontrollerfactory.php:31
Bitrix\Main\Access\AccessibleController
Definition
accessiblecontroller.php:15
Bitrix\Main\Access\Rule\RuleFactory
Definition
rulefactory.php:8
Bitrix\Main\Access\Rule\RuleInterface
Definition
ruleinterface.php:15
Bitrix\Main\Access\Rule\Factory
Definition
rulecontrollerfactory.php:3
modules
main
lib
access
rule
factory
rulecontrollerfactory.php
Создано системой
1.10.0