list controller

mail@pastecode.io avatar
unknown
php
3 years ago
2.7 kB
3
Indexable
Never
<? 
function listcontrollers(){

        $controllers    = array();

        



        $dir            = APPPATH.'/controllers';

        $files          = scandir($dir);



        $controller_files = array_filter($files, function($filename) {

            return (substr(strrchr($filename, '.'), 1)=='php') ? true : false;

        });





        

          

        foreach ($controller_files as $filename)

        {

            
            require_once(APPPATH.'/controllers/'.$filename);



            $classname = ucfirst(substr($filename, 0, strrpos($filename, '.')));

            //$controller = new $classname();

           // $methods = get_class_methods($controller);

            

            $controller = new ReflectionClass($classname);

            

            $methods = $controller->getMethods(ReflectionMethod::IS_PUBLIC);

            

            $methodspe =array();

            foreach ($methods as $method)

            {

                if ($method->class == $classname && $method->name != '__construct') {

             

            $method_info = $method->name;

            array_push($methodspe,$method_info);

                

                      }

                

            }

        

            $controller_info = (object) array(

                'controller_filename' => $filename,

                'controller_name' => $classname,

                'controller_slug' => seo($classname),

                'controller_methods'  => json_encode($methodspe),

                 

            );

            array_push($controllers,$controller_info);

        }



        

         return  $controllers;

 

        

        

    }

public function controller_update()
    {
        $this->db->trans_start();
        $controllers = listcontrollers();
        $controllerdbs = $this->core_m->get();



        foreach ($controllers as $controller) {
            if (count($this->core_m->get_by(array('controller_filename' =>$controller->controller_filename))) == 0) {
                $this->core_m->save((array)$controller);
            }

            $this->db->where('controller_slug', $controller->controller_slug)->update('controllers', array('controller_methods'=>$controller->controller_methods));
        }

        foreach ($controllerdbs as $controllerdb) {
            $filename  = APPPATH . '/controllers/'.$controllerdb->controller_filename;
            if (!file_exists($filename)) {
                $this->core_m->delete($controllerdb->controller_id);
            }
        }
        $this->db->trans_complete();


        if ($this->db->trans_status()) {
            return true;
        } else {
            return false;
        }
    }

?>