Получить все модули, контроллеры и действия из приложения Zend Framework

13
задан Linger 4 September 2012 в 19:09
поделиться

3 ответа

Я создал функцию, которая может получать все действия, контроллеры и модули из приложения zend. Вот он:

$module_dir = substr(str_replace("\\","/",$this->getFrontController()->getModuleDirectory()),0,strrpos(str_replace("\\","/",$this->getFrontController()->getModuleDirectory()),'/'));
    $temp = array_diff( scandir( $module_dir), Array( ".", "..", ".svn"));
    $modules = array();
    $controller_directorys = array();
    foreach ($temp as $module) {
        if (is_dir($module_dir . "/" . $module)) {
            array_push($modules,$module);
            array_push($controller_directorys, str_replace("\\","/",$this->getFrontController()->getControllerDirectory($module)));
        }
    }

    foreach ($controller_directorys as $dir) {
        foreach (scandir($dir) as $dirstructure) {
            if (is_file($dir  . "/" . $dirstructure)) {
                if (strstr($dirstructure,"Controller.php") != false) {
                    include_once($dir . "/" . $dirstructure);
                }
            }

        }
    }

    $default_module = $this->getFrontController()->getDefaultModule();

    $db_structure = array();

    foreach(get_declared_classes() as $c){
        if(is_subclass_of($c, 'Zend_Controller_Action')){
            $functions = array();
            foreach (get_class_methods($c) as $f) {
                if (strstr($f,"Action") != false) {
                    array_push($functions,substr($f,0,strpos($f,"Action")));
                }
            }
            $c = strtolower(substr($c,0,strpos($c,"Controller")));

            if (strstr($c,"_") != false) {
                $db_structure[substr($c,0,strpos($c,"_"))][substr($c,strpos($c,"_") + 1)] = $functions;
            }else{
                $db_structure[$default_module][$c] = $functions;
            }
        }
    }       
}
7
ответ дан 1 December 2019 в 19:50
поделиться

Я не думаю, что в Zend есть решение этой проблемы. Вам придется сделать это самостоятельно ...

Один из способов сделать это - перечислить все классы и проверить, расширяют ли эти классы (например) класс Zend_Controller_Action ...

проверить функции php get_declared_classes и is_subclass_of

foreach(get_declared_classes() as $c){
  if(is_subclass_of($c, 'Zend_Controller_Action')){
     ...
  }
}
0
ответ дан 1 December 2019 в 19:50
поделиться

Это может быть старый вопрос, но вот как я это делаю ...

//        $front = Zend_Controller_Front::getInstance(); // use this line instead on a model class
    $front = $this->getFrontController(); // this in controller
    $acl   = array();

    foreach ($front->getControllerDirectory() as $module => $path) {
        foreach (scandir($path) as $file) {

            if (strstr($file, "Controller.php") !== false) {

                include_once $path . DIRECTORY_SEPARATOR . $file;
                $class = substr($file,0,strpos($file,".php"));

                if (is_subclass_of($class, 'Zend_Controller_Action')) {

                    $controller = strtolower(substr($file, 0, strpos($file, "Controller")));
                    $methods = array();

                    foreach (get_class_methods($class) as $method) {
                        if (strstr($method,"Action") != false) {
                            array_push($methods,substr($method,0,strpos($method,"Action")));
                        }
                    }
                }

                $acl[$module][$controller] = $methods;
            }
        }
    }
25
ответ дан 1 December 2019 в 19:50
поделиться
Другие вопросы по тегам:

Похожие вопросы: