Answer the question
In order to leave comments, you need to log in
PHP. How to parse a PHP file?
Good afternoon.
There is a php file with approximate content:
/**
* перед добавлением инфоблока
*
* даем права на инфоблоки на чтение по умолчанию
*/
AddEventHandler("iblock", "OnBeforeIBlockAdd", "iblock_OnBeforeIBlockAdd_FixIBlockPermissions");
function iblock_OnBeforeIBlockAdd_FixIBlockPermissions(&$arFields) {
Bitrix\Main\Diag\Debug::writeToFile("iblock_OnBeforeIBlockAdd_FixIBlockPermissions", "", "iblock_OnBeforeIBlockAdd_FixIBlockPermissions.txt");
$rsGroups = CGroup::GetList(($by = "c_sort"), ($order = "desc"), $filter);
while ($arGroup = $rsGroups->Fetch()) {
if ($arGroup['ANONYMOUS'] == 'Y') {
$group_id = $arGroup['ID'];
break;
}
}
$arFields['GROUP_ID'][$group_id] = "R";
}
/**
* перед добавлением инфоблока
*
* даем права на инфоблоки на чтение по умолчанию
*/
Answer the question
In order to leave comments, you need to log in
There is a built-in function token_get_all() that allows you to parse a PHP file into tokens:
php.net/manual/en/function.token-get-all.php
Example: https://3v4l.org/em0It
Token codes: php.net/ manual/en/tokens.php
From one of the core PHP developers: https://github.com/nikic/php-parser
The two options above are fine. Well, or write your own EBNF grammar using:
1) Hoa LL(1)/LL(k): https://github.com/hoaproject/Compiler (The example above nikic from Mikhail Osher uses a LALR parser based on Yacc )
2) Or my fork: https://github.com/railt/compiler (grammar features are almost the same , but a few bugs have been fixed, sources have been rewritten and lexical analysis has been accelerated by 140 times ).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question