R
R
Ruslan Ruslanov2019-08-05 22:49:58
PHP
Ruslan Ruslanov, 2019-08-05 22:49:58

How does autoload work in composer?

I'm writing my own autoloader.
I want to understand how the autoloader works in composer.
So far I've done this:
1. glob(*.php)
2. foreach {require file}
And how does it work in composer?
What's under the hood? How are files connected? Where to see the code?
Does it just look at the json file and pull all the values ​​of the autoload fields, and then connect all the files using them?
Or does he somehow understand which files need to be connected?
Explain, leave links. Couldn't find anything specific.
(Although maybe I just searched badly...)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aleksandr Obukhov, 2019-08-05
@dasauser

Composer works according to several standards - PSR-0 and PSR-4 which work according to the naming convention of the classes and the location of the files in which they are declared - that is, it implements "Lazy" class loading - the class is loaded only when it is first used ( https://secure .php.net/manual/en/language.oop5.aut...
See also:
- https://www.php-fig.org/psr/psr-0/
- https://www.php-fig. org/psr/psr-4/
Also, for compatibility, there is a classmap method when the "class" => "file" map is explicitly set:
- https://getcomposer.org/doc/04-schema.md#autoload

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question