In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces what the loading mode of Composer is, which is very detailed and has certain reference value. Friends who are interested must finish reading it!
Automatic loading of Composer.
Let's take Yii2 as an example. When we generate a Yii2 program through Composer, we will create an autoload.php file under vendor, which is responsible for automatically loading various libraries in vendor (the yii2 core library is also in vendor, you know! ).
And you must know that Yii2's entry file index.php has a line.
Require (_ _ DIR__. '/.. / vendor/autoload.php')
Thus it can be seen that Yii2 is so friendly to Composer that it is no wonder that a single tree does not make a forest. Yii2 also needs countless Composer branches to become towering trees.
Let's officially explain Composer's autoload, telling you that we didn't use include / require after various extensions were installed, so how did Composer help us find them?
So far, Composer supports a total of four automatic loading methods
PSR-0PSR-4class-map contains file directly
These four ways are sufficient for Composer to cover all the PHP third-party extension libraries on the planet.
PSR is a set of PHP development standards, which is now supported by most mainstream frameworks, and the engineer company has opened a special topic to share practical information on PSR.
PSR-4
PSR-4 is recommended by Composer because it is easier to use and leads to a more concise directory structure. In an extended composer.json, it is configured as follows:
{"autoload": {"psr-4": {"Foo\\": "src/",}
Key and value define namespace and its corresponding directory mapping. According to PSR-4 rules, when you try to load the class "Foo\ Bar\ Baz" automatically, you will look for the file "srcBarBaz.php" and load it if it exists. Note that "Foo\" does not appear in the file path at this time.
The configuration such as composer.json will be converted by Composer into MAP form of namespace and file directory, and stored in the vendor/composer/autoload_psr4.php file, so if you install an extension that automatically loads in the form of PSR-4, you can find its real path in autoload_psr4.php.
PSR-0
This is an outdated standard, it was in the distant era of PHP5.2, you and I both know that PHP5.3 has advanced attributes like namespace, so PSR-0 is more about $baseDir. '/ src/BaseController.php'
If you don't understand, go and see autoload_classmap.php.
File mode
Isn't it enough to have the above loading methods? Yes, there will also be some global functions such as help, so well, let's just include these files directly.
{"autoload": {"files": ["src/MyLibrary/functions.php"]}}
When Composer installs the extension, it will put it into the
Vendor/composer/autoload_files.php above is all the content of this article "what is the Composer loading method?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.