【问题标题】:List all the namespaces and plugins (Octobercms)列出所有命名空间和插件(Octobercms)
【发布时间】:2018-01-27 01:28:14
【问题描述】:

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

【问题讨论】:

    标签: plugins models octobercms


    【解决方案1】:
    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>');
    
    }
    

    【讨论】:

      【解决方案2】:

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

      echo dump(get_declared_classes());
      

      dd(get_declared_classes());
      

      【讨论】:

        猜你喜欢
        • 2018-05-21
        • 2016-04-24
        • 1970-01-01
        • 2014-12-11
        • 2010-11-19
        • 2020-01-02
        • 1970-01-01
        • 2012-09-19
        • 1970-01-01
        相关资源
        最近更新 更多