发布于 2016-01-01 12:08:40 | 315 次阅读 | 评论: 0 | 来源: PHPERZ

这里有新鲜出炉的Composer中文文档,程序狗速度看过来!

Composer PHP中依赖关系管理工具

Composer 是PHP中用来管理依赖(dependency)关系的工具。你可以在自己的项目中声明所依赖的外部工具库(libraries),Composer会帮你安装这些依赖的库文件。


安装

$ sudo php -r "readfile('https://getcomposer.org/installer');" | php
$ sudo mv composer.phar /usr/local/bin/composer

使用

https://github.com/mikecao/flight 为例,先看一下他的composer.json文件的内容:

{
    "name": "mikecao/flight",
    "description": "Flight is a fast, simple, extensible framework for PHP. Flight enables you to quickly and easily build RESTful web applications.",
    "homepage": "http://flightphp.com",
    "license": "MIT",
    "authors": [
        {
            "name": "Mike Cao",
            "email": "mike@mikecao.com",
            "homepage": "http://www.mikecao.com/",
            "role": "Original Developer"
        }
    ],
    "require": {
        "php": ">=5.3.0"
    },
    "autoload": {
        "files": [ "flight/autoload.php", "flight/Flight.php" ]
    },
    "require-dev": {
        "phpunit/phpunit": "~4.6"
    }
}

注意 autoload

$ cd /var/www/html
$ touch index.php
$ touch .htaccess

.htaccess内容如下:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteRule !\.(js|html|ico|gif|jpg|png|css)$ index.php
</IfModule>

下载flight:

$ composer require mikecao/flight

看下目录结构:

输入图片说明

index.php同一级的composer.json的内容如下:

{
    "require": {
        "mikecao/flight": "^1.2"
    }
}

编写index.php

<?php

require 'vendor/autoload.php';

Flight::route('/', function(){
    echo 'hello world!';
});

Flight::route('/foo', function(){
    echo 'welcome to foo!';
});

Flight::start();

浏览器访问http://127.0.0.1http://127.0.0.1/foo可以看到效果。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务