composer-package demo

作者: 太阳上的雨天 分类: Composer,PHP 发布时间: 2021-07-02 15:16

Composer-package制作,代码上传github,发布到packagist,并配置github代码更新自动上传packagist(github的webhook)

1. 初始化double-triple-encryption文件夹

# mkdir double-triple-encryption
# composer init

This command will guide you through creating your composer.json config.

Package name (<vendor>/<name>) [cc/double-triple-encryption]:
Description []: Adopt AES threee-stage three-layer encryptioin
Author [, n to skip]: Adoniscc
Invalid author string.  Must be in the format: John Smith <john@example.com>
Author [, n to skip]: Adoniscc <cljcailianjie@163.com>
Minimum Stability []: stable
Package Type (e.g. library, project, metapackage, composer-plugin) []: library
License []: MIT

Define your dependencies.

Would you like to define your dependencies (require) interactively [yes]? N
Would you like to define your dev dependencies (require-dev) interactively [yes]? N
Add PSR-4 autoload mapping? Maps namespace "Cc\DoubleTripleEncryption" to the entered relative path. [src/, n to skip]:

{
    "name": "cc/double-triple-encryption",
    "description": "Adopt AES threee-stage three-layer encryptioin",
    "type": "library",
    "license": "MIT",
    "autoload": {
        "psr-4": {
            "Cc\\DoubleTripleEncryption\\": "src/"
        }
    },
    "authors": [
        {
            "name": "Adoniscc",
            "email": "cljcailianjie@163.com"
        }
    ],
    "minimum-stability": "stable",
    "require": {}
}

Do you confirm generation [yes]? yes
Generating autoload files
Generated autoload files
PSR-4 autoloading configured. Use "namespace Cc\DoubleTripleEncryption;" in src/
Include the Composer autoloader with: require 'vendor/autoload.php';


Config.php
<?php
/**
 * Copyright (C), 2016-2018, Adoniscc, Ltd.
 * Filename:
 * Description:
 *
 * @author: Adoniscc
 * @Create Date: 2021/11/4 1:19 下午
 * @Update Date: 2021/11/4 1:19 下午 By Adoniscc
 * @version: 1.0
 */

namespace DoubleTripleEncryption\Config;

class Config
{
    public function info()
    {
        echo "This is config info";
    }
}
Demo.php
<?php
/**
 * Copyright (C), 2016-2018, Adoniscc, Ltd.
 * Filename:
 * Description:
 *
 * @author: Adoniscc
 * @Create Date: 2021/11/4 1:19 下午
 * @Update Date: 2021/11/4 1:19 下午 By Adoniscc
 * @version: 1.0
 */

namespace DoubleTripleEncryption\Encrypt;

class Demo
{
    public function info()
    {
        echo "This is demo info";
    }
}
Test.php
<?php
/**
 * Copyright (C), 2016-2018, Adoniscc, Ltd.
 * Filename:
 * Description:
 *
 * @author: Adoniscc
 * @Create Date: 2021/11/4 1:20 下午
 * @Update Date: 2021/11/4 1:20 下午 By Adoniscc
 * @version: 1.0
 */

namespace DoubleTripleEncryption\Test;

class Test
{
    public function info()
    {
        echo "This is test info";
    }
}
.gitignore
.idea

2. gitHub.com 创建一个仓库,并把代码提交上去

3. 将github地址提及到packagist中

1. 登陆https://packagist.org/packages/submit

2. 配置github自动更新到packages




3. 安装测试

1. 创建一个test文件夹
-> mkdir test

-> cd test

-> composer init (一路回车即可)

-> composer require adoniscc/double-triple-encryption:dev-main

2. test目录下新建index.php文件

3 . 输出以下则说明成功

git tag 发布稳定版本 composer 包
git add .
git commit -m '描述'
git tag -a v0.1 -m 'version 0.1'
git push origin --tags

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注