列出所有命名空间和插件(Octobercms)

时间:2017-08-18 11:14:41

标签: plugins models octobercms

我是octobercms的新手,我想在项目中列出所有现有的命名空间和插件以及模型,我该怎么办?

2 个答案:

答案 0 :(得分:3)

public function test_stat()
{
    if(is_dir(('./plugins/'))){
        $pluginPath = './plugins/' ;
        $namespaces_list = [];
        $namespaces = scandir($pluginPath);
        foreach ($namespaces as $namespace){

            if(!in_array($namespace, ['.', '..'])){
                $plugins = scandir($pluginPath . $namespace);
                if(count($plugins)>2){

                    $plugins = array_values($plugins);
                    $plugins_list = [];
                    foreach ($plugins as $plugin){
                        if(!in_array($plugin, ['.', '..'])){
                            if(is_dir($pluginPath . $namespace . '/' . $plugin . '/models')){
                                $modelsPath = $pluginPath . $namespace . '/' . $plugin . '/models';
                                $models = scandir($modelsPath);
                                $models_list = [];
                                foreach ($models as $model){
                                    if(is_dir($modelsPath . '/' . $model) && !in_array($model, ['.', '..'])){
                                        if(file_exists($modelsPath . '/' . $model . '/columns.yaml')){
                                            $models_list[] = $model;
                                        }
                                    }
                                }
                                if(count($models_list) > 0){
                                    $pluginNamespace = $namespace . '_' . $plugin;
                                    $tables = DB::select("SHOW TABLES LIKE '" . $pluginNamespace . "%'");
                                    $plugins_list[] = [
                                        "name"      => $plugin,
                                        "models"    => $models_list,
                                        "tables"    => $tables
                                    ];
                                }
                            }
                        }
                    }

                    $namespace_obj = NULL;
                    if(count($plugins_list) > 0){
                        $namespace_obj = [
                            "name"      => $namespace,
                            "plugins"   => $plugins_list
                        ];
                    }
                    if($namespace_obj !== NULL){
                        $namespaces_list[] = $namespace_obj;
                    }
                }
            }
        }
        dump( $namespaces_list );


    }else{
        echo "";
        return false;
    }
    die('<br>test<br>');

}

答案 1 :(得分:2)

https://secure.php.net/manual/en/function.get-declared-classes.php

echo dump(get_declared_classes());

dd(get_declared_classes());