飞嗨,欢迎您的光临,本博所发布之文章皆为作者亲测通过,如有错误,欢迎通过各种方式指正。(本博已于2015.12.6升级到php7,运行环境php7 php-fpm + nginx1.8.0)

编写和提交composer包到packagelist

PHP lf 5787℃ 0评论

python有pip,node.js有npm包管理工具。php在composer出现之前,有个官方的pear,好吧,虽然我很早就知道pecl和pear,但我从来没用过pear…直到非官方的composer出现,php的包管理工具也流弊哄哄啦,composer包依赖管理真心太好用了,现在众多的sdk、插件、框架,官方都置composer安装为recommend。今天是2015年最后一天了,也做了小两年php啦,也来共享一下自己的积累。

        本例程github地址:http://www.github.com/liufee/php,composer包搜索feehi/standard安装。目前只分享了一个http request类,慢慢会把自己常用的工具全放上去,composer安装遇到任何问题欢迎联系QQ:1838889850和email:admin@feehi.com

        composer自动导入类,有他自己的一套导入规则(vendor/composer目录下的源码,读里面的源码才能更好的理解composer的自动导入机制)。composer分别有较老的psr-0和最新的psr-4自动导入标准。这次,我们先使用psr-0的标准,其实psr-4跟psr-0差不多,只是psr-4更精简了目录结构以及对下划线的处理方式不同而已。

首先要有一个github/bitbucket账号,然后编写composer.json文件,告诉composer应该要怎么处理这个包,当然这个composer.json的文章大大的有,肯定必须读官方的文档>>官方说明,如:

{
    "name": "feehi/standard",
    "type": "library",
    "description": "A library provided by wfee",
    "keywords": ["feehi","library","liufee"],
    "homepage": "https://blog.feehi.com/wp-content/uploads",
    "license": "MIT",
    "authors": [
        {
            "name": "liufee",
            "email": "job@feehi.com",
            "homepage": "https://blog.feehi.com/wp-content/uploads",
            "role": "Developer"        
        }
    ],
    "require:": {
        "php": ">=5.4"
    },
    "autoload": {
        "psr-0": {
            "Feehi": "src/"
        }
    }
}

name为vendor name/package name,require指明此包依赖于哪些别的包,autoload指定使用自动加载的标准是psr-0还是psr-4。这里详细一定要读文档。

然后,git push代码到github。打几个tag,composer会认为包更稳健,下图就有2个release

github php

github php

        然后去packagelist.org注册一个账号,并向composer submit这个包

submit package

submit package

feehi/standard

feehi/standard

好啦,就阔以啦。成功!需要注意的是,composoer.json配置了composer对此包是如何处理的,所以一定要搞明白,其次,写的php代码命名空间要写对,要适应psr-0或者psr-4的自动导入标准,不然会造成composer自动require的时候找不到文件的正确位置。读读vendor/composer下的加载源码,以及读读psr-0和psr-4自动加载的文档是非常有必要的。当然,现在往github上push代码时,需要到pakagelist.org点击update手动更新,github已经提供了钩子,只要设置就可在每次push代码时自动update,点击github仓库中settings按钮,然后点击Webhooks & Services,然后点击add service选中packagist,填入相应配置。这样,每当往github上push代码就能自动update到packagist啦

packagistpackagist[/caption]

composer feehi/standard

 composer feehi/standard


        现在,我们就可以通过composer来自动安装feehi/standard这个库啦。编写composer.json,这个composer.json是配置要安装什么包,跟提交包到composer不是一回事。比如:

 "require": {
            "feehi/standard" : "*"
        }

指定要安装的宝明,*代表的版本号。当然,我们处在一个神奇的国度,真心想不明白composer哪里就危害郭嘉了!!!只有配置一下镜像,让composer去国内的镜像(这个好坑,明明在pakagelist更新了,但是国内镜像并非实时的,有缓存,,,哎)如:

{
        "require": {
            "feehi/standard" : "*"
        },
        "repositories": [
            {"type": "composer", "url": "http://packagist.phpcomposer.com"},
            {"packagist": false}
        ]
   }

然后运行composer update就能看到composer帮我们自动安装以及解决依赖和自动导入这个库了

composer install

composer install

这里面已经带了一个测试文件了,让然我们也可以自己手写一个测试文件:

  <?php
  require "vendor/autoload.php";

  use Feehi\Http;

  $http = new Http();
  $res = $http->get("https://blog.feehi.com/wp-content/uploads");
  $res = $http->post("https://blog.feehi.com/wp-content/uploads", ['username'=>'xxx','password'=>'yyy']);
  var_dump($res);

result

result

转载请注明:飞嗨 » 编写和提交composer包到packagelist

喜欢 (7)or分享 (0)
发表我的评论
取消评论
表情
(36)个小伙伴在吐槽
  1. Poppers Und Levitra http://viacialisns.com/# - Buy Cialis Le Viagra Generique Est Il Efficace cialis 5 mg best price usa Cialis Dosierung Erfahrungen
    匿名2020-02-23 12:36 (7小时前)回复
  2. Buy Stendra Free Shipping https://buyciallisonline.com/# - cialis vs viagra Difference Between Cephalexin And Cephalexin Monohydrate Cialis Viagra Wirkung Prostata
    匿名2020-02-19 17:37 (4天前)回复
  3. Amoxicillin For Canines http://abcialisnews.com - Cialis Viagra Prescription In Canada п»їcialis Safe Online Viagra
    匿名2020-02-19 14:12 (4天前)回复
  4. Buy Methotrexate 2 5 Mg No Rx Overnight http://buyciallisonline.com/# - Buy Cialis Diclofenac Tablets Without Prescription Buy Cialis Propecia Receding
    匿名2020-02-11 02:32 回复
  5. Proscar Order Best On Line Pharmacy http://cheapcialisir.com - Cheap Cialis Kamagra 200 Mg Cialis Comprar Cialis Femenino
    匿名2020-02-09 08:11 回复
  6. Cephalexin Sinus http://abuycialisb.com - Buy Cialis Farmaci Con Dapoxetina cialis online Generic Viagra Costco
    匿名2020-02-09 07:20 回复
  7. Amoxicillin For Dry Socket http://buycialisuss.com - Buy Cialis Cephalexin Dose Morning Night Buy Cialis Levitra 20mg Pas Cher
    匿名2020-02-08 05:28 回复
  8. How Much Amoxicillin For A Cat http://cheapcialisir.com - buy generic cialis online Nebenwirkungen Von Viagra Forum cialis without prescription Tadalis Sx Naturel En Ligne
    匿名2020-02-07 23:01 回复
  9. Buying Discount Provera Cod Only http://buyciallisonline.com/# - Cialis Ed Meds Usa Buy Cialis Viagra Levitra Et Cialis
    匿名2020-02-07 04:51 回复
  10. Meilleure Facon De Prendre Priligy http://ggenericcialisle.com - Cialis Como Usar El Kamagra cialis Zithromax Strength
    匿名2020-02-04 06:47 回复
  11. Acheter Baclofen En Canada http://ggenericcialisle.com - Cialis Priligy And Cialis Cialis Cheap Antabuse Disulfiram
    匿名2020-02-03 19:39 回复
  12. isotretinoin 10mg http://cialisir.com - Buy Cialis Buy Discount Secure Provera Real No Prior Script cialis generic Cialis Ou Viagra Acheter
    匿名2020-02-03 09:48 回复
  13. Ou Acheter Du Vrai Kamagra http://cheapcialisir.com - Buy Cialis Can i purchase isotretinoin 10mg website cheap Cialis Discount Doxycycline Where To Buy
    匿名2020-02-02 20:23 回复
  14. Cytotec Voie Oral http://cialibuy.com/#755 - cheapest cialis Amoxil Categorie De Grossesse cialis from canada Viagra 50 Mg Reviews
    匿名2020-02-01 09:06 回复
  15. Propecia Cancer Risk http://buyciallisonline.com/#442 - Buy Cialis Cialis Effet Dose Cialis Overnight Cialis In Us
    匿名2020-02-01 02:38 回复
  16. Purchase Fluoxetine Medication Quick Shipping Low Price http://buyciaonlinex.com - Buy Cialis Online Us Pharmacy Cialis Levitra 10 Mg Vendita
    匿名2020-01-30 23:13 回复
  17. Furosemide Side Effects http://abcialisnews.com - cialis Propecia Finasteride Problemi Buy Cialis Pcm Pharmacy Utah
    匿名2020-01-30 15:01 回复
  18. Discount For Effexor Xr http://cheapcialisir.com - generic 5mg cialis best price Kamagra Prescrizione Montreal Buy Cialis 5mg Cialis Online
    匿名2020-01-30 13:08 回复
  19. Safe Generic Propecia Finasteride 1mg http://abcialisnews.com - cialis canada Que Es Levitra 20 Mg cialis Best Place To By Online Viagra Usa
    匿名2020-01-29 20:24 回复
  20. Viagra Generique France http://cialibuy.com - Buy Cialis Online Pharmacy India Cialis canadian pharmacy cialis Where Can I Buy Discount Progesterone Medication Shop
    匿名2020-01-28 12:45 回复
  21. Discount Zentel With Free Shipping http://abcialisnews.com - Buy Cialis How To Get Levitra canadian cialis Cialis 5 Mg Giorni Alterni
    匿名2020-01-28 08:21 回复
  22. Healtyman. Com http://cialibuy.com - Cialis Why Use Keflex Cialis Amoxicillin Drug Interactions
    匿名2020-01-26 18:17 回复
  23. Viagra Pfizer 100 http://cialibuy.com - Buy Cialis Generic Viagra For Less cialis Cialis Kamagra Bestellen
    匿名2020-01-26 10:34 回复
  24. Zithromax To Treat Eczema http://cialibuy.com - Buy Cialis Zithromax Adverse Effects Buy Cialis For Sale Provera Pills Overseas
    匿名2020-01-26 04:48 回复
  25. Best Generic Viagra Overnight http://cialibuy.com - cialis vs viagra Prix Levitra 20mg cialis 20mg price at walmart Comprar Remedio Levitra
    匿名2020-01-24 23:36 回复
  26. Want To Buy Dutasteride http://cialibuy.com - Cialis Cheap Kamagra Soft Tabs Cialis Uk Meds Online
    匿名2020-01-23 18:58 回复
  27. Canadian Pharmcy Buy Cialis Propecia Castillo Injectable Amoxicillin
    匿名2020-01-20 02:52 回复
  28. Viagra Positive Nebenwirkungen Buy Cialis Viagra Kaufen Mit Uberweisung Kamagra Sildenafil Citrate Cephalexin Strep
    匿名2020-01-19 08:56 回复
  29. Zithromax Online Overnight A Vendre Baclofen Propecia Bon Prix Pharmacie Achat Cialis Isotretinoin Discount Fedex Shipping Glasgow
    匿名2020-01-18 23:49 回复
  30. What Is The Structure Of Amoxicillin Amoxicillin Dreams Amoxicillin Ulcers Cialis Viagra Brand Vs Generic Dutasteride From Canada Free Shipping
    匿名2020-01-16 09:18 回复
  31. ertyukl :wink:
    匿名2019-09-08 05:17 回复
  32. 66
    匿名2018-08-24 15:50 回复
  33. 99
    匿名2017-08-15 11:29 回复
    • 感谢光临飞嗨博客
      lf2017-08-18 00:12 回复
      • hello
        匿名2019-11-09 16:28 回复
粤ICP备15018643号-1