zoukankan      html  css  js  c++  java
  • 一步一步创建自己的composer包

    构建之前

    1. 申请github账号,并建好一个repositories。
    2. 用github登录packageList.

    创建包

    初始化仓库

    mkdir -p /www/plan
    cd /www/plan
    
    echo "# plan" >> README.md
    git init
    git add README.md
    git commit -m "first commit"
    git remote add origin git@github.com:lujiang/plan.git
    git push -u origin master

    composer init构建composer.json

    {
        "name": "lujiang618/plan",
        "description": "plan",
     "type": "project",
     "licence": "MIT",
        "authors": [
            {
                "name": "lujiang",
                "email": "531432594@qq.com"
            }
        ],
        "require": {
      "php":">=7.0.0"
     },
     "autoload": {
      "psr-4":{
       "Tools\":"src/Tools"
      }
     }
    }

    构建包

    1.按照autoload中设置的,在根目录下建一个Tools的目录
    2.在Tools目录写一个tools类

    <?php
    /**
     * Created by PhpStorm.
     * User: lujiang
     * Date: 2018/9/30
     * Time: 15:57
     */
    
    namespace Tools;
    
    class Tools
    {
        public function __construct() {
    
        }
    
        public static function hi() {
            echo 'hi';
        }
    }
    

    3.在根目录写一个测试类hi.php

    <?php
    /**
     * Created by PhpStorm.
     * User: lujiang
     * Date: 2018/9/30
     * Time: 16:06
     */
    
    require_once './vendor/autoload.php';
    
    use ToolsTools;
    
    echo Tools::hi();
    

    4.执行composer install生成vendor目录

    5.执行测试类,输出hi。如此一个包构建完成了

    cd /www/plan
    php hi.php
    

    6.提交代码到github

    git add .
    git commit -am 'first'
    git push
    
    git tag -a v0.0.1 -m "first version"
    git push origin v0.0.1

    在github上发布版本,找到release,执行发布(勾上[This is pre-release])

    在packagist上submit package。并在profile里面获取token。在github的settings的Installed GitHub Apps添加packagist的service

    参考资料

    1. 如何建立自己的composer包
  • 相关阅读:
    leetcode 13. Roman to Integer
    python 判断是否为有效域名
    leetcode 169. Majority Element
    leetcode 733. Flood Fill
    最大信息系数——检测变量之间非线性相关性
    leetcode 453. Minimum Moves to Equal Array Elements
    leetcode 492. Construct the Rectangle
    leetcode 598. Range Addition II
    leetcode 349. Intersection of Two Arrays
    leetcode 171. Excel Sheet Column Number
  • 原文地址:https://www.cnblogs.com/gelu/p/9732649.html
Copyright © 2011-2022 走看看