How to implement a PHP Framework series article "3" Support PSR4 auto-load class

Source: Internet
Author: User
Tags php framework

PSR4 Automatic Loading Specification https://github.com/PizzaLiu/PHP-FIG/blob/master/PSR-4-autoloader-cn.md

We put third parties in the vendor directory using the PSR Standard class library

Modify the AutoLoad function

12345678910111213141516171819202122     //psr    if(!empty($GLOBALS[‘_UCT‘][‘autoload_psr‘])) {        //namespace        if(false !== strpos($class_name‘\\‘)) {            $dir str_replace(‘\\‘, DS, ltrim($class_name‘\\‘)).‘.php‘;        }        else{            $dirstr_replace(‘_‘, DS, $class_name).‘.php‘;        }        foreach ($GLOBALS[‘_UCT‘][‘autoload_psr‘as$vendor) {            if(!strncmp($vendor.DS, $dirstrlen($vendor) + 1)) {                $f= UCT_PATH . ‘vendor‘. DS . $dir;            }            else{                $f= UCT_PATH . ‘vendor‘. DS . $vendor. DS . $dir;            }            if(file_exists($f)) {                returninclude$f;            }        }    }

Referencing third-party class libraries

123456789101112131415 functionuct_use_vendor($vendor) {    if(empty($GLOBALS[‘_UCT‘][‘autoload_psr‘])) {        $GLOBALS[‘_UCT‘][‘autoload_psr‘] = array(            $vendor        );        returntrue;    }    if(!in_array($vendor$GLOBALS[‘_UCT‘][‘autoload_psr‘])) {        //$GLOBALS[‘_UCT‘][‘autoload_psr‘][] = $app;            array_unshift($GLOBALS[‘_UCT‘][‘autoload_psr‘], $vendor);        returntrue;    }    returnfalse;}

How to implement a PHP Framework series article "3" Support PSR4 auto-load class

Related Article

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.