使用composer来安装php的相关框架,不需要事先准备composer.json以及conmposer.lock以及composer.phar等文件;
直接在项目根目录下是使用composer require frameworkname即可
使用composer require frameworkname命令执行以下动作:
(1)首先在项目根目录下生成composer.json文件
(2)会在项目更目录下生成框架的vendor目录,vendor目录即为框架,vendor目录会包含一个autoload.php文件用于加载框架;包含一个composer目录定义各种加载器
(3)最后生成composer.lock文件
例如在一个空目录下安装beanbun
生成的文件如下所示:
composer.json
{ "require": { "kiddyu/beanbun": "^1.0" } }
autoload.php
<?php // autoload.php @generated by Composer require_once __DIR__ . ‘/composer/autoload_real.php‘; return ComposerAutoloaderInitf0360927d4c8cd5f4c7318db461c5f92::getLoader();
composer.lock
{ "_readme": [ "This file locks the dependencies of your project to a known state", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], "content-hash": "f39f11ea038520d38d9236d063973569", "packages": [ { "name": "guzzlehttp/guzzle", "version": "6.3.3", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba", "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba", "shasum": "" }, "require": { "guzzlehttp/promises": "^1.0", "guzzlehttp/psr7": "^1.4", "php": ">=5.5" }, "require-dev": { "ext-curl": "*", "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", "psr/log": "^1.0" }, "suggest": { "psr/log": "Required for using the Log middleware" }, "type": "library", "extra": { "branch-alias": { "dev-master": "6.3-dev" } }, "autoload": { "files": [ "src/functions_include.php" ], "psr-4": { "GuzzleHttp\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" } ], "description": "Guzzle is a PHP HTTP client library", "homepage": "http://guzzlephp.org/", "keywords": [ "client", "curl", "framework", "http", "http client", "rest", "web service" ], "time": "2018-04-22T15:46:56+00:00" }, { "name": "guzzlehttp/promises", "version": "v1.3.1", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", "shasum": "" }, "require": { "php": ">=5.5.0" }, "require-dev": { "phpunit/phpunit": "^4.0" }, "type": "library", "extra": { "branch-alias": { "dev-master": "1.4-dev" } }, "autoload": { "psr-4": { "GuzzleHttp\\Promise\\": "src/" }, "files": [ "src/functions_include.php" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" } ], "description": "Guzzle promises library", "keywords": [ "promise" ], "time": "2016-12-20T10:07:11+00:00" }, { "name": "guzzlehttp/psr7", "version": "1.4.2", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c", "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", "shasum": "" }, "require": { "php": ">=5.4.0", "psr/http-message": "~1.0" }, "provide": { "psr/http-message-implementation": "1.0" }, "require-dev": { "phpunit/phpunit": "~4.0" }, "type": "library", "extra": { "branch-alias": { "dev-master": "1.4-dev" } }, "autoload": { "psr-4": { "GuzzleHttp\\Psr7\\": "src/" }, "files": [ "src/functions_include.php" ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" }, { "name": "Tobias Schultze", "homepage": "https://github.com/Tobion" } ], "description": "PSR-7 message implementation that also provides common utility methods", "keywords": [ "http", "message", "request", "response", "stream", "uri", "url" ], "time": "2017-03-20T17:10:46+00:00" }, { "name": "kiddyu/beanbun", "version": "1.0.4", "source": { "type": "git", "url": "https://github.com/kiddyuchina/Beanbun.git", "reference": "3b84c35de3470a3a2a44d47d201bdc3b7602e666" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/kiddyuchina/Beanbun/zipball/3b84c35de3470a3a2a44d47d201bdc3b7602e666", "reference": "3b84c35de3470a3a2a44d47d201bdc3b7602e666", "shasum": "" }, "require": { "guzzlehttp/guzzle": "^6.0", "php": ">=5.5.0", "workerman/workerman": "^3.3" }, "type": "application", "autoload": { "psr-4": { "Beanbun\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Kidd Yu", "email": "58631254@qq.com" } ], "description": "Beanbun 是用 PHP 编写的多进程网络爬虫框架,具有良好的开放性、高可扩展性", "keywords": [ "crawler", "scraper", "spider" ], "time": "2017-06-11T17:13:59+00:00" }, { "name": "psr/http-message", "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/php-fig/http-message.git", "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", "shasum": "" }, "require": { "php": ">=5.3.0" }, "type": "library", "extra": { "branch-alias": { "dev-master": "1.0.x-dev" } }, "autoload": { "psr-4": { "Psr\\Http\\Message\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "PHP-FIG", "homepage": "http://www.php-fig.org/" } ], "description": "Common interface for HTTP messages", "homepage": "https://github.com/php-fig/http-message", "keywords": [ "http", "http-message", "psr", "psr-7", "request", "response" ], "time": "2016-08-06T14:39:51+00:00" }, { "name": "workerman/workerman", "version": "v3.5.8", "source": { "type": "git", "url": "https://github.com/walkor/Workerman.git", "reference": "cbc6e46deb9e1a82a5f628118c850ebeea7b2224" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/walkor/Workerman/zipball/cbc6e46deb9e1a82a5f628118c850ebeea7b2224", "reference": "cbc6e46deb9e1a82a5f628118c850ebeea7b2224", "shasum": "" }, "require": { "php": ">=5.3" }, "suggest": { "ext-event": "For better performance. " }, "type": "library", "autoload": { "psr-4": { "Workerman\\": "./" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "walkor", "email": "walkor@workerman.net", "homepage": "http://www.workerman.net", "role": "Developer" } ], "description": "An asynchronous event driven PHP framework for easily building fast, scalable network applications.", "homepage": "http://www.workerman.net", "keywords": [ "asynchronous", "event-loop" ], "time": "2018-05-23T05:36:47+00:00" } ], "packages-dev": [], "aliases": [], "minimum-stability": "stable", "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": [], "platform-dev": [] }
原文:https://www.cnblogs.com/liuzhiqaingxyz/p/9085018.html