封装自定义的composer包,并发布到packgist.org

封装自定义的composer包,并发布到packgist.org
2022-05-20 20:29:29 0
本文 2515 个字,阅读需要大约 6 分钟
加载失败

文章目录 [回顶部]
发布自己的composer包
composer 包结构介绍
2. 发布到 packagist.org
3. 设置自动更新
[--评论--]

发布自己的composer包

composer 包结构介绍

├── composer.json // composer.json
├── LICENSE // 遵循的许可
├── README.md // 包使用说明
├── src // 包的源代码
│   └── Hello.php 
├── test // 单元测试代码
│   └── demo.php
└── vendor // 自动加载和第三方库
    ├── autoload.php // 全局自动加载文件,需要在项目入口引入该文件
    └── composer // 自动加载具体的文件
        ├── autoload_classmap.php
        ├── autoload_namespaces.php
        ├── autoload_psr4.php
        ├── autoload_real.php
        ├── autoload_static.php
        ├── ClassLoader.php
        ├── installed.json
        ├── installed.php
        ├── InstalledVersions.php
        └── LICENSE

具体文件介绍:

  • composer.json

          {
                  "name": "leorain/self-composer", // 包名字,其他用户通过这个名字搜索到你的包
                  "description": "composer test", // 包描述,最好用一句话描述包的内容,通俗易懂
                  "license": "MIT", // 遵循的协议。常见的还有 Apache 、GNU 等
                  "autoload": { // 自动加载相关配置
                          "psr-4": { // psr-4 类的自动加载
                                  "Leorain\\SelfComposer\\": "src/"
                          }
                  },
                  "authors": [ // 作者相关信息
                          {
                                  "name": "leorain",
                                  "email": "woshilihexin@gmail.com"
                          }
                  ],
                  "require": {} // 依赖的第三方包信息
          }
    
  • LICENSE 这里借用 guzzle 包的 LICENSE 文件
    ```
    The MIT License (MIT)

    Copyright (c) 2011 Michael Dowling mtdowling@gmail.com
    Copyright (c) 2012 Jeremy Lindblom jeremeamia@gmail.com
    Copyright (c) 2014 Graham Campbell hello@gjcampbell.co.uk
    Copyright (c) 2015 Márk Sági-Kazár mark.sagikazar@gmail.com
    Copyright (c) 2015 Tobias Schultze webmaster@tubo-world.de
    Copyright (c) 2016 Tobias Nyholm tobias.nyholm@gmail.com
    Copyright (c) 2016 George Mponos gmponos@gmail.com

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.

- **README.md**
包的 readme.md 文件,现在以 markdown 格式为主,主要是介绍包的用途和基本用法
# composer 发包测试
## 如您所见,这个 composer 包是用来测试 [https://packagist.org/](https://packagist.org/) 发 composer 包的。有时候也会写一些发包相关的问题。
### 发包流程:
1. github 或者其他仓库创建项目。
2. 登录 [https://packagist.org/](https://packagist.org/)
3. 点击 submit 
4. 填写 github 仓库地址
5. 提交!

## 封包流程
### 1. 创建仓库并上传代码
代码仓库需要开源,packagist可以直接拉取代码。这里选用github。

- 登录 github 

- 创建新仓库,并设置开源

  ![2022-05-23-11-20-15](https://gallery-repository.oss-cn-hangzhou.aliyuncs.com/images/2022/05/23/2022-05-23-11-20-15.png)

- 本地代码 git 初始化。如果是先创建仓库后编写代码,或者本地代码已经设置远程仓库地址,跳过这一步

  ```shell
  git init 
  git remote add github [git仓库地址]
  git add . 
  git commit -m "init"
  git tag -a v0.0.1
  git push tag v0.0.1

2. 发布到 packagist.org

  • 注册并登录 packagist.org

  • 点击 submit

  • 粘贴代码仓库地址

  • 点击 检查 ,并提交

    image-20220523112758405

3. 设置自动更新

进到包主页,点击右侧版本下面的 auto-updated . 根据引导设置自动更新

image-20220523112839322

原创文章,转载请注明出处~ 以上就是本文的全部内容啦,有什么疑问欢迎在下方评论区留言嗷,收到通知会及时回复~
文章浏览总量:724 (非即时 )
Comments
Nothing...
推荐文章 使用余弦向量算法进行推荐(分数)
跳转到顶部