In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you the example analysis of Composer autoload, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
It is well known that composer is the cornerstone of modern PHP projects. Different from the ancient pear, composer is not a package management system focused on system-level php management, but a project-based library management system. This is like the difference between npm install-g and npm install. And the most important thing is that pear can not keep up with the trend of the times. Pear still has its own way when everyone is using psr-*.
Well, maybe that's a good thing, but it's also a bad thing. The good news is that many good packages have become rich from pear families, such as PHP_CodeSniffer, PHP_Unit and so on. However, with the development of the times, the php community has gradually drawn some essence from other communities and slowly moved forward. The most recent laravel is thrown directly into the composer. Because the psr-4 specification really can't be any better. This is really a set of naming conventions that I use most easily with all kinds of bags.
Go too far, pull back to the core composer file vendor/composer/autoload_real.php.
Types that are loaded automatically
In general, composer provides several types of automatic loading
Classmap
Psr-0
Psr-4
Files
In theory, the project code is loaded automatically with psr-4, helper is loaded automatically with files, and development is loaded automatically with classmap. Psr-0 has been abandoned, but some historical relics are still in use, so I see it occasionally.
Classmap
This should be the simplest autoload mode. It probably means something like this:
{"classmap": ["src/"]}
Then composer reads all the files in this folder behind it, and then angrily generates all the namespace + classname of class into a php array of key = > value in vendor/composer/autoload_classmap.php.
Then you can use the spl_autoload_register function openly to do autoload.
Well, the above example is actually a little bit tricky, that is, the above autoload is actually generated based on prs-4. But it doesn't matter. If you understand the important points at the bottom, we can see that all the so-called autoloading can actually be understood as generating such a classmap, which is what composer dump-autoload-o does. Otherwise, compoesr will read the contents of psr-4 and prs-0 dynamically.
Psr-0
Now this standard is out of date. This standard was developed mainly when php jumped from 5.2 to 5.3 + with the concept of namespaces. So at this time, the standard of psr-0 mainly takes into account
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.