hi,你好!欢迎访问本站!登录
本站由网站地图腾讯云宝塔系统阿里云强势驱动
当前位置:首页 - 教程 - 开发工具 - 正文 君子好学,自强不息!

【编程开辟工具】如何用composer开辟本身的php扩大包

2019-11-19开发工具搜奇网72°c
A+ A-
下面由 composer运用教程栏目给人人引见用composer开辟本身的php扩大包的要领,愿望对须要的朋侪有所协助!

composer 是PHP用来治理依靠关联的东西

概况能够浏览:https://www.phpcomposer.com/

装置 见 https://www.phpcomposer.com/

开辟流程

初始化本身的扩大包 composer init

$ composer init
  Welcome to the Composer config generator
  
This command will guide you through creating your composer.json config.
Package name (<vendor>/<name>) [administrator/self_composer]: victor/composer-self //包称号-不能大写,不然无效 
Description []: composer-self package //形貌
Author [victor24680 <490319148@qq.com>, n to skip]://作者
Minimum Stability []: dev //最小稳固版本
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
{
    "name": "victor/composer-self",
    "description": "This is a composer-send package",
    "type": "victor",
    "license": "MIT",
    "authors": [
        {
            "name": "victor24680",
            "email": "490319148@qq.com"
        }
    ],
    "minimum-stability": "dev",
    "require": {}
}
Do you confirm generation [yes]? yes

修正本身包的依靠关联,修正内容以下

{
    "name": "victor/sendtool-package",
    "description": "sendtool package",
    "type": "victor",
    "license": "MIT",
    "authors": [
        {
            "name": "victor24680",
            "email": "490319148@qq.com"
        }
    ],
    "minimum-stability": "dev",
    "require": {
        "php": ">=5.6" //php版本请求
    },
    "autoload": {
        "psr-4": { //加载范例
            "App\\": "src/App",
            "Contract\\": "src/Contract"
        }
    }
}

编写好源码 见:https://github.com/victor24680/self-composer/tree/master/src

装置测试 composer install

$ composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Content-Length mismatch, received 37487 bytes out of the expected 2005372
http://packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date
Nothing to install or update
Writing lock file
Generating autoload files

GitHub上建立composer-self堆栈

git init
git add .
git commit -m "初始本身的组件库"
git remote add origin https://github.com/victor24680/self-composer.git
git push origin master

Packagist 上提交本身的github建立的composer-self堆栈地点

注册地点:https://packagist.org/,提交胜利以后,就能够最先下面的测试

测试 ,A目次代表项目根目次

建立一个A目次,然后在项目根目次下实行:composer require victor24680/self-composer dev-master

$ composer require victor24680/self-composer dev-master
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing victor24680/self-composer (dev-master 0935c75): Cloning 0935c75eda from cache
Writing lock file
Generating autoload files
<?php
#项目根目次/index.php
include "vendor/autoload.php";
use App\CommonInfo;
use App\Zn;
$app=new CommonInfo(new Zn());
echo $app->msg('小明','近邻老王在偷吃!!!');
//输出:【站内音讯】发送给:小明|发送内容:【一般音讯】近邻老王在偷吃!!!

至此,一个完全的本身的composer组件包,开辟完成。

以上就是如何用composer开辟本身的php扩大包的细致内容,更多请关注ki4网别的相干文章!

  选择打赏方式
微信赞助

打赏

QQ钱包

打赏

支付宝赞助

打赏

  移步手机端
【编程开辟工具】如何用composer开辟本身的php扩大包

1、打开你手机的二维码扫描APP
2、扫描左则的二维码
3、点击扫描获得的网址
4、可以在手机端阅读此文章
标签:

本文来源:搜奇网

本文地址:https://www.sou7.cn/282486.html

关注我们:微信搜索“搜奇网”添加我为好友

版权声明: 本文仅代表作者个人观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。请记住本站网址https://www.sou7.cn/搜奇网。

发表评论

选填

必填

必填

选填

请拖动滑块解锁
>>