carono /
yii2-1c-exchange
| 1 | <?php |
||
| 2 | |||
| 3 | |||
| 4 | namespace carono\exchange1c\helpers; |
||
| 5 | |||
| 6 | |||
| 7 | class ModuleHelper |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @param string $class |
||
| 11 | * @param null $default |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 12 | * @return int|null|string |
||
| 13 | */ |
||
| 14 | public static function getModuleNameByClass($class = 'carono\exchange1c\ExchangeModule', $default = null) |
||
| 15 | { |
||
| 16 | foreach (\Yii::$app->modules as $name => $module) { |
||
| 17 | $result = ''; |
||
| 18 | if ((is_array($module))) { |
||
| 19 | $result = ltrim($module['class'], '\\'); |
||
| 20 | } elseif (is_object($module)) { |
||
| 21 | $result = get_class($module); |
||
| 22 | } |
||
| 23 | if ($result == ltrim($class, '\\')) { |
||
| 24 | return $name; |
||
| 25 | } |
||
| 26 | } |
||
| 27 | return $default; |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param $variable |
||
| 32 | * @param string $class |
||
| 33 | * @return string|null |
||
| 34 | */ |
||
| 35 | public static function getPhpDocInterfaceProperty($variable, $class = 'carono\exchange1c\ExchangeModule') |
||
| 36 | { |
||
| 37 | $reflection = new \ReflectionClass($class); |
||
| 38 | $property = $reflection->getProperty($variable); |
||
| 39 | if (preg_match('#@var\s+([\w\\\]+)#iu', $property->getDocComment(), $match)) { |
||
| 40 | return $match[1]; |
||
| 41 | } else { |
||
| 42 | return null; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | } |