与作曲家一起构建
在PHP项目的生命周期中,我们已经
- 安装了:Composer Install
- Publish:Composer Push,
但是,用作曲家构建PHP项目的命令是什么?
In a life cycle of a php project we have
- install: composer install
- publish: composer push
But, what would be the command to build a php project with composer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简而言之,您会构建PHP项目。作曲家是您可以用来管理PHP Projects 依赖项的实用程序。此外,您还可以使用它来定义PHP项目。
您如何构建PHP项目完全取决于您。这通常取决于哪种类型的PHP项目以及如何组织它。
举个例子:让我们考虑一下您的PHP项目是带有
composer.json
的项目目录,其词根与所有其他子目录和文件。作曲家在该目录内运行。因此,当您要创建该项目的构建工件时,您可以执行以下操作:
Composer install -no -dev
- 准备供应商
使用生产依赖项和自动加载器的文件夹。作曲家存档
- 创建构建工件。将经常又一次地这样
正如您
做文件名。默认情况下,它应该是
.tar
file(Tarfile,Tarball),您可以在命令行上使用tar
实用程序进行检查(此处 gnutar ):那将是一个例子。我不知道
作曲家推送
是。您可能将其放在作曲家配置中。所以我无法评论。在给定的示例上扩展一点:我使用作曲家管理了我的PHP项目中最多(甚至不是全部)。但是,这不是全部真理。我实际上是用git控制它们的。从鸟类的角度看,Git Utilities比作曲家实用程序更为领先。例如,我希望能够构建特定的GIT修订。
现在,作曲家对Git还不错。它识别该项目是否存在,并且在
Composer Archive
示例中,它甚至将git修订版本放入构建伪像的文件名中。但是作曲家在树上运作。那也是开发也会发生的地方,因此很容易发生冲突(您不希望构建在运行测试时(或之后)在运行测试时删除开发依赖项)。甚至作曲家也认识到该项目是由GIT管理的,否则这有点愚蠢,因为作曲家仅关心依赖项,对项目本身知之甚少 - 它不仅可以猜测您如何管理整个项目。
因此,通常会发生的事情是您在构建过程中仍然使用作曲家,但是您有一个专用的构建过程和跑步者,并且知道项目的来龙去脉及其构建。
是这样的跑步者。 EG在项目中使用
Makefile
,知道何时需要再次构建。说到PHP项目:当然,它可以只是
rsync
进行远程求职并进行烟雾测试以将部署标记为绿色(使用旧的,愚蠢的技术并保持简单)。Simply speaking, you build the PHP project. Composer is a utility you can use to manage a PHP projects dependencies. Additionally you can also use it to define your PHP project.
How you build the PHP project is entirely up to you. This is normally dependent of what kind of PHP project that is and how you organize it.
To give an example: Lets consider your PHP project just is the project directory with the
composer.json
at its root with all the other sub-directories and files.Composer operates within that directory. So when you want to create a build artifact of that project you do the following:
composer install --no-dev
- Prepare thevendor
folder with the production dependencies and the autoloader.composer archive
- Create the build artifact.As you will do this quite often and over and over again you could add a Composer Script named
build
or similar to put things together:You can then run:
Composer will then output the file-name. By default it should be a
.tar
file (tarfile, tarball), you can inspect it on the commandline with thetar
utility (here gnutar):And that would be the example. Whatever
composer push
is, I don't know. It is likely that you have it somewhere in your Composer configuration. So I can't comment on it.To extend a bit on the given example: I manage most (if not even all) of my PHP projects with Composer. However this is not the full truth. I actually version control them with Git. Looking from a birds perspective, the Git utility is way more leading than the Composer utility. That is for example, that I want to be able to build a specific git revision.
Now Composer is not that bad with Git. It recognizes if the project exists and in case of the
composer archive
example, it even puts the git revision hash into the file name of the build artifact.However Composer operates in-tree. That is the place where the development happens as well, so this can easily clash (you don't want the build to remove the development dependencies while you're running tests as well - or afterwards). And even Composer recognizes that the project is managed by Git, it is otherwise a bit dumb as Composer is merely concerned about the dependencies and knows very little about the project itself - it can't just guess how you manage the overall project.
So what then commonly happens is that you still use Composer during the build but you have a dedicated build process and runner that knows the ins and outs of the project and its build.
is such a runner. Works with a
Makefile
in the project, e.g.knows when it needs to build again. And speaking of PHP projects: It certainly can just
rsync
to remotes and run smoke-tests to mark the deployment as green (use old, dumb tech and keep it simple).