Facade wrapper class--solve the long namespace call problem in the view spring namespace QQ space naming global naming null

Source: Internet
Author: User
Tags dsn
Sometimes the template definition needs to write a long full path class name, here is a simple alias calling code to circumvent this problem, the disadvantage is that the IDE code hints function is not
 *//Initialize * Zgfacade::setzgfacade (' form ', ' aert_form '); * Zgfacade::setzgfacade (' esclient ', ' \elasticsearch\client '); * *//Use demo * $form = zgfacade::newinstance (' form ', ' frm2 ', ' delete '); * Dump ($form); * * echo zgfacade::server (' form ', ' request_method '); * Echo zgfacade::get (' form ', ' a '); * * $dsn = config::get (' Esken.dsn '); * $esClient = zgfacade::newinstance (' esclient ', $DSN); * Dump ($esClient); * * @author vb2005xu@qq.com */final class zgfacade{private static $map = [' form ' = ' aert_form '];p ublic static function s Etzgfacade ($alias, $class) {self:: $map [$alias] = $class;} private static function __facade__ ($facade, $method, $arguments =[]) {if (Is_object ($facade)) {//Call object method return Call_user_ Func_array ([$facade, $method], $arguments);} else if (is_string ($facade)) {if (Empty (self:: $map [$facade])) {throw new Exception ("Undefined ' facade ': {$facade}");}    Call the static method if (' newinstance ' = = $method) {$class = new Reflectionclass (self:: $map [$facade]);    Return $class->newinstanceargs ($arguments); } $class = self:: $map [$facade];return Call_user_func_array ([$class, $method], $arguments);} throw new Exception ("Invalid ' facade ' call!");}    Public Function __call ($method, $arguments) {$facade = Array_shift ($arguments);    Return self::__facade__ ($facade, $method, $arguments); The public static function __callstatic ($method, $arguments) {$facade = Array_shift ($arguments);    Return self::__facade__ ($facade, $method, $arguments); }}

The above describes the facade wrapper class-to solve the long namespace call problem in the view, including the namespace, Acad aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • 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.