Last active
September 21, 2015 02:05
-
-
Save quangpd/6349bc4e68518ea0183a to your computer and use it in GitHub Desktop.
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 | |
/* | |
* Danh sach tat ca controller va method trong HMVC CodeIgniter | |
* modules/* | |
* application/controllers/* | |
*/ | |
function structure() | |
{ | |
$hmvc = array(); | |
foreach(glob(APPPATH . 'controllers/*') as $controller) | |
{ | |
$m = ''; | |
if(is_dir($controller)) | |
{ | |
$dirname = basename($controller, EXT); | |
foreach(glob(APPPATH . 'controllers/'.$dirname.'/*') as $subdircontroller) | |
{ | |
$subdircontrollername = basename($subdircontroller, EXT); | |
if(!class_exists($subdircontrollername)) | |
{ | |
ci()->load->file($subdircontroller); | |
} | |
$methods = get_class_methods($subdircontrollername); | |
$_methods = array(); | |
foreach($methods as $method) | |
{ | |
if(substr($method, 0, 1) != '_' && $method != 'get_instance' && $method != $subdircontrollername) | |
{ | |
$_methods[] = $method; | |
} | |
} | |
$hmvc[$m][$controllername] = $_methods; | |
} | |
} | |
else if(pathinfo($controller, PATHINFO_EXTENSION) == "php") | |
{ | |
$controllername = basename($controller, EXT); | |
if(!class_exists($controllername)) | |
{ | |
ci()->load->file($controller); | |
} | |
$methods = get_class_methods($controllername); | |
$_methods = array(); | |
if(is_array($methods)) | |
{ | |
foreach($methods as $method) | |
{ | |
if(substr($method, 0, 1) != '_' && $method != 'get_instance' && $method != $controllername) | |
{ | |
$_methods[] = $method; | |
} | |
} | |
} | |
$hmvc[$m][$controllername] = $_methods; | |
} | |
} | |
foreach(glob('modules/*') as $module) | |
{ | |
$m = str_replace('modules/', '', $module); | |
$hmvc[$m] = array(); | |
foreach(glob("{$module}/controllers/*") as $controller) | |
{ | |
if(pathinfo($controller, PATHINFO_EXTENSION) == "php") | |
{ | |
$controllername = basename($controller, EXT); | |
$controller_context = file_get_contents($controller); | |
preg_match_all('/function (.*?)\(/i', $controller_context, $matches); | |
$methods = ($matches && isset($matches[1])) ? $matches[1] : null; | |
$_methods = array(); | |
if(is_array($methods)) | |
{ | |
foreach($methods as $method) | |
{ | |
if(substr($method, 0, 1) != '_' && $method != 'get_instance' && $method != $controllername) | |
{ | |
$_methods[] = trim($method); | |
} | |
} | |
} | |
$hmvc[$m][$controllername] = $_methods; | |
} | |
} | |
} | |
return $hmvc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment