Home  >  Article  >  Backend Development  >  Composer 001

Composer 001

WBOY
WBOYOriginal
2016-08-08 09:29:18735browse
For modern languages, package managers are basically standard. Java has Maven, Python has pip, Ruby has gem, and Nodejs has npm. PHP is PEAR, but PEAR has many pitfalls:
  • Problems are prone to dependency processing
  • The configuration is very complicated
  • The command line interface is difficult to use
  • Fortunately, we have Composer, a powerful tool for PHP dependency management. It's open source and simple to use, and it's easy to submit your own packages. Install ComposerComposer requires PHP 5.3.2+ to run. $ curl -sS https://getcomposer.org/installer | php This command will download composer.phar to the current directory. PHAR (PHP compressed package) is a compressed format that can be run directly from the command line. You can use the --install-dir option to install Composer to a specified directory, for example: $ curl -sS https://getcomposer.org/installer | php -- --install-dir=bin Of course, you can also install it globally: $ curl -sS https://getcomposer.org/installer | php $ mv composer.phar /usr/local/bin/composer You can also use homebrew to install under Mac OS X: brew tap josegonzalez/homebrew-php brew install josegonzalez/php/composer However, usually you only need to add the location of composer.phar to the PATHenvironment variable, and it does not have to be installed globally. Declare dependenciesCreate a composer.json file in the project directory, specify the dependencies, for example, your project depends on monolog: { "require": { "monolog/monolog": "1.2.*"} } Installing dependenciesInstalling dependencies is very simple, just run in the project directory: composer install If it is not installed globally, run: php composer.phar install Auto-loadingComposer提供了自动加载的特性,只需在你的代码的初始化部分中加入下面一行:require'vendor/autoload.php'; 模块仓库packagist.org是Composer的仓库,很多著名的PHP库都能在其中找到。你也可以提交你自己的作品。高级特性以上介绍了Composer 的基本用法。Composer还有一些高级特性,虽然不是必需的,但是往往能给PHP开发带来方便。项目主页更多信息请访问 Composer 的官方主页或者中文站点。

    以上就介绍了Composer 001,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn