zoukankan      html  css  js  c++  java
  • composer引用本地git做为源库

    PHP使用者大多对composer是又爱又恨,爱的是composer require后,很多类库不用去下载了,恨的是网速卡成翔,虽然国内有很多道友做了镜象,但对于bower库这些都还是整体更新。

    那么,如何只利用composer的基本功能来为自己服务呢?composer的官网有介绍,只要在composer.json中加入几行代码就行了。。

    1
    2
    3
    4
    5
    6
    "repositories":[ 
           
               "type":"git"
               "url":"/var/www/gouki/test/" 
           }, 
       

    上面的代码中/var/www/gouki/test,是我的一个git库。也是按照composer的标准来建的。里面只有一个composer.json文件:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
        "name":"gouki/test"
        "description":"test"
        "authors":[ 
            
                "name":"gouki"
                "email":"xxxx@qq.com" 
            
        ], 
        "minimum-stability":"dev"
        "require":{}, 
        "autoload":{ 
            "psr-4":{ 
                "gouki\test\":"src/"
            }
        },
        "extra":{
            "branch-alias":{
                "dev-master":"1.0.x-dev" 
            
        

     src目录下的代码中使用的namespace就是gouki est,然后在原项目的composer.json中再加入:

    1
    2
    3
    "require":{ 
            "gouki/test":"dev-master" 
        }, 

      

    最后,运行一下composer update,你会看到项目的根目录下多了vendor目录,同时,vendor目录下也会多一个gouki/test的目录,至此项目引入成功,如果还不放心,那就看一下:vendor/composer/autoload_psr4.php中有没有gouki/test。

    之所以这么做,就是因为前文所说的速度,当然也有小团队的成本。比如写个类,就可以直接composer进行加载了。

    问题就这么来了,如果放到线上去,那上面的

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    "repositories":[   
           {   
               "type":"git",   
               "url":"/var/www/gouki/test/"   
           },   
       ]  
    需要改为: 
    "repositories":[   
           {   
               "type":"git",   
               "url":" http://xxxx.xxx.xxx/git "   
           },   
       ]    

     如果该git是public的,则不需要任何处理,如果git是需要登录的,则需要在项目的根目录下(和composer.json平级的目录)增加一个auth.json,里面也就两三行代码

    1
    2
    3
    4
    5
    6
    7
    8
    {   
        "http-basic":{   
            "http://xxxx.xxx.xxx/git":{   
                "username":"",   
                "password":""   
            }   
        }   
    }   

      

    当然如果你是ssh免登陆的git则另计。至此一个小小的自建composer源就已经完成。

    本站采用版权协议, 要求署名、非商业和保持一致. 本站欢迎任何非商业应用的转载, 但须注明出自"

    ", 保留原始链接, 此外还必须标注原文标题和链接.

  • 相关阅读:
    【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones
    【概率dp】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs
    【基数排序】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C. Jon Snow and his Favourite Number
    【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1
    【kmp算法】poj2185 Milking Grid
    【kmp算法】poj2406 Power Strings
    【DFS】Codeforces Round #398 (Div. 2) C. Garland
    【枚举】【贪心】 Codeforces Round #398 (Div. 2) B. The Queue
    【暴力】Codeforces Round #398 (Div. 2) A. Snacktower
    【kmp算法】uva11475 Extend to Palindrome
  • 原文地址:https://www.cnblogs.com/huashengxue/p/9578599.html
Copyright © 2011-2022 走看看