mtdowling/burgomaster

将 PHP 包打包成 zip 和 phar 格式

0.0.3 2015-09-02 05:18 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:29:39 UTC


README

城镇、汉堡以及为 PHP 应用创建 phar 和 zip 的大师。

此脚本可用于

  1. 轻松创建用于您的包的预发布目录。
  2. 构建所有 PHP 文件的类映射自动加载器。
  3. 创建包含您的项目、其依赖项和自动加载器的 zip 文件。
  4. 创建包含所有项目依赖项并在加载时注册自动加载器的 phar 文件。

此项目可能永远不会超过一个包含单个类的单个文件,因此请随意将此文件复制并粘贴到您的项目中,而不是仅为了构建而引入新的依赖项。

教程

以下示例演示了 Guzzle 如何使用此项目。对于此示例,假设此脚本位于 guzzlehttp/src/build/

获取 Burgomaster

在运行您的打包脚本之前,您需要 Burgomaster 的副本。这可以通过 composer(mtdowling/burgomaster)或仅创建一个 Makefile 来下载 Burgomaster.php 脚本来完成。

首先,在您的项目根目录中创建以下 Makefile

package: burgomaster
    php build/packager.php

burgomaster:
    mkdir -p build/artifacts
    curl -s https://raw.githubusercontent.com/mtdowling/Burgomaster/0.0.1/src/Burgomaster.php > build/artifacts/Burgomaster.php

注意

您可以使用上述 URL 替换为不同的标签,而不是 0.0.1。查看 Burgomaster 的发行版本 以获取可用标签的列表。

创建 packager.php 脚本

现在您需要编写一个 packager.php 脚本,通常位于项目的 build/ 目录中。以下是 Guzzle 的样子。

<?php
require __DIR__ . '/artifacts/Burgomaster.php';

// Creating staging directory at guzzlehttp/src/build/artifacts/staging.
$stageDirectory = __DIR__ . '/artifacts/staging';
// The root of the project is up one directory from the current directory.
$projectRoot = __DIR__ . '/../';
$packager = new \Burgomaster($stageDirectory, $projectRoot);

// Copy basic files to the stage directory. Note that we have chdir'd onto
// the $projectRoot directory, so use relative paths.
foreach (['README.md', 'LICENSE'] as $file) {
    $packager->deepCopy($file, $file);
}

// Copy each dependency to the staging directory. Copy *.php and *.pem files.
$packager->recursiveCopy('src', 'GuzzleHttp', ['php', 'pem']);
$packager->recursiveCopy('vendor/guzzlehttp/streams/src', 'GuzzleHttp/Stream');
// Create the classmap autoloader, and instruct the autoloader to
// automatically require the 'GuzzleHttp/functions.php' script.
$packager->createAutoloader(['GuzzleHttp/functions.php']);
// Create a phar file from the staging directory at a specific location
$packager->createPhar(__DIR__ . '/artifacts/guzzle.phar');
// Create a zip file from the staging directory at a specific location
$packager->createZip(__DIR__ . '/artifacts/guzzle.zip');

如你所见,创建一个 packager.php 脚本只是一系列使用 Burgomaster 帮助执行一些常见任务的动作,如创建预发布目录、构建自动加载器、创建 zip 和创建 phar。

make package

现在您已经创建了 packager.php 脚本,只需从命令行运行 Makefile 中的 packge 目标即可。

make package

GitHub 发布

现在您已经找到了一种轻松打包发布的方法,您应该设置打包脚本以自动构建并部署到 GitHub 发布 使用 Travis-CI 的 GitHub 发布部署 目标,以便在您向存储库推送标签时上传 phar 和 zip。