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

How to develop your own php expansion package with composer

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Editor to share with you how to use composer to develop their own php expansion package, 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 know it!

Composer is a tool used by PHP to manage dependencies

Development process

Initialize your own expansion pack composer init

$composer init Welcome to the Composer config generator This command will guide you through creating your composer.json config.Package name (/) [administrator/self_composer]: victor/composer-self / / package name-cannot be capitalized Otherwise invalid Description []: composer-self package / / description Author [victor24680, n to skip]: / / author Minimum Stability []: dev / / minimum stable version Package Type (e.g. Library, project, metapackage, composer-plugin) []: library / / Type License []: MITDefine your dependencies.Would you like to define your dependencies (require) interactively [yes]? N / / do you define the dependency Would you like to define your dev dependencies (require-dev) interactively [yes]? N {"name": "victor/composer-self", "description": "This is a composer-send package", "type": "victor", "license": "MIT", "authors": [{"name": "victor24680", "email": "490319148@qq.com"}], "minimum-stability": "dev" "require": {}} Do you confirm generation [yes]? Yes

Modify the dependency of your own package, as follows

{"name": "victor/sendtool-package", "description": "sendtool package", "type": "victor", "license": "MIT", "authors": [{"name": "victor24680", "email": "490319148@qq.com"}], "minimum-stability": "dev" "require": {"php": "> = 5.6" / / php version requirements}, "autoload": {"psr-4": {/ / loading specification "App\": "src/App", "Contract\": "src/Contract"}

To prepare the source code, please see: https://github.com/victor24680/self-composer/tree/master/src

Install and test composer install

$composer installLoading composer repositories with package informationUpdating dependencies (including require-dev) Content-Length mismatch, received 37487 bytes out of the expected 2005372 http://packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of dateNothing to install or updateWriting lock fileGenerating autoload files

Create a composer-self repository on GitHub

Git initgit add .git commit-m "initial component library" git remote add origin https://github.com/victor24680/self-composer.gitgit push origin master

Submit the address of the composer-self warehouse created by your github on Packagist

Registered address: https://packagist.org/, after the submission is successful, you can start the following test

Test, directory A represents the project root directory

Create an A directory and execute it under the project root: composer require victor24680/self-composer dev-master

$composer require victor24680/self-composer dev-master./composer.json has been updatedLoading composer repositories with package informationUpdating dependencies (including require-dev) Package operations: 1 install, 0 updates, 0 removals-Installing victor24680/self-composer (dev-master 0935c75): Cloning 0935c75eda from cacheWriting lock fileGenerating autoload files

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