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

Sample Analysis of all attribute Fields in composer.json

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article will explain in detail the example analysis of all the attribute fields in composer.json. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

1 、 name

The name of the bag. Consists of the supplier (vendor) name and the project name, separated by /.

It needs to be filled in when releasing the package.

2 、 description

A short description of a package, usually the length of a line.

It needs to be filled in when releasing the package.

3 、 version

The version of the package.

The format must be X.Y.Z with optional suffixes:-dev,-alphaN,-betaN,-RCN.

4 、 type

The type of the package, default to library.

The package type is used to customize the installation logic. If your package installation requires some special logic, you can define a custom type. It can be a type of symfony-bundle, or wordpress-plugin, or typo3-module. These types will be used by specific projects, and they will provide an installer to install these types of packages.

Composer supports three types:

Library: default value. It will copy the files to the vendor directory.

Project: it indicates that this is a project, not a library. For example, applications like Symfony Standard.

Metapackage: an empty package with dependencies that triggers the installation but does not contain files and does not write anything to the file system.

Composer-install: a package that provides an installer for other custom types of packages.

5 、 keywords

An array of keywords related to the package. Used for packet search and filtering.

Optional.

6 、 homepage

The website of the project, URL.

Optional.

7 、 time

Release time of the version. Must be in YYYY-MM-DD or YYYY-MM-DD HH:MM:SS format.

Optional.

8 、 license

The license for the bag. Can be a string or an array of strings.

Optional, but strongly recommended.

9 、 authors

The author of the bag. It's an array of objects.

Each author object has these properties:

Name: first name of the author

Email: author's mailbox

Homepage: the author's website URL

Role: the role of the author in the project (e.g. developer or translator)

10 、 support

All kinds of information about how to get support for the project. Include these attributes:

Email: get supported mailboxes

Issues: URL for problem tracking

Forum: URL of the forum

URL of wiki:Wiki

Irc:IRC 's channel

Source: view or download URL of the source code

Optional.

11 、 Package links

Depends on the mapping table of the package, which is constrained by the package name mapping version. Such as:

{"require": {"monolog/monolog": "1.0.*"}}

(1) require

Lists the packages on which the package depends. This package will not be installed unless these dependencies already exist.

(2) require-dev (root-only)

List the packages that you rely on to develop this package (or run tests, etc.). When using the install command, the dev package can only be installed with the "- dev" parameter. When using the update command, it is not updated with "- no-dev".

(3) conflict

List which packages will conflict with. They will not be allowed to be installed with your package. If a version is constrained, it is only for a specific version.

(4) replace

List which packages will be replaced by this package.

(5) provide

A list of recommended packages for this package. This is most useful for public interfaces, where a package can rely on a virtual logger package, while libraries that implement the logger interface can be placed in the provide field.

12 、 suggest

Suggest a list of packages that will make this package work better or enhanced. This information is given only when the package installation is complete, suggesting that the user can add more packages, although it is not necessary to install them.

Format is, package name mapping text description, such as:

{"suggest": {"monolog/monolog": "Allows more advanced logging of the application flow"}}

13 、 autoload

The auto-load mapping provided to PHP autoloader.

Currently supported are: PSR-0 auto-loading specification, classmap generator, and files.

PSR-0 is recommended because of its excellent extensibility (there is no need to regenerate the autoloader when adding new classes).

(1) PSR-0

Under the psr-0 key name, define a namespace-to-path mapping table, relative to the root of the package. Note that this also supports PEAR-style 's namespace-free style.

Note that the declaration of the namespace ends with\\ to ensure that the autoloader responds correctly.

References to PSR-0 can be viewed in files generated during installation or update:

Vendor/composer/autoload_namespaces.php

Example:

{"autoload": {"Monolog\": "src/", "Vendor\\ Namespace\\": "src/", "Vendor_Namespace_": "src/"}

If you need to find a namespace with the same prefix in multiple directories, you can use an array, such as:

{"autoload": {"psr-0": {"Monolog\\": ["src/", "lib/"]}

The PSR-0 style is not limited to things that load namespace declarations, but can also be used at the class level. This approach can be used when there is only one class in the global namespace in the library. For example, if you have a PHP source file in the root directory of the project, you can declare:

{"autoload": {"psr-0": {"UniqueGlobalClass": ""}

If you have a directory that is all organized in namespaces, you can use the unprecedented suffix:

{"autoload": {"psr-0": {":" src/ "}

(2) Classmap

References to classmap can be viewed in files generated during installation or update:

Vendor/composer/autoload_classmap.php

The class mapping table is generated by scanning all .php and .inc files under the specified directory or file.

You can use the classmap generator to automatically load any library that does not support PSR-0. In configuration, you only need to specify the directory or file where the class is located:

{"autoload": {"classmap": ["src/", "lib/", "Something.php"]}}

(3) files

If you determine that you need to load certain files in any request, you can use the files autoload mechanism. It is especially useful when there are some PHP functions in those packages that cannot be loaded automatically. For example:

{"autoload": {"files": ["src/MyLibrary/functions.php"]}}

14 、 include-path

Will be deprecated and its function will be replaced by autoload. In fact, it is to set include_path (optional)

15 、 target-dir

Specify the installation target path.

If the root directory of the package is under the namespace, the autoload is incorrect, so there is target-dir to solve this problem.

Symfony is an example. It consists of many component packages. The Yaml component is located in the

Symfony\ Component\ Yaml

Namespace, whose root directory is the Yaml directory. For autoload to work properly, we need to make sure that it is not installed in the

Vendor/symfony/yaml

But in the

Vendor/symfony/yaml/Symfony/Component/Yaml

So that the autoloader can load it from vendor/symfony/yaml

So the definition of target-dir is as follows:

{"autoload": {"psr-0": {"Symfony\\ Component\\ Yaml\": ""}}, "target-dir": "Symfony/Component/Yaml"}

16. Minimum-stability (root-only)

Defines how packets are filtered based on stability. The default is stable. If you trust a dev package, you need to specify it.

17. Prefer-stable (root-only)

If enabled, Composer chooses the former between stable and unstable packages.

18. Repositories (root-only)

The warehouse address of the custom package.

By default, Composer uses only Packagist repositories. By specifying the warehouse address, you can get the package from anywhere.

The warehouse cannot be recursive. You can only add them to the Lord's composer.json. The repository definition in the composer.json file in the dependent package is ignored.

The types of warehouses supported are:

(1) composer

The composer repository provides packages.json files over the network, which contains a list of composer.json objects, as well as additional dist or source information. The packages.json file is loaded through the PHP stream.

(2) vcs

Version control system repositories, such as git, svn, hg.

(3) pear

With it, you can import any pear repository into your project.

(4) package

If you rely on a project that does not support composer, you can define a repository of type package and write the composer.json object directly.

A complete example:

{"repositories": [{"type": "composer", "url": "http://packages.example.com"}, {" type ":" composer "," url ":" https://packages.example.com", " "options": {"ssl": {"verify_peer": "true"}, {"type": "vcs", "url": "https://github.com/Seldaek/monolog"}" {"type": "pear", "url": "http://pear2.php.net"}, {" type ":" package "," package ": {" name ":" smarty/smarty "," version ":" 3.1.7 " "dist": {"url": "http://www.smarty.net/files/Smarty-3.1.7.zip"," type ":" zip "}," source ": {" url ":" http://smarty-php.googlecode.com/svn/", " "type": "svn", "reference": "tags/Smarty_3_1_7/distribution/"]}

19. Config (root-only)

Some configurations for the project.

Process-timeout: default 300s, Composer process timeout; use-include-path: default false, if it is true,Composer autoloader, it will also look in PHP's include_path; preferred-install: default auto, set Composer installation mode; github-protocols: default ["git", "https"], set communication protocol with github; github-oauth: set oauth;vendor-dir: default vendor, you can change it to something else. Bin-dir: default vendor/bin, which will be linked if the project has binaries; cache-dir: default $home/cache, which stores the cache generated when Composer is running; cache-files-dir: default $cache-dir/files, which stores the zip file of the package; cache-repo-dir: default $cache-dir/repo, which stores warehouse metadata; cache-vcs-dir: default $cache-dir/vcs, which stores vcs clones Cache-files-ttl: default of six months, cache expiration time; cache-files-maxsize: default of 300Mnotiposition false: default true, installation package from the repository will be notified, which can be turned off; discard-changes: default false, how to handle dirty updates

20. Scripts (root-only)

Composer allows you to install hook scripts during installation. Hooks are event-based.

21 、 extra

Additional data for scripts consumption

22 、 bin

Specifies which files must be treated as binary files

23 、 archive

Set the options when creating the package, and the exclude property sets which directories to exclude, for example:

{"archive": {"exclude": ["/ foo/bar", "baz", "/ * .test", "! / foo/bar/baz"]} this is the end of the article on "sample analysis of all attribute fields in composer.json". I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good. Please share it for more people to see.

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