In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to achieve plus-component in Laravel. I hope you will get something after reading this article. Let's discuss it together.
What is plus-component?
Like the name, plus stands for ThinkSNS+ program, and the component after it is "package" or "application" as we understand it. The term "application" here refers to the implementation of API or web functions. So this type came into being.
But plus-component is not just an application, it can also be a simple function extension. For example, medz/plus-storage-quniu is the extended Qiniuyun storage.
Establishment of composer plug-in
Since routing is involved, the initial idea is to generate a file in the / routes directory and copy the packet routing file here. Later, the problem was found to be insufficient.
Finally, it comes to mind that the implementation of plus-component is not necessarily based on routing applications, but also may be a simple extension. Let's take a look at the interface class of the intermediate plug-in:
Among them, router becomes a non-essential item.
Instead, you have three hook methods, install, update, and uninstall, which correspond to install, upgrade, and uninstall.
In the design, the plus-component intermediate plug-in adds the following configuration to the / config/component.php of Laravel:
Composer.json configuration of intermediate plug-ins
It's actually very simple. You can see the code added to / config/component.php above. Where did the installer entry come from? Take a look at the package configuration:
This is the final extra.installer-class configuration, and here is the full class name, so that the additional configuration is read when the composer plug-in executes and is written to the Laravel configuration file.
Install/update/uninstall
There is a command php artisan component [install | update | unstall] vendor/name in ThinkSNS+, which is mainly used to install, upgrade and uninstall packages.
The actual operation is as follows:
The package is installed in this way, and this command reads the configuration of / config/component.php to get installer, so that after running different parameters, call the required hook such as install,uodate,uninstall to achieve the purpose.
Router
As you can see from the top interface class, there is a router method that has two void | string return types, so void represents no route, and string represents the absolute address of the packet routing file.
When the php artisan component command is executed, the corresponding configuration in / config/component_routes.php is added.
In / app/Providers/RouteServiceProvider.php, it is as follows:
Maybe you misunderstand, why only include came in? Yes, the code here actually refers to Route::group, and the files in the package can be routed normally using Route::*.
Resource
Since it can be based on routing, there is bound to be the problem of static resources, which is also specified in the interface class:
This returns the directory stored in the static resource in the package, and when you execute the installation or upgrade command, copy it to the / public/vendor/name directory to achieve the static resource release function.
After reading this article, I believe you have some understanding of "how to achieve plus-component in Laravel". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
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: 241
*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.