Last active
May 14, 2018 11:08
-
-
Save ZiTAL/18a6444f47b35748989b522a1eed86ee to your computer and use it in GitHub Desktop.
php: Code Igniter, get code from controller's public methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
class Get_code extends CI_Controller | |
{ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
public function index() | |
{ | |
$dir = preg_replace("/\/paneles\/get_code.php$/", '', __FILE__); | |
$dir .= "/modulo/"; | |
$controllers = scandir($dir); | |
foreach($controllers as $c) | |
{ | |
if(preg_match("/\.php$/", $c)) | |
{ | |
$filename = "{$dir}{$c}"; | |
$cn = preg_replace("/\.php/", '', $c); | |
$cn = ucfirst($cn); | |
require_once($filename); | |
$class = new ReflectionClass($cn); | |
$methods = $class->getMethods(ReflectionMethod::IS_PUBLIC); | |
$tmp = array(); | |
foreach($methods as $method) | |
{ | |
$tmp[] = $method->name; | |
} | |
$methods = $tmp; | |
foreach($methods as $method) | |
{ | |
$func = new ReflectionMethod($cn, $method); | |
$f = $func->getFileName(); | |
$start_line = $func->getStartLine() - 1; | |
$end_line = $func->getEndLine(); | |
$length = $end_line - $start_line; | |
$source = file($f); | |
$source = implode('', array_slice($source, 0, count($source))); | |
$source = preg_split("/(\n|\r\n|\r)/", $source); | |
$body = ''; | |
for($i=$start_line; $i<$end_line; $i++) | |
$body.="{$source[$i]}\n"; | |
if(preg_match("/\/modulos\//", $body)) | |
{ | |
echo "filename: {$filename}\n"; | |
echo "class: {$cn}\n"; | |
echo "method: {$method}\n"; | |
/* | |
echo "Start: {$start_line}\n"; | |
echo "End: {$end_line}\n"; | |
*/ | |
echo "code: \n"; | |
echo $body; | |
echo "\n--------------------------------------------------------------------------------------------------------\n"; | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment