cyberspectrum/pharpiler

从任何基于composer的项目创建phar文件 - 高度可配置

安装: 247

依赖项: 0

建议者: 0

安全: 0

星标: 6

关注者: 3

分支: 0

开放问题: 1

类型:项目

1.0.8 2018-09-29 16:03 UTC

This package is auto-updated.

Last update: 2024-09-15 06:26:16 UTC


README

Build Status Latest Version tagged Latest Version on Packagist Installations via composer per month

什么是Pharpiler?

Pharpiler是一个简单且高度可配置的命令行工具,可以将基于composer的PHP项目编译成phar文件。

为什么使用Pharpiler?

我(@discordier)厌倦了为每个开发中的phar项目编写自定义编译脚本,这些脚本通常都是复制粘贴每个项目的代码。因此,确实需要减少代码重复,所以Pharpiler应运而生。

如何使用?

在你的项目中运行composer require --dev cyberspectrum/pharpiler,并在项目根目录中创建一个.pharpiler.yml文件。

配置

.pharpiler.yml允许进行许多配置选项,请查看此存储库中Pharpiler本身的配置(是的,Pharpiler可以编译自己)。

在配置中,你可以使用某些参数。

你可以在根级别定义自己的参数以减少重复。例如

parameters:
  - my-parameter: "Hello World"

然而,Pharpiler为每个包注册了一些参数,以简化配置。包根目录:%package:[vendor]/[package-name]% 包版本:%version:[vendor]/[package-name]% 包发布日期:%date:[vendor]/[package-name]%

# First off, tell what the desired phar name should be.
phar: pharpiler.phar

# Now we need to declare some compile tasks.
tasks:
  # We want to add a composer package.
  - type: add-package

    # The name of the package.
    # NOTE: you most likely. want to add your root package here as first.
    name: cyberspectrum/pharpiler

    # Optional flag to include all requirements of the package
    # default: true
    # You may specify a list of package names instead of true or false.
    # include_require: true

    # Optional flag to include all development requirements of the package.
    # default: false
    # You may specify a list of package names instead of true or false.
    # include_requiredev: false

    # Optionally list package names that shall get omitted.
    exclude_dependencies:
    #  - phpcq/all-tasks

    # Define file name pattern for files to get included.
    # You can specify glob and regex patterns here.
    # NOTE: this example makes use of YAML references.
    include_files: &default_include_files
      # Include all php files.
      - "*.php"
      # Include all the license files.
      - "(LICENSE\\.?.*)"
    # Define file name patterns of files to exclude.
    # You can specify glob and regex patterns here.
    # NOTE: this example makes use of YAML references.
    exclude_files: &default_exclude_files
      # We do not want to include unit tests.
      - "(.*[Tt]ests?\/)"
      - "*tests/*.php"

    # You may override the "include_files", "exclude_files" on a per package 
    # basis and can even move files around by specifying "rewrite_paths".
    package_override:
      # Override settings for package "cyberspectrum/pharpiler"
      cyberspectrum/pharpiler:
        include_files:
          # Import the previously defined default includes.
          - *default_include_files
          # Additionally add the file "bin/pharpiler" from said package.
          - "%package:cyberspectrum/pharpiler%/bin/pharpiler"
        exclude_files:
          # Import the previously defined default excludes.
          - *default_exclude_files
          # Additionally omit the files within phar directories.
          - "*/phar/*"
        rewrite_paths:
          # Here you can rewrite path portions.
          src: /src

      # Symfony has some tester classes we do not want to add - so let's skip them.
      symfony/console:
        exclude_files:
          - *default_exclude_files
          - "(Tester\/)"

  # A real phar file needs a stub, here you tell pharpiler to set it.
  - type: set-stub
    # The stub file must be accessible from anywhere within the composer project.
    stub_file: %package:cyberspectrum/pharpiler%/phar/stub.php

  # We most of the times also need to add the autoload information.
  - type: composer-autoload
    # Pharpiler can optimize the autoload information to remove anything which
    # got excluded by any other setting.
    # Default: true
    optimize: true

# For some files it is necessary to alter the file contents.
# To do so, you may specify a list of filters which alter file contents.
# Currently there are the following types of filters registered:
# - replace      Which performs simple search and replace on the file contents.
# - php-strip    Which removes all comments and trailing whitespace while
#                maintaining line numbers.
# - warning-time Creates a timestamp in the future - useful for selfupdate
#                notices etc.
rewrites:
    # Define the file names to be matched by this rewrite.
  - files:
      - %package:cyberspectrum/pharpiler%/phar/stub.php
      - %package:cyberspectrum/pharpiler%/bin/pharpiler
    # Define a list of filters to apply on these files.
    filter:
      # Search for "@@MIN_PHP_VERSION@@" and replace it with "5.5"
      - type: replace

        @@MIN_PHP_VERSION@@: "5.5"
      # Search for "@@PHARPILER_VERSION@@" and replace it with the installed version.
      - type: replace
        @@PHARPILER_VERSION@@: %version:cyberspectrum/pharpiler%

      # Search for "// @@DEV_WARNING_TIME@@" and replace it with the given define.
      # The magic value "@@warning_time@@" will get replaced with the calculated timestamp.
      - type: warning-time
        search: // @@DEV_WARNING_TIME@@
        format: define('DEV_WARNING_TIME', @@warning_time@@);
        # The ahead value is: 30 * 24 * 3600 = 2592000, hence 30 days.
        ahead: 2592000

  # This removes the shebang line from the passed script.
  - files:
      - %package:cyberspectrum/pharpiler%/bin/pharpiler
    filter:
      - type: replace
        "#!/usr/bin/env php\n": ""

  # You most likely want to keep the php-strip filter at the end as otherwise 
  # comments will get stripped that should get replaced by other filters, like
  # the "warning-time".
  - files: "*.php"
    filter:
      - type: php-strip