Reflection Lookup Plugin

Source: Internet
Author: User

<?phpecho ' <pre> ';//define a class that tests reflections cqh{public $name = ' CQH ';    Private $country = ' China ';    Const GENDER = ' man ';    Public function say () {echo ' Hello,world ';    } Private Function Eat () {echo ' eat ';    } public static function drink () {echo ' Drink '; }}/*//Print all the Reflective interface Reflection::export (new Reflectionextension (' Reflection ')); *//*//reflection creates export results for all PHP classes, get_declared_classes can get all declared classes foreach (Get_declared_classes () as $class) {Reflecti    On::export (New Reflectionclass ($class)); } *//*//Only reflects the user-defined class foreach (Get_declared_classes () as $class) {$reflectionClass = new Reflectionclass ($CLA        SS);        if ($reflectionClass->isuserdefined ()) {reflection::export ($reflectionClass);        } *//******************************** uses the Reflection lookup plugin ********************************///to define an interface interface IPlugin {    public static function GetName (); }//Find all the class function that implements the IPlugin interfaceFindplugins () {$plugins = array ();            foreach (Get_declared_classes () as $class) {$reflectionClass = new Reflectionclass ($class);            if ($reflectionClass->implementsinterface (' IPlugin ')) {$plugins [] = $reflectionClass;    }} return $plugins;        }//Determines the member of the class used for the menu function Computemenu () {$menu = array ();            foreach (Findplugins () as $plugins) {$reflectionMethod = $plugins->getmethod (' Getmenuitems ');            if ($reflectionMethod->isstatic ()) {$items = $reflectionMethod->invoke (null); } else {//If this method is not static, we need an instance $pluginsInstance = $plugins->n                Ewinstance ();            $items = $reflectionMethod->invoke ($pluginsInstance);        } $menu = Array_merge ($menu, $items);    } return $menu; }//Determine the members of the class used for the sidebar of the article function compUtearticles () {$articles = array ();                foreach (Findplugins () as $plugin) {if ($plugin->hasmethod (' getarticles ')) {                $reflectionMethod = $plugin->getmethod (' getarticles ');                if ($reflectionMethod->isstatic ()) {$items = $reflectionMethod->invoke (null);                    } else {$pluginInstance = $plugin->newinstance ();                $items = $reflectionMethod->invoke ($pluginInstance);            } $articles = Array_merge ($articles, $items);    }} return $articles;        }//Determine the member of the class of the sidebar function computesidebars () {$sidebars = array ();                foreach (Findplugins () as $plugin) {if ($plugin->hasmethod (' Getsidebars ')) {                $reflectionMethod = $plugin->getmethod (' Getsidebars '); if ($reflectionMethod->isstAtic ()) {$items = $reflectionMethod->invoke (null);                    } else {$pluginInstance = $plugin->newinstance ();                $items = $reflectionMethod->invoke ($pluginInstance);            } $sidebars = Array_merge ($sidebars, $items);    }} return $sidebars;            }//Create a class that implements the IPlugin interface Mycoolplugin implements IPlugin {public static function GetName () {        Return ' Mycoolplugin ';                } public static function Getmenuitems () The numeric index array of the {///menu item} (Array (        ' Description ' = ' mycoolplugin ', ' link ' = '/mycoolplugin ');                } public static function Getarticles () {///The numeric index array of the article (Array ( ' Path ' = '. ', '/mycoolplugin ', ' title ' = ' This is a really COol article ', ' text ' = = ' This article is cool because ... ');    }} $menu = Computemenu ();    $sidebars = Computesidebars ();    $articles = Computearticles ();    Print_r ($menu);    Print_r ($sidebars);    Print_r ($articles); Echo ' </pre> ';? >

Reflection Lookup plug-in

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.