Ответов: 6 Просмотров: 3296
|
Привет!
У меня вопрос, решение которого может помочь многим программистам, включая Вас.
Как реализовать возможность просмотра «карты» PHP кода?
Например:
Я хотел бы реализовать код, который может отображать карту сценария.
Например, я получаю код, который необходимо отладить, но я не знаю, его структуры и модели.
Вариант 1:
Я написал в специальную функцию в начале скрипта, запустите его и получить в указанном файле ("dump.txt") скрипт с кодами всех включаемых файлов.
Код index.php
CODE ( htmlphp):
скопировать код в буфер обмена
//index.php <?php function special_function(){ ....... } define("modules","/modules/"); function greeting(){ echo "Hello, user!"; } $a = "112"; include("main.php"); //main.php class main{ .... } include(modules."module1.php); include(modules."module2.php); include(modules."module3.php); // ... module3.php class modulethree{ .... } $modulethree->render(); include(modules."module4.php); include(modules."module5.php); include(modules."module6.php); include("components.php"); //components.php include(components."component1.php); include(components."component2.php); include(components."component3.php); include(components."component4.php); include("template.php"); ?>
Файл: dump.txt
CODE ( htmlphp):
скопировать код в буфер обмена
<?php define("modules","/modules/"); function greeting(){ echo "Hello, user!"; } $a = "112"; // ========================main.php===================== class main{ .... } // ========================modules/module1.php===================== // ========================modules/module2.php===================== // =============================module3.php========================== class modulethree{ .... } $modulethree->render(); // ========================modules/module4.php===================== // ========================modules/module5.php===================== // ========================modules/module6.php===================== //===========================components.php======================== // ========================components/component1.php===================== // ========================components/component2.php===================== // ========================components/component3.php===================== // ========================components/component4.php===================== // ========================template.php===================== <html> <head><?=$title?></head> <body><?=$body?></body> </html> ?>
Возможно, "special_function" должен быть вызван из другого сценария.
Вариант 2: Разработать расширение для PHP. На мой взгляд, лучшее решение этой проблемы.
В этом случае, где и как я могу поймать PHP код в виде строки после вставки всех инклюдов? |