系统学习magento二次开发,推荐小册:《Magento中文全栈二次开发 》
本小册面向Magento2以上版本,书代码及示例兼容magento2.0-2.4版本。涵盖了magento前端开发,后端开发,magento2主题,magento2重写,magento2 layout,magento2控制器,magento2 block等相关内容,带领您成为magento开发技术专家。
Composer是一个在PHP中处理依赖关系管理的工具。它不像Yum和Apt在Linux系统上那样是一个包管理器。尽管它处理库(包),但它是在每个项目级别上处理的。它不会在全局范围内安装任何内容
。Composer是一个多平台工具。因此,它在Windows、Linux和OS X上运行得同样好。在计算机上安装Composer就像使用以下命令在项目目录中运行安装程序一样简单:
curl -sS https://getcomposer.org/installer | php
有关安装Composer的更多信息,请访问其官方网站https://getcomposer.org.Compose r用于获取Magento及其使用的第三方组件。
如前一章所示,以下composer命令将所有内容拉入指定目录:
composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition <installation directory name>
一旦下载并安装了Magento,就可以在其目录中找到许多composer.json文件。假设<installation directory name>是magento2,如果我们执行一个快速搜索执行命令,如find magento2/-name‘composer.json’,将产生100多个composer.json文件。其中一些文件(部分)列在此处:
/vendor/magento/module-catalog/composer.json/vendor/magento/module-cms/composer.json/vendor/magento/module-contact/composer.json/vendor/magento/module-customer/composer.json/vendor/magento/module-sales/composer.json/.../vendor/magento/theme-adminhtml-backend/composer.json/vendor/magento/theme-frontend-blank/composer.json/vendor/magento/theme-frontend-luma/composer.json/vendor/magento/language-de_de/composer.json/vendor/magento/language-en_us/composer.json/.../composer.json/dev/tests/.../vendor/magento/framework/composer.json
最相关的文件可能是magento目录根目录中的composer.json文件。其内容如下所示:
{ "name": "magento/project-community-edition", "description": "eCommerce Platform for Growth (Community Edition)", "type": "project", "version": "2.0.0", "license": ["OSL-3.0", "AFL-3.0"], "repositories": [{ "type": "composer", "url": "https://repo.magento.com/" }], "require": { "magento/product-community-edition": "2.0.0", "composer/composer": "@alpha", "magento/module-bundle-sample-data": "100.0.*", "magento/module-widget-sample-data": "100.0.*", "magento/module-theme-sample-data": "100.0.*", "magento/module-catalog-sample-data": "100.0.*", "magento/module-customer-sample-data": "100.0.*", "magento/module-cms-sample-data": "100.0.*", "magento/module-catalog-rule-sample-data": "100.0.*", "magento/module-sales-rule-sample-data": "100.0.*", "magento/module-review-sample-data": "100.0.*", "magento/module-tax-sample-data": "100.0.*", "magento/module-sales-sample-data": "100.0.*", "magento/module-grouped-product-sample-data": "100.0.*", "magento/module-downloadable-sample-data": "100.0.*", "magento/module-msrp-sample-data": "100.0.*", "magento/module-configurable-sample-data": "100.0.*", "magento/module-product-links-sample-data": "100.0.*", "magento/module-wishlist-sample-data": "100.0.*", "magento/module-swatches-sample-data": "100.0.*", "magento/sample-data-media": "100.0.*", "magento/module-offline-shipping-sample-data": "100.0.*" }, "require-dev": { "phpunit/phpunit": "4.1.0", "squizlabs/php_codesniffer": "1.5.3", "phpmd/phpmd": "@stable", "pdepend/pdepend": "2.0.6", "sjparkinson/static-review": "~4.1", "fabpot/php-cs-fixer": "~1.2", "lusitanian/oauth": "~0.3 <=0.7.0" }, "config": { "use-include-path": true }, "autoload": { "psr-4": { "Magento\\Framework\\": "lib/internal/Magento/Framework/", "Magento\\Setup\\": "setup/src/Magento/Setup/", "Magento\\": "app/code/Magento/" }, "psr-0": { "": "app/code/" }, "files": ["app/etc/NonComposerComponentRegistration.php"] }, "autoload-dev": { "psr-4": { "Magento\\Sniffs\\": "dev/tests/static/framework/Magento/Sniffs/", "Magento\\Tools\\": "dev/tools/Magento/Tools/", "Magento\\Tools\\Sanity\\": "dev/build/publication/sanity/ Magento/Tools/Sanity/", "Magento\\TestFramework\\Inspection\\": "dev/tests/static/framework/Magento/ TestFramework/Inspection/", "Magento\\TestFramework\\Utility\\": "dev/tests/static/framework/Magento/ TestFramework/Utility/" } }, "minimum-stability": "alpha", "prefer-stable": true, "extra": { "magento-force": "override" } }
Composer的JSON文件遵循特定的模式。有关此架构的详细文档,请访问https://getcomposer.org/doc/04-schema.md 应用到架构可以确保composer文件的有效性。我们可以看到,所有列出的键,如name、description、require、config等,都是由架构定义的。
让我们来看看单个模块的composer.json文件。其中一个依赖关系最少的简单模块是Contact module,其vendor/magento/module-contact/composer.json内容如下:
{ "name": "magento/module-contact", "description": "N/A", "require": { "php": "~5.5.0|~5.6.0|~7.0.0", "magento/module-config": "100.0.*", "magento/module-store": "100.0.*", "magento/module-backend": "100.0.*", "magento/module-customer": "100.0.*", "magento/module-cms": "100.0.*", "magento/framework": "100.0.*" }, "type": "magento2-module", "version": "100.0.2", "license": [ "OSL-3.0", "AFL-3.0" ], "autoload": { "files": [ "registration.php" ], "psr-4": { "Magento\\Contact\\": "" } }}
您将看到这些模块定义了对PHP版本和其他模块的依赖关系。此外,您将看到PSR-4用于自动加载和直接加载registration.php文件。
接下来,我们来看看en_us语言模块中vendor/magento/language-en_us/composer.json的内容:
{ "name": "magento/language-en_us", "description": "English (United States) language", "version": "100.0.2", "license": ["OSL-3.0", "AFL-3.0"], "require": { "magento/framework": "100.0.*" }, "type": "magento2-language", "autoload": { "files": ["registration.php"] } }
最后,让我们看看来自luma主题的vendor/magento/theme-front-end-luma/composer.json的内容:
{ "name": "magento/theme-frontend-luma", "description": "N/A", "require": { "php": "~5.5.0|~5.6.0|~7.0.0", "magento/theme-frontend-blank": "100.0.*", "magento/framework": "100.0.*" }, "type": "magento2-theme", "version": "100.0.2", "license": ["OSL-3.0", "AFL-3.0"], "autoload": { "files": ["registration.php"] } }
如前所述,magento周围散布着更多的composer文件。
以上就是magento2中的composer相关介绍。