Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Composer

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the example analysis of Composer, which is very detailed and has certain reference value. Friends who are interested must finish it!

Composer parses composer configuration items

For details of each configuration item, please refer to the Composer official website.

Configuration list ID configuration item describes the name of the 1name package, which includes the vendor name and project name, separated by /. 2description package describes 3version version 4type installation type 5keywords keyword 6homepage project home page 7time release time 8license license agreement 9authors author 10support support to get relevant information objects supported by the project. 11require automatically loaded package 12require-dev automatically loaded under DEV 13conflict the package in this list conflicts with this version of the current package. They will not be allowed to be installed at the same time as packages recommended by 14suggest, and they are enhanced or able to work well with the current package. This is just information and shows that after the dependency package installation is complete, give your users a suggestion that they can add more packages. 15autoload automatic loading, there are four loading mechanisms psr-4 psr-0 classmap file16include-path to retain the tradition, it is not recommended to use 17target-dir to define the target folder of the current package installation 18minimum-stability package installation through stability filter package default behavior, dev alpha beta RC stable optional 19prefer-stable package installation package preferred to use a more stable version, "prefer-stable": true20repositories uses a custom package repository. By default, composer only uses packagist as the repository for packages. By specifying the repository, you can get the resource bundle from somewhere else. 21config configuration parameters, eg:process-timeout vendor-dir22scriptsComposer allows you to attach scripts at all stages of the installation process. 23extra arbitrary additional data for use by scripts. 24bin this attribute is used to annotate a set of files that should be treated as binary scripts, which are softly linked to the directory marked by the bin-dir attribute (in the config object) for other dependent packages to call. 25archive these options are used when creating package archives. Development configuration details 11. Require identifier means the latest version of the instance ^ installation "barryvdh/laravel-cors": "^ 0.10.0" install the latest version of laravel-cors ~ identify the last interval version of the installation "barryvdh/laravel-cors": "~ 0.10.0", install laravel-cors 0.10.0-0.10.912. Require-dev

Composer install installs packages in require-dev, packages in require

Composer install-- no-dev only installs packages in require

twenty-two。 Scripts "scripts": {"post-root-package-install": ["@ php-r\" file_exists ('.env') | | copy ('.env.example', '.env') \ ""], "post-create-project-cmd": ["@ php artisan key:generate"], "post-autoload-dump": ["Illuminate\\ Foundation\\ ComposerScripts::postAutoloadDump", "@ php artisan package:discover"]}

Scripts is a custom execution SHELL command, as in the above code, execute post-root-package-install to copy files.

15 autoload

PHP automatically loads files, and there are four loading mechanisms, psr-4 psr-0 classmap file

After modifying the contents of autoload, remember to execute composer dump-autoload to regenerate the load file

Prs-4

The PHP files in this directory adopt the PSR-4 automatic loading standard.

Composer will write the file mapping relationship under this structure to autoload_classmap.php

"autoload": {"psr-4": {"App\": "app/"}} prs-0

The PHP files in this directory adopt the PSR-0 automatic loading standard.

Composer will write the file mapping relationship under this structure to autoload_namespaces.php

"autoload": {"psr-4": {"Cx\": "prs0/"}} classmap

Composer loads all the files in the lib/ directory and puts them into autoload_classmap.php

{"classmap": ["lib/"]} file

Composer loads the src/test.php file and puts it into autoload_files.php

{"files": ["src/test.php"]} commands

For detailed naming, please refer to the Composer command line.

Composer install

Install the version in packages in the composer.lock file first, even if the version in composer.json is not consistent with that in composer.lock

Installation flow chart

Composer update

Install the version of composer.json first, and update the version in packages in composer.lock

Installation flow chart

Composer dump-autoloadCMD indicates that the application scene composer dump-autoload print automatically loads the index, that is, loading the items in autoload into the directory that should have been specified. Development environment you updated the autoload, composer dump-autoload-o convert PSR-0/4 autoloading to classmap for faster loading speed for production environment composer dump-autoload-o-no-dev disable autoload-dev rules apply to production environment composer dump-autoload-classmap-authoritative only load files in ClassMap, must go to the disk file system for any check applicable to production environment

So please use composer dump-autoload-o-no-dev-classmap-authoritative for production.

The above is all the content of this article "sample Analysis of Composer". 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report