composer 创建自己包

Posted xuey

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了composer 创建自己包相关的知识,希望对你有一定的参考价值。

服务器环境下创建自己的项目文件

技术分享图片

 

初始化composer

打开cmd 窗口,cd 到 backrestore 执行 composer init 命令

D:phpStudyWWWackrestore>composer init
Welcome to the Composer config generator This command will guide you through creating your composer.json config. Package name (
<vendor>/<name>) [administrator/backrestore]: xue-y/backrestore Description []: mysql Backup and restore // 项目描述可以不写 Author [xue-y <1922527784@qq.com>, n to skip]:
// 这里跳过使用默认 Minimum Stability []: Package Type (e.g. library, project, metapackage, composer-plugin) []: License []: // 这个可以不填 Define your dependencies. Would you like to define your dependencies (require) interactively [yes]? y Search for a package: Would you like to define your dev dependencies (require-dev) interactively [yes]? y Search for a package: { "name": "xue-y/backrestore", "description": "mysql Backup and restore", "authors": [ { "name": "xue-y", "email": "[email protected]" } ], "require": {} } Do you confirm generation [yes]? y

这里完成composer 初始化工作,自动生成一下文件

技术分享图片

编辑composer.json 文件

{
    "repositories": {     // 更改镜像源,国外的太慢
        "packagist": {
            "type": "composer",
            "url": "https://packagist.phpcomposer.com"
        }
    },
    "name": "xue-y/backrestore",
    "description": "mysql Backup and restore",
    "license": "Apache-2.0",
    "minimum-stability":"stable",
    "authors": [
        {
            "name": "xue-y",
            "email": "[email protected]"
        }
    ],
    "require": {
        "php": ">=5.0"
    },
    "autoload": {   // 添加自动加载
        "psr-4": {
            "backup\\": "backup/",
            "import\\": "import/"
        }
    }
}

执行 composer install 

D:phpStudyWWWackrestore>composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files

 

测试文件

技术分享图片

 

创建git 仓库

 技术分享图片

创建后会跳转到下面这个页面,根据你的需要按命令操作

技术分享图片

 

项目提交git

我这个项目现在不是一个存储库,所有先执行了一下 git init 初始化仓库

[email protected] MINGW64 /d/phpStudy/WWW/backrestore
$ git init
Initialized empty Git repository in D:/phpStudy/WWW/backrestore/.git/

[email protected] MINGW64 /d/phpStudy/WWW/backrestore (master)
$ git add README.md
[email protected] MINGW64
/d/phpStudy/WWW/backrestore (master) $ git commit -m 添加第一个测试文件 [master (root-commit) d79b36b] 添加第一个测试文件 1 file changed, 76 insertions(+) create mode 100644 README.md
[email protected] MINGW64
/d/phpStudy/WWW/backrestore (master) $ git remote add origin https://github.com/xue-y/backrestore.git [email protected] MINGW64 /d/phpStudy/WWW/backrestore (master) $ git push -u origin master Counting objects: 3, done. Delta compression using up to 2 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 1.57 KiB | 1.57 MiB/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: remote: Create a pull request for master on GitHub by visiting: remote: https://github.com/xue-y/backrestore/pull/new/master remote: To https://github.com/xue-y/backrestore.git * [new branch] master -> master Branch master set up to track remote branch master from origin.

 添加标签

技术分享图片

 




以上是关于composer 创建自己包的主要内容,如果未能解决你的问题,请参考以下文章

如何创建自己的composer包

创建自己的composer包

一步一步创建自己的composer包

开发自己的composer包

如何将自己的php包GitHub项目与composer集成使用和同时开发

使用 compose 在 AndroidView 中使用片段时崩溃