与作曲家一起构建

发布于 2025-02-07 18:59:37 字数 127 浏览 0 评论 0原文

在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盗梦空间 2025-02-14 18:59:37

用作曲家构建PHP项目的命令是什么?

简而言之,您会构建PHP项目。作曲家是您可以用来管理PHP Projects 依赖项的实用程序。此外,您还可以使用它来定义PHP项目。

您如何构建PHP项目完全取决于您。这通常取决于哪种类型的PHP项目以及如何组织它。

举个例子:让我们考虑一下您的PHP项目是带有composer.json的项目目录,其词根与所有其他子目录和文件。

作曲家在该目录内运行。因此,当您要创建该项目的构建工件时,您可以执行以下操作:

  1. Composer install -no -dev - 准备供应商使用生产依赖项和自动加载器的文件夹。
  2. 作曲家存档 - 创建构建工件。

将经常又一次地这样

{
  "scripts": {
    "build": [
      "@composer --no-plugins --no-interaction install --no-scripts --no-dev",
      "@composer --no-plugins --no-interaction archive"
    ]
  },
  "scripts-descriptions": {
    "build": "Build project artifact."
  }
}

正如您

$ composer build
...

做文件名。默认情况下,它应该是.tar file(Tarfile,Tarball),您可以在命令行上使用tar实用程序进行检查(此处 gnutar ):

$ tar -tvf "$(composer show -sN | sed 's|/|-|')"*.tar | less

那将是一个例子。我不知道作曲家推送是。您可能将其放在作曲家配置中。所以我无法评论。


在给定的示例上扩展一点:我使用作曲家管理了我的PHP项目中最多(甚至不是全部)。但是,这不是全部真理。我实际上是用git控制它们的。从鸟类的角度看,Git Utilities比作曲家实用程序更为领先。例如,我希望能够构建特定的GIT修订。

现在,作曲家对Git还不错。它识别该项目是否存在,并且在Composer Archive示例中,它甚至将git修订版本放入构建伪像的文件名中。

但是作曲家在树上运作。那也是开发也会发生的地方,因此很容易发生冲突(您不希望构建在运行测试时(或之后)在运行测试时删除开发依赖项)。甚至作曲家也认识到该项目是由GIT管理的,否则这有点愚蠢,因为作曲家仅关心依赖项,对项目本身知之甚少 - 它不仅可以猜测您如何管理整个项目。

因此,通常会发生的事情是您在构建过程中仍然使用作曲家,但是您有一个专用的构建过程和跑步者,并且知道项目的来龙去脉及其构建。

$ make

是这样的跑步者。 EG在项目中使用Makefile

$ make deploy

知道何时需要再次构建。说到PHP项目:当然,它可以只是rsync进行远程求职并进行烟雾测试以将部署标记为绿色(使用旧的,愚蠢的技术并保持简单)。

what would be the command to build a php project with composer?

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:

  1. composer install --no-dev - Prepare the vendor folder with the production dependencies and the autoloader.
  2. 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:

{
  "scripts": {
    "build": [
      "@composer --no-plugins --no-interaction install --no-scripts --no-dev",
      "@composer --no-plugins --no-interaction archive"
    ]
  },
  "scripts-descriptions": {
    "build": "Build project artifact."
  }
}

You can then run:

$ composer build
...

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 the tar utility (here gnutar):

$ tar -tvf "$(composer show -sN | sed 's|/|-|')"*.tar | less

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.

$ make

is such a runner. Works with a Makefile in the project, e.g.

$ make deploy

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文