PHP管理依赖(dependency)关系工具 Composer 安装与使用(2)

E:\USB\Dropbox\phpstorm\php53>E:\USB\xampp_181\php\php.exe -v PHP 5.4.7 (cli) (built: Sep 12 2012 23:48:31) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

确定版本高于PHP 5.3.2 后,开始安装:

E:\USB\Dropbox\phpstorm\php54>curl -sS https://getcomposer.org/installer | E:\USB\xampp_181\php\php.exe #!/usr/bin/env php Some settings on your machine may cause stability issues with Composer. If you encounter issues, try to change the following: The openssl extension is missing, which will reduce the security and stability o f Composer. If possible you should enable it or recompile php with –with-openssl Downloading… Composer successfully installed to: E:\USB\Dropbox\phpstorm\php54\composer.phar Use it: php composer.phar

安装完成后,检查安装版本。

E:\USB\Dropbox\phpstorm\php54>E:\USB\xampp_181\php/php.exe composer.phar -V Composer version 0209bd31a0ac3aeb2a68fc81e2d03c71072bef33

这样,PHP 5.4 环境下的Composer也安装成功了。

PHP Composer 使用

这里我只简单演示使用PHP Composer安装Symfony框架。

首先大概讲解一下命令的标准格式:

php composer.phar create-project symfony/framework-standard-edition path/ 2.2.1

第一个参数PHP为本地PHP开发环境,指向PHP运行命令。
第二个参数,为composer.phar方式下载。
第三个参数,为动作命令,例如create-project,目的是为了创建一个新的项目从一个软件包到指定目录。
第四个参数,为本地安装的目录。
第五个参数,为安装软件包的版本。

根据上述我们在PHP5.4环境下安装的Composer,我们的安装命令为:

E:\USB\Dropbox\phpstorm\php54>E:\USB\xampp_181\php/php.exe composer.phar create-project symfony/framework-standard-edition E:\USB\xampp_181\htdocs\Symfony 2.2.1

安装结果:

Installing symfony/framework-standard-edition (v2.2.1) – Installing symfony/framework-standard-edition (v2.2.1) Downloading: 100% Created project in E:\USB\xampp_181\htdocs\Symfony Loading composer repositories with package information Installing dependencies from lock file – Installing doctrine/lexer (v1.0) Downloading: 100% – Installing doctrine/annotations (v1.1) Downloading: 100% – Installing doctrine/cache (v1.0) Downloading: 100% – Installing doctrine/collections (v1.1) Downloading: 100% – Installing twig/twig (v1.12.2) Downloading: 100% – Installing psr/log (1.0.0) Downloading: 100% – Installing doctrine/inflector (v1.0) Downloading: 100% – Installing doctrine/common (2.4.0-RC1) Downloading: 100% – Installing symfony/symfony (v2.2.1) Downloading: 100% – Installing jdorn/sql-formatter (v1.2.0) Downloading: 100% – Installing doctrine/dbal (2.3.3) Downloading: 100% – Installing doctrine/doctrine-bundle (v1.2.0-beta1) Downloading: 100% – Installing doctrine/orm (2.3.3) Downloading: 100% – Installing jms/cg (1.0.0) Downloading: 100% – Installing phpoption/phpoption (1.2.0) Downloading: 100% – Installing jms/parser-lib (1.0.0) Downloading: 100% – Installing jms/metadata (1.3.0) Downloading: 100% – Installing jms/aop-bundle (1.0.0) Downloading: 100% – Installing jms/di-extra-bundle (1.3.0) Downloading: 100% – Installing jms/security-extra-bundle (1.4.0) Downloading: 100% – Installing sensio/distribution-bundle (v2.2.1) Downloading: 100% – Installing sensio/framework-extra-bundle (v2.2.1) Downloading: 100% – Installing sensio/generator-bundle (v2.2.1) Downloading: 100% – Installing kriswallsmith/assetic (v1.1.0-alpha4) Downloading: 100% – Installing symfony/assetic-bundle (v2.1.2) Downloading: 100% – Installing monolog/monolog (1.4.1) Downloading: 100% – Installing symfony/monolog-bundle (v2.2.0) Downloading: 100% – Installing swiftmailer/swiftmailer (v4.3.0) Downloading: 100% – Installing symfony/swiftmailer-bundle (v2.2.0) Downloading: 100% – Installing twig/extensions (v1.0.0) Downloading: 100% kriswallsmith/assetic suggests installing leafo/lessphp (Assetic provides the integration with the lessphp LESS compiler) kriswallsmith/assetic suggests installing leafo/scssphp (Assetic provides the integration with the scssphp SCSS compiler) kriswallsmith/assetic suggests installing leafo/scssphp-compass (Assetic provides the integration with the SCSS compass plugin) kriswallsmith/assetic suggests installing ptachoire/cssembed (Assetic provides the integration with phpcssembed to embed data uris) monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server) monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required)) monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server) monolog/monolog suggests installing mlehner/gelf-php (Allow sending log messages to a GrayLog2 server) monolog/monolog suggests installing raven/raven (Allow sending log messages to a Sentry server) Generating autoload files Clearing the cache for the dev environment with debug true Installing assets using the hard copy option Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework Installing assets for Acme\DemoBundle into web/bundles/acmedemo Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution

从命令行结果,我们看到了整个Symfony框架的安装过程与结果。

PHP Composer 定义依赖关系

Composer在使用时会自动寻找composer.json这个文件。 composer.json将用来定义整个项目的依赖包。例如:

{ "require": { "monolog/monolog": "1.2.*" } }

依赖包简单的说明,我们的项目需要一些从1.2开始的任何版本的monolog/monolog包。

Composer是PHP中的一个依赖关系管理工具。通过Composer我们可以在发布软件时节省大量的文件数目和控制依赖包的版本。

PHP Composer 项目

Composer 项目官方:

Composer Github项目:https://github.com/composer/composer

PHP Composer软件包列表:https://packagist.org/

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/52d9ffb5ef0c6bdcf470ce85ed757844.html