Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to load composer automatically

Shulou Source: shulou.com Published: 2022-06-02 15:04:52 09月26日 Update

Editor to share with you how to automatically load composer, 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 understand it!

Four ways of automatic loading of composer

Composer is a package dependency management tool for PHP, similar to node.js 's npm. It's not official, but it's already very popular.

Composer provides four kinds of support for the automatic loading of third-party packages. They are psr-0,psr-4, generate class-map, and directly contain files

Psr-0 automatic loading

Psr-1 basic Code Specification

Psr-2 code style specification

Psr-3 log interface

Psr-4 automatic loading

The main difference between psr-0 and psr-4 is that there is no processing for underscores in psr-4. The underscore in psr-0 is escaped as a directory separator

Write in the main file index.php

Require 'vendor/autoload.php'

1.PSR-4

This is how it is configured in composer.json

{"aotuload": {"psr-4": {"FOO\": "src/"}

When you new FOO the class\ A\ An in index.php. Composer will look for src/A/A.php. If this file exists, load it

2.PSR-0

This is how it is configured in composer.json

{"aotuload": {"psr-0": {"FOO\": "src/"}

When you new FOO the class\ A\ An in index.php. Composer will look for src/FOO/A/A.php. If this file exists, load it

3.class-map

{"aotuload": {"class-map": ['a class-map']}}

Composer scans the abc directory for class that ends with .php or .inc. And produce a new file mapping relationship, which is put into / vendor/composer/aotuload_classmap

4.files

{"aotuload": {"files": ["src/my/function.php"]}}

Manually specify the file to provide loading. Such as the global function file

The above is all the contents of the article "how to load composer automatically". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Files articles code content directories configurations not much global delimiters most tools manual interfaces methods logs more styles knowledge third parties management tools Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker macOS Shulou Information Microsoft NVidia